1

Any help would be greatly appreciated.

Looking at the logs it looks like when the case is created none of the variables are passed and nothing is sent to twilio - for the class above. The sms that is triggered at the same time works fine. –

The code below works perfectly in Execute Anonymous Window

String account = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
String token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
TwilioRestClient client = new TwilioRestClient(account, token);

Map<String,String> params = new Map<String,String> {
'To'   => '+xxxxxxxxx',
'From' => '+xxxxxxxxxx',                
 by Twilio
'Url' => 'https://pink-dog-6501.twil.io/assets/SampleAudio_0.4mb.mp3'
};

TwilioCall call = client.getAccount().getCalls().create(params);

However when I place it in Apex below nothing fires. As far as I can tell I followed the docs correctly and it should work

public class sendCaseCall {

   @Future(callout = true)
   public static void callPhoneService(Set<ID> caseIDs)
   {
        List<Case> newCases = [Select Id, ContactId, ContactMobile, CaseNumber, Subject 
                               from Case 
                               Where ID in :caseIDs] ;

        for (Case c : newCases){
            String account = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
            String token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
            TwilioRestClient client = new TwilioRestClient(account, token);

            Map<String,String> params = new Map<String,String> {
                'To'   => '+xxxxxxxxx',
                'From' => '+xxxxxxxxxx',                
                'Url' => 'https://pink-dog-6501.twil.io/assets/SampleAudio_0.4mb.mp3'
            };

            TwilioCall call = client.getAccount().getCalls().create(params);
            Task newTask = new Task();
            newTask.WhatId = c.id;
            newTask.WhoId = c.ContactId;
            newTask.Subject = 'Sent Case Creation Call';
            newTask.priority= 'High' ;
            newTask.status = 'Completed';
            newTask.description = string.valueOf('Call Sent') ;
            newTask.ActivityDate = System.today() ;
            insert newtask;
        }
    }
}

I have something very similar that sends an sms when a new case is created and that works perfectly

  • how is it "not working" ? any debugging? – glls Jan 10 '18 at 20:33
  • Looking at the logs it looks like when the case is created none of the variables are passed and nothing is sent to twilio - for the class above. The sms that is triggered at the same time works fine. – Cameron Houser Jan 10 '18 at 20:47
  • please make sure you include this in your post, thanks =) – glls Jan 10 '18 at 20:48
  • Ok, I updated the post as suggested. – Cameron Houser Jan 10 '18 at 21:53
  • 1
    A suggestion, don't make callouts from within a for loop as you will likely hit the max callout limit A single Apex transaction can make a maximum of 100 callouts to an HTTP request or an API call. – Bob Lopez Jan 10 '18 at 21:57
0

Took me a while and I have working method. I am using a for loop so I may have issues with that, If you have an idea how to fix that feel free to let me know.

So here is the "final" solution:

public class SendCallTriggered {

@InvocableMethod
public static void callPhoneService(List<ID> caseIDs) {
    List<Case> SelectCase = [Select Id, ContactPhone from Case Where ID in :caseIDs] ;
for (Case c : SelectCase){
   Map<String,String> params = new Map<String,String> {
'To'   => c.ContactPhone,
'From' => '+xxxxxxxxxxxxxxxx',              
'Url' => 'https://pink-dog-6501.twil.io/assets/SampleAudio_0.4mb.mp3'
};

    DoCallout(params);      
 }
  }

@future(callout=true)

private static void DoCallout(Map<String, String> params){
String account = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
String token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
TwilioRestClient client = new TwilioRestClient(account, token);
TwilioCall call = client.getAccount().getCalls().create(params);
    system.debug('TwilioCAL' + call);
}
}

Best part is I can use use Process builder to fire this code, so happy. I have not built code for handling number of rings to allow, or for voicemail. That will be next

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.