Skip to main content
Conga Support

Creating an Apex Test Class for a Custom Object as a Step

Create the following Class in order to deploy the trigger to your production environment.

If your custom object is the detail record in a master-detail relationship, create a formula field that retrieves the OwnerId from the master object. The structure of the field will be dependent on how the relationship is named. For example, if your object is related to the account object through a master-detail relationship the formula is: Business_Account__r.OwnerId.

  1. In your sandbox environment, select the Settings Cog icon (in Lightning) or your name (in Classic) in the upper right corner of Salesforce.
  2. Select Developer Console.
  3. Select File.
  4. Hover over New and choose Apex Class.
  5. Give your class a descriptive name. Something like CustomObjectNameAsStepTriggerTest.
  6. Select OK.
  7. Copy/Paste the following code into the new class window:

    @isTest
    private class CustomObjectNameAsStepTriggerTest {
        private static testMethod void Test_CustomObjectNameAsStepTrigger () {
            YOUR_PROCESS_OBJECT_API_NAME__c fw = new YOUR_PROCESS_OBJECT_API_NAME__c();
            insert fw;

            CustomStepObject__c cso = new CustomStepObject__c();
            insert cso;
            update cso;
            delete cso;
        }
    }

  8. Replace CustomObjectNameAsStepTriggerTest with the name of the class you chose in step 5 above.
  9. Replace the CustomObjectName within Test_CustomObjectNameAsStepTrigger with the name of your custom object (no spaces).
  10. Replace YOUR_PROCESS_OBJECT_API_NAME__c with the API name of a process object (you can use FSTR__Business_Process__c or the API name of a custom process object you have already set up).
  11. Replace CustomStepObject__c with the API name of your custom step object.

    You may need to add additional code to your test method depending on what fields your object requires and validation rules that may be in place. When running tests in step 13, take note of any errors that may occur as these point out required fields that may not have been populated by your test code.

  12. Save the class by pressing Ctrl+S on your keyboard or by selecting File > Save in the top menu of the Developer Console.
  13. Select the Run Test button within the Developer Console.
  14. Verify the minimum 75% code coverage was achieved. If applicable, fix any errors and run the test again.
  15. Close the Developer Console window.

Refer to the Deploy from Sandbox with Change Sets module in Trailhead for instructions on the deployment process.