Conga Product Documentation

Welcome to the new doc site. Some of your old bookmarks will no longer work. Please use the search bar to find your desired topic.

download

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

Create the following class 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 gear icon (in Lightning) or your name (in Classic) in the upper right corner of Salesforce to open Settings.
  2. Select Developer Console.
  3. Select File.
  4. Hover over New and choose Apex Class.
  5. Give your class a descriptive name, like CustomObjectNameTriggerTest.
  6. Click OK.
  7. Copy the following code and paste it into the new class window:
    @isTest private class CustomObjectNameTriggerTest { private static testMethod void Test_CustomObjectNameTrigger () { YOUR_CUSTOM_OBJECT_API_NAME__c fw = new YOUR_CUSTOM_OBJECT_API_NAME__c(); insert fw; System.assertNotEquals(null, fw.id); update fw; delete fw; } }
  8. Replace CustomObjectNameTriggerTest with the name of the class you chose in step 5 above.
  9. Replace the CustomObjectName in Test_CustomObjectNameTrigger with the name of your custom object (no spaces).
  10. Replace YOUR_CUSTOM_OBJECT_API_NAME__c with the API name of your custom object. You may need to add code to your test method depending on which fields your object requires and validation rules that may be in place. When running tests in step 12, note any errors that may occur as these indicate required fields that your test code may not have populated.
  11. Save the class by pressing Ctrl+S or by selecting File > Save in the top menu of the Developer Console.
  12. Click the Run Test button in the Developer Console.
  13. Verify the minimum 75% code coverage was achieved. If applicable, fix any errors and run the test again.
  14. Close the Developer Console.

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