Loading
Feature Disruption - Service Cloud VoiceRead More
Feature degradation | Gmail Email delivery failureRead More
Sales Productivity
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Add Prospects to a Cadence Automatically with Process Builder and Apex

          Add Prospects to a Cadence Automatically with Process Builder and Apex

          Save your sales reps from taking an extra step. To automatically add lead, contact, or person account records to a cadence when the records are created, create an Apex class and a process.

          Required Editions

          Available in: Lightning Experience
          Available with Sales Engagement, which is included with Sales in Performance, Einstein 1, and Unlimited Editions, and available for an extra cost in Professional and Enterprise Editions. Sales Engagement is also available for an extra cost in Service and Lightning Platform.
          User Permissions Needed
          To create, edit, or view processes:

          Manage Flow

          AND

          View All Data

          To define Apex triggers: Author Apex
          To configure remote settings:

          Customize Application

          OR

          Modify All Data

          To add prospects to cadences:

          Sales Engagement User

          OR

          Sales Engagement User Included

          Note
          Note You can’t add Apex classes directly in production Salesforce orgs. Only Developer, trial, and sandbox orgs support direct Apex editing in Setup. To deploy Apex code in a production org, add it first to a sandbox org, test, and then promote it to the production org.

          This example uses the AssignTargetToSalesCadence action. You can also build processes with the RemoveTargetFromSalesCadence action.

          Set your process to start only upon record creation. Setting your process to run upon both record creation and edit creates duplicate targets within the cadence.

          1. Create the Apex class.
            1. From the Setup menu, choose Developer Console.
            2. From the File menu, choose New | Apex Class.
            3. Enter EnrollTargetIntoSalesCadence for class name. Click OK.
            4. In the Developer Console, replace the code you see with the following Apex.
              public class EnrollTargetIntoSalesCadence {
                  
                  @InvocableMethod(label='Enroll Target In Cadence' description='Uses REST Invocable Action to assign a Target to a Cadence')
                  public static void enrollTarget(List<EnrollTargetRequest> targetsToEnroll) {
                      System.debug('*** Targets to enroll *** ' + targetsToEnroll);
                      if (targetsToEnroll != null) {
                          for (EnrollTargetRequest req : targetsToEnroll) {
                              System.debug('*** request *** ' + req);
                              System.debug('\ttarget: ' + req.targetId);
                              System.debug('\tsales cadence: ' + req.salesCadenceName);
                              sendRequest(req.targetId, req.salesCadenceName);
                          }
                      } else {
                          System.debug('*** null targetsToEnroll receieved ***');
                      }  
                  }
                  
                  @future(callout = true)
                  private static void sendRequest(String targetId, String salesCadenceNameOrId) {
                      String sfdcURL = URL.getSalesforceBaseUrl().toExternalForm();
                      String actionsRestURL = sfdcURL + '/services/data/v45.0/actions';
                      String assignTargetRESTUrl = actionsRestURL + '/standard/assignTargetToSalesCadence';
              
                      HttpRequest httpReq = new HttpRequest();
                      httpReq.setMethod('POST');
                      httpReq.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId());
                      httpReq.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
                      httpReq.setEndpoint(assignTargetRESTUrl);
                      httpReq.setHeader('Content-Type', 'application/json');
                      httpReq.setBody('{"inputs" : [{"salesCadenceNameOrId" : "' + salesCadenceNameOrId + '", "targetId" : "' + targetId + '"}]}');
                      
                      String response = '';
                      try {
                          Http http = new Http();
                          HttpResponse httpResponse = http.send(httpReq);
                          if (httpResponse.getStatusCode() == 200) {
                              response = JSON.serializePretty(JSON.deserializeUntyped(httpResponse.getBody()));
                          } else {
                              System.debug('http response: ' + httpResponse.getBody());
                              throw new CalloutException(httpResponse.getBody());
                          }
                      } catch (System.Exception e) {
                          System.debug('ERROR! ' + e);
                          throw e;
                      }
                      
                      System.debug('response: ' + response);     
                  }
                  
                  public class EnrollTargetRequest {
                      @InvocableVariable(required=true)
                      public Id targetId;
                      
                      @InvocableVariable(required=true)
                      public String salesCadenceName;
                  }
              }
            5. Save the Apex class.
          2. Create a process.
            1. From Setup, enter Process Builder in the Quick Find box. Then click Process Builder.
            2. Click New.
            3. Name the process.
            4. In the process starts when menu, choose A record changes.
            5. Click Save.
            6. In the Process Builder, click the Add Object node.
            7. From the Object menu in the right pane, choose Lead, Contact, or Person Account.
            8. Under Start the process, choose only when a record is created.
              Don’t choose when a record is created or edited. This setting causes duplicate targets to appear in the cadence.
            9. Click Save.
            10. In the Process Builder, click the +Add Criteria node.
            11. In the right pane, name the criteria.
              For example, call it something like Trigger for Cadence Enrollment.
            12. Under Criteria for Executing Actions, click No criteria—just execute the actions!.
            13. Click Save.
            14. In the Immediate Actions node to the right of the criteria node you just added, click +Add Action.
            15. In the right pane, choose these settings.
              • Action Type: Apex
              • Action name: Enter a name for the action.
              • Apex Class: Choose the Apex class you created previously.
              • SalesCadenceName: For Value, enter the name of your cadence.
              • TargetId: For Type, choose Field Reference. For Value, click the field and search for Lead.Id, Contact.Id, or Account.Id depending on whether you want to add lead, contact, or person account records to the cadence.
            16. Click Save.
            17. Click Activate and then click Confirm.
           
          Loading
          Salesforce Help | Article