Skip to content

Instantly share code, notes, and snippets.

@amitastreait
Created March 25, 2022 05:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amitastreait/6bac50c28c2e539e268f03425ca1abc8 to your computer and use it in GitHub Desktop.
Save amitastreait/6bac50c28c2e539e268f03425ca1abc8 to your computer and use it in GitHub Desktop.
public class TwilioService {
@InvocableMethod(label='Send Verification SMS' description='Send Verification SMS' category='Login' callout=true)
public static List<TwilioService.InputWrapper> run(List<TwilioService.InputWrapper> code){
sendSMS(code.get(0));
return code;
}
private static void sendSMS(TwilioService.InputWrapper input){
HttpRequest httpReq = new HttpRequest();
httpReq.setEndpoint('callout:Twilio'+'/2010-04-01/Accounts/'+SYSTEM.LABEL.TWILIOACCOUNTSID+'/Messages.json');
httpReq.setMethod('POST');
httpReq.setHeader('Content-Type', 'application/x-www-form-urlencoded');
String body = 'From='+EncodingUtil.urlEncode(System.Label.TWILIO_PHONE, 'UTF-8')+'&Body='
+EncodingUtil.urlEncode('Salesforce has requested you to verify your idendity. Use below code to verify '+input.code, 'UTF-8')
+'&To='+EncodingUtil.urlEncode('+91'+input.phone, 'UTF-8');
httpReq.setBody(body);
HttpResponse response = (new Http() ).send(httpReq);
System.debug(' response '+response.getBody() );
if(response.getStatusCode() == 200){
}else{
}
}
public class InputWrapper{
@InvocableVariable(label='Verification Code' required=false)
public String code;
@InvocableVariable(label='Salesforce User Contact No' required=false)
public String phone;
@InvocableVariable(label='Country Code with +' required=false)
public String countryCode;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment