Salesforce App: Apex Code Deployment

This article will guide you in the process of setting up automatic creation of Salesforce Cases or Opportunities based on the data our App is getting from our API.

I. Pre-requisite

  • To know how to create a sandbox and to log in
  • Having installed our App on your Salesforce environment
  • Knowing how to deploy a changes set

II. Creating Apex Classes

It is not possible to create directly a code in the production environment, so you will need to create a sandbox and then login. This step will allow to create two Apex classes and one Apex trigger on the sandbox. An Apex trigger is a trigger that use specific code following the creation or modification of an object record.

In our use case, we are going to create an Apex trigger on the object "Allomediacallc", which will use the Apex class "Call.cls". The Apex class "Call_test.cls" is the unit test allowing to deploy the code in the production organization.

The creation of Apex classes and trigger is done by using the developer console.

Path: click on the cogwheel in the top right corner, then "setup"

A. Creation of the Apex class "Calls.cls"

  • In a new window, select the "File" menu, then "New", then "Apex class"
  • In the "New Apex class" popup, enter the name of the class "Calls".
  • Delete the class content already present.
  • Copy and past the content of the file "Calls.cls" in the input field (the file is in attachment).
  • Modify the values according to your needs, then save :
    • TagOppGUID corresponds to the GUID of the tag to track, which allow to create "opportunities".
    • TagCaseGUIDE corresponds to the GUID of the tag to track, which allow to create cases.

B. Creation of unit tests "Call_tests.cls"

  • In a new window, select the "File" menu, then "New", then "Apex class"
  • In the "New Apex class" popup, enter the name of the class "Calls_test".
  • Delete the class content already present.
  • Copy and past the content of the file "Calls_test.cls" in the input field (the file is in attachment), then save.

C. Creation of the Apex trigger "Calltrigger.trigger"

  • In a new window, select the "File" menu, then "New", then "Apex trigger"
  • In the "New Apex trigger" popup, enter the name of the class "Calltrigger".
  • Select "allomedia__call_c" for the object, then click "Submit"
  • Delete the class content already present.
  • Copy and past the content of the file "CallTrigger" in the input field (the file is in attachment), then save.

III. Change sets

Change sets allows to send code or other settings from a Sandbox organization to a production organization.

A. Authorize inbound changes

To allow deployment of the change sets, you must allow deployment from a sending organization.

Go to the target organization:

Path: Configuration > PLATFORM TOOL > Environment > Deploy > Deployment settings
  • Chose the issuing organization that contains the Apex classes

B. Create a change set

The change set can contain several developer components or parameter on a test sandbox.

Go on the sender organization:

Path: Configuration > PLATFORM TOOL > Environment > Change sets > Inbound change sets
  • Click "New" to create a change set and name it "PkCall"
  • Click on "Add" to add components.
  • In "Component type", select "Apex Class", check "Calls" and "Call_test"
  • Click on "Add to the change set"
  • Click again on the "Add" button.
  • In "Component type", select "Apex trigger", check "CallTrigger"
  • Click on "Add to the change set", then "Load"
  • Select "Production" the "Load" again

IV. Deploy the change set

Receiving a modification set can take several minutes (5 to 30, on average). The administrator can delete or deploy this change set.

Go on the target organization to manage the change set:

Path: Configuration > PLATFORM TOOL > Environment > Change sets > Inbound change sets
  • Select "PkCall", then "Deploy".

Downloads