InsideSales.com
InsideSales.com
InsideSales.com Menu

Appendix A - Apex Trigger to Initiate Immediate Response

Introduction

As you may already know, our system features two options for immediate response: ResponsePop and Call Now. These features provide Salesforce users with a way to respond to incoming web leads with impressive speed.

A ResponsePop is routed to an ACD or IVR and triggers an inbound call to an available agent. When the agent accepts it, the system makes the call to the prospect. This option is advantageous for agents who make a lower volume of calls and may be multitasking while waiting for calls to arrive. A Call Now acts more like a typical outbound call. It is inserted at the top of a Seek or Domino list and (if set to do so) also notifies agents in the list that this high priority lead is available. This option is faster when you have a team of agents who make a higher volume of calls.

Technical Limitations

The current "immediate response" process in Salesforce utilizes workflow rules. A record comes in, and a workflow rule initiates an outbound message containing the lead information. At that point, it hits a URL on our side, which then schedules an "immediate response" worker.

There is an obstacle here. Salesforce workflow rules schedule outbound messages for delivery and can sometimes run up to 20 minutes behind schedule. In this case, a company's ability to respond to an incoming web lead can be no faster than 20 minutes.

This page shows you a way to address these delays and get Salesforce immediate response times down by using an alternate method. Instead of the previously mentioned wait time, response times with this method are usually only a matter of seconds.

A Faster Alternative

The method described on this page describes how to change the process on the Salesforce side, by eliminating the need to use workflow rules. Instead you can use an Apex Trigger, configured to work with lead posts coming off the Web. When new leads are added to the system, the trigger will run as part of the lead addition "validation."

The trigger will be configured to include / parse relevant data from the Salesforce record, and pass it to a URL housed on the client's InsideSales.com domain. The URL will point to a PHP script that spawns a PHP process. The process will immediately sync records via the Salesforce API, so they get added to the IS.com database. Then the system will trigger the appropriate immediate response action.

Example Code

IMPORTANT DISCLAIMER:

Because the APEX Code for this solution must be installed and maintatined by the customer, InsideSales.com does not accept responsibility for the programming or maintainence of your Salesforce Apex Trigger or Class. The information provided below is only an example, provided for your information. We recommend that it be used only by a qualified Salesforce APEX developer or consultant! Altering Apex Trigger code can be useful, but also carries the potential for negative consequences on system functionality if it is done incorrectly. It should be managed only by an experienced developer. InisideSales.com can not take responsibility for any code alteration performed by you or others under your direction.

Apex Code

There are two pieces to the actual Apex code -- the trigger itself, and an associated Apex Class. Both need to be added to Salesforce.

The Apex Class is generic and will be explained in the section immediately following this paragraph. Parts of the code for the Apex Trigger will be individual to you and your system. We will help you determine exactly what to enter.

It may be helpful to test and make changes to the trigger and class in your organization’s sandbox environment on Salesforce first before putting it into your main system. This can help to avoid and detect problems with configuration or other code and packages.

The Apex Class

First, you will need to create a new Salesforce Apex class. The code for this class is provided below. You don't need to make any changes to this class code; you simply need to add it to Salesforce. To do this, follow these steps.

  1. Go to Username > Setup
  2. Click Develop in the sidebar
  3. Click Manage your Apex Classes
  4. Click New
  5. Paste the code displayed below these steps into the main window.
  6. Click Save.

 

 

[START CODE]

global class HTTPRequestSender{

    @future (callout=true)

    Public static void sendHTTPRequest(String url, String body){

        Http http = new Http();

        HttpResponse res = new HttpResponse();

        HttpRequest req = new HttpRequest();

        req.setEndpoint(url);

        req.setBody(body);

        req.setMethod('POST');

        try {

            res = http.send(req);

        } catch(System.CalloutException e) {

            System.debug('CalloutException: '+ e);

            System.debug(res.toString());

        }

     }

}

[END CODE]

 

 

The Apex Trigger

The trigger itself determines the method for the immediate response -- RepsonsePop or Call Now, with their associated ACD ID or dialer initiative ID. In our example, when a new lead enters Salesforce, with a Lead Source = “Web”  InsideSales.com will spawn a ResponsePop to an available agent.  This is a common trigger criteria, but depending on how you want it to act, you'll need to tell it what to do! We'll guide you through this process with our example, but cannot explain everything that can be done with this code in the brief scope of this document. Only a qualified Salesforce APEX developer or consultant should attempt to use the information below.

First, here is the full code. Notice the text highlighted in red and blue. These parts will need to be altered according to instructions we will give you. The green section is also identified for reference. It does not need to be altered. However, a qualified developer may wish to alter this section in order to tailor the Apex Trigger more specifically to your needs.

 

Trigger Code Sample

 

[START CODE]

trigger ImmediateResponse on Lead (after insert) {

    ID[] ids = new List<ID>();

    String url = 'https://subdomain.insidesales.com/do=noauth/immediate_response';

    String body;

    for (Lead l : Trigger.new) {

        if (l.LeadSource == 'Web') {

            ids.add(l.Id);

        }

    }  

    if (!ids.isEmpty()) {

       body = 'method=responsepop&inbound_initiative_id=1&ids='+EncodingUtil.urlEncode(JSON.serialize(ids), 'ISO-8859-1');

       HTTPRequestSender.sendHTTPRequest(url, body);

    }

}

[END CODE]

 

 

The Blue Section

The trigger code needs to have the subdomain updated in order to work with your system. It is contained in this code line:

String url = 'https://subdomain.insidesales.com/do=noauth/immediate_response';

We will work only with the text appearing in blue in the overall code shown earlier in this document.

We must change the subdomain in the blue text to be the your specific InsideSales.com subdomain. For example:

subdomain.insidesales.com

Finding your Subdomain

If you're not sure what your subdomain is, here is how to find it.

  1. Go to the InsideSales Tab.
  2. Click Domino Lists or click Seek Lists.
  3. Click Launch next to any list. The list will open in a new window.
  4. Notice the URL in the navigation bar at the top of the new window. It will be similar to the example provided. The subdomain is the text between https:// and .insidesales. Use this part of the url to replace the portion of the blue code that reads "subdomain" in our example.

Domain Site Reference

This is not part of the Apex Trigger code, but in order to work, the trigger itself references an InsideSales.com domain site. This is the same domain used to alter the blue section of the code. This site needs to be added to Salesforce as an allowed remote site. To add the new remote site, follow these steps:

  1. Click Username > Setup
  2. Click Security Controls in the sidebar.
  3. Click Remote Site Settings.
  4. Click New Remote Site.
  5. Add your entire blue section text into the URL field. For example:

    https://subdomain.insidesales.com

  6. Enter whatever you like in the Remote Site Name field.
  7. Click Save.

The Red Section

To work properly, the red code shown in the example also needs to be updated. It is contained in this line:

body = 'method=responsepop&inbound_initiative_id=1

This section of code determines what kind of immediate response is given. Several options exist for you to put into the code. Let's break the line above down to show you the components and options.

In our example, we have a ResponsePop going an ACD. You could also have a ResponsePop that goes to an IVR, a Call Now that goes to a specific dialer list, or a Call Now that goes to all dialer lists.

Here are all the options you can use and the code you'll need to enter into the red section for each one. Keep the example above in mind as a model. We will change only the text appearing in red in the overall code shown above. For many options, you will also need to enter a unique ID number. See the instructions immediately after the chart for more information.

  ResponsePop with an ACD ResponsePop with an IVR Call Now With a Specific Dialer List Call Now for All Dialer Lists
Entry Code

(with ID number example 1)
responsepop&inbound_initiative_id=1 responsepop&ivr_id=1 call_now&dialer_initiative_id=1 call_now
How to Find the Specific ID Number for the Code See the section of this document entitled "ResponsePop with an ACD" under the "Finding ID Numbers" heading below this chart. See the section of this document entitled "ResponsePop with an IVR" under the "Finding ID Numbers" heading below this chart. See the section of this document entitled "Call Now with a Specific Dialer List" under the "Finding ID Numbers" heading below this chart. No ID number is needed for this code option. Enter it exactly as shown above.

Finding ID Numbers

Notice the numbers at the end of the code after id= in most of the entries above. These numbers are specific to the ACD, IVR, or dialer list and must be entered correctly for the code to work. Here is how to find each of the relevant values.

ResponsePop with an ACD

Follow this path:

InsideSales Tab > Manage ACDs

Then hover your mouse for several seconds over the Edit button next to the ACD you wish to use.

The lower left corner of your browser will display a URL that ends with the appropriate ID number for this ACD.

ResponsePop with an IVR

Follow this path:

InsideSales Tab > Manage IVRs

Then hover your mouse for several seconds over the Edit button next to the IVR you wish to use.

The lower left corner of your browser will display a URL that ends with the appropriate ID number for this IVR.

Call Now with a Specific Dialer List

  1. Go to the InsideSales Tab
  2. Click Seek Lists (if the list you wish to use is a Seek List) or Domino Lists (if the list you wish to use is a Domino List).
  3. Click Launch next to the name of the dialer list you wish to use. The list will open in a new window.
  4. Find the ID number in the URL in the navigation bar at the top of the new window. It will be the number between id= and the & symbol. This is located approximately in the middle of the URL. This is the ID number to use when entering the code for this dialer list.

The Green Section

The green section of code determines which incoming leads will qualify for an immediate response through the Apex Trigger. Our example will offer an immediate response to any lead with a Lead Source of "Web." This is only one example.

If desired, there are endless possibilities that can be utilized to define which leads will qualify for an immediate response through the Apex Trigger and which will not. However, explaining every detail of how this portion of the code could work is beyond the scope of this document. The green section is identified only to inform a qualified APEX developer about which section of the code would need to be altered in order to accomplish this.

For reference material on how Apex Triggers can be used that is relevant to this line of code, your programmer may wish to visit the following Salesforce pages:

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_lead.htm

http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_expressions_operators_understanding.htm

Entering the  Apex Trigger

Once you have successfully determined your code in its entirety (by replacing the code in the red, blue, and possibly green sections), enter the code in its entirety by following these steps.

  1. Click Username > Setup
  2. Click Customize in the sidebar.
  3. Click Leads
  4. Click Triggers
  5. Click New
  6. Paste your entire Apex Trigger code, (including your individualized blue, red, and green passages) into the the main window.
  7. Click Save.

Release Notes

Find our most recent release notes.

Forum

Our InsideSales.com community forum is coming soon.

Advanced Training Guides

Advanced training for the PowerDialer for Salesforce.

Have questions?

We're happy to help. An InsideSales.com expert is just a phone call away.

(866) 593-2807

Mon-Fri 6-7 MST

Back To Top

© 2004–2014 InsideSales.com, Inc. all rights reserved. Use of the InsideSales.com service and this Web site constitutes acceptance of our Terms of Use and Privacy Policy. InsideSales.com technology is protected by the following United States Patents: 8078605, 8325738, 8352389, 8510382, 8566419.