This is a public Forum  publicRSS


    Muthulakshmi Muthaiah
    Custom process to send SMS
    Topic posted June 19, 2017 by Muthulakshmi MuthaiahPro 
    199 Views, 8 Comments
    Custom process to send SMS

    Hi All,

    I have created the CPM code to send SMS whenever the incident status is in unresolved ,solved status.

    The code is working fine in the test harness level but while triggering it via business rule It doesn't send any SMS to the contact.

    Could anyone face this sort of issue before.

    Kindly help





    • Bastiaan van der Kooij

      you'll have to provide some code, otherwise it is getting real difficult..

    • Mig Ponce

      Note: this response discusses doing it via directly-configured business rule and not a CPM. Your doing it through CPM may be a much cleaner way to do it once you're able to make it work!

      For direct configuration: it depends on if your CPM has the ability to send SMS via the cell provider (less likely) or if you're trying to just use the business rule to send a notification (much more likely, and the solution I discuss here).

      The first case (via cell provider) is similar to how I get text messages from a number like "46507" with something like "free popcorn with your movie ticket, reply STOP to stop". That's worked out on a large scale between the company and the phone provider, as far as I know. If you have a way of doing this via CPM, then... awesome!

      What I think you might be looking to do instead is to send an alert to someone via business rule, but have that alert go to them via SMS rather than email. I have set this up many times before, it's doable but rather kludgy. You need to format it in the form of an email address that is provider-specific. I'll provide examples below.

      This can be done via just regular rule configuration-- it doesn't require a CPM per se-- but if you need the CPM for some other functionality then you still might need to do some variant of this.

      The formatting depends on the provider. For Verizon, it's (number) For Sprint, it's (number) You can find it for any provider by doing an internet search for "send email to Verizon phone number" or whatever provider you mention. I'm on Verizon, so if my cell number were (916) 555-1212, then you would use the address Then just use a business rule with a Then clause like this:
      ‚ÄčTHEN [Email Incident Information] to [Email Address] [With Subject Line] [Alert: unresolved incident needs attention].

      So what you're technically doing is not sending an SMS, but rather, sending an email to an email address that converts it to SMS for the recipient. 

      There are a few pitfalls with this to beware of: 

      1. Remember SMS length cutoffs. The "incident information" you're emailing will far exceed this and get cut off. So it's best to keep the subject line really short. And you'll likely have to tinker with it.

      2. This is hard to scale for a lot of recipients because you will need to know each person's phone number and provider, and code the THEN clause for each one accordingly. 


      I'm not a coder but if you have a way to have your CPM take a 10-digit phone number and somehow directly send an SMS to it, I'd love to hear about it! And if course if anyone has a more elegant solution than what I mention, I'm all ears!


    • Mig Ponce


      This thread discusses doing this via agreement with cell provider. If you're looking to do it for more than just a few people, that's the way to go!

    • Muthulakshmi Muthaiah

      Hi  Bastiaan,

      Thanks for the response. I start to learn the CPM process. So if I have done anything wrong, Kindly help to modify it accordingly.

      Please find the attached code.

      While testing it in CPM, it works fine. But via business rule it is not working.

      @Mig Ponce,

      Thank you for the response.




    • Danette Beal

      This is a great thread! It's always fun to see how to do it via development as well as OOB. Thanks all for your feedback.

      Danette, Community Manager

    • Rajan Davis

      I looked through the CPM; this is a great start but there are a lot of issues with your code. There's some ways to simplify this code that I left off, but you can private message me if you want some more help.

      These were the issues that I could find:

      1. In the apply function, you are declaring $i_id twice; you should declare it once.
      2. In the apply function, you are doing a check for the Incident Status ID whereas in the test harness, you set up a variable for the Incident Status LookupName
      3. You have a lot of nested conditionals which creates cyclomatic complexity; your code is really hard to debug and hard to follow.
      4. If it is possible, try to break down a lot of the conditional checking, ROQL calls, and even the curl call into smaller, singular purpose functions and call them from the apply and test harness functions. This will make it easier to isolate issues in your code.
      5. In the apply function, on line 49, you are doing a check for a returned phone number. This check is not performed in the test harness.
      6. I think the logic for
         if ((RNCPM\ActionUpdate == $action || RNCPM\ActionCreate == $action) && ($c_id != "" || $c_id != null))

        should be

         if ((RNCPM\ActionUpdate == $action || RNCPM\ActionCreate == $action) && (!empty($c_id)))

        I think you are trying to check to make sure that the $c_id variable isn't an empty string nor is it null; the empty function should check both.

      7. In the apply function, you are using MailMessage but in the test harness you are not.
      8. On lines 68 - 78 in the apply function, there is a lot of code duplication; remove the unneeded code.
      9. You might be able to get all of the data in one ROQL Call; I would test out this query:
        SELECT as first_name,
          as last_name,
                   I.primaryContact.parentContact.emails.address as email_address,
                   I.primaryContact.parentContact.phones.number as phone_number, 
          as c_id 
        FROM Incident I 
        WHERE = 1 AND 
                   I.primaryContact.parentContact.emails.addresstype.ID = 0 AND 
                   I.StatusWithType.Status.ID IN (1,2) AND
                   I.Id= <incident_id>


      Everything Mig has pointed out about the message length cutoffs and scalability is very true. I couldn't imagine implementing something like this strictly within Service Cloud as an email to be converted into a text... I would probably use Twilio.

    • Muthulakshmi Muthaiah

      Hi Rajan Davis,

      Thank you very much for the response. I will check those things from my side and let you know the results.



    • Pramod Vasudeva Murthy

      Also, embed logs inside CPM which will help you track execution of CPM. Check this link.