You need to sign in to do that
Don't have an account?
Tolby Hunt
SMS to lead upon creation
Hello everyone! i am trying to send a text to my leads with twilio with a trigger event once they are created. I am new to salesforce so most of this is a whirlwind to me. If you could fix my code and then explain it that would be best.
Thanks
Apex Class
and my trigger
Apex Trigger
Let me know
Thanks!
Thanks
Apex Class
public class Send_SMS_ControllerLead { public String smsBody {get; set;} public boolean hasNumber {get; set;} public final String fromNumber = '+1xxxxxxxxx';// get it from twilio //after login click Phone Numbers tab in left sidebar public string dialCode = '+1'; // Add your dial Code of your country. public Send_SMS_ControllerLead(ApexPages.StandardController controller) { hasNumber = true; } public static void Send() { String account = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; // Account SID on home tab String token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'';//AUTH Token on home tab TwilioRestClient client = new TwilioRestClient(account, token); Id leadId = ApexPages.currentPage().getParameters().get('id'); String baseUrl = URL.getSalesforceBaseUrl().toExternalForm(); Lead a = [SELECT Phone FROM Lead WHERE Id = :leadId]; if(a.Phone != null) { String phoneNumber = a.Phone; if(!phoneNumber.Contains('+1')) phoneNumber = '+1'+phoneNumber;// If by default dialCode is not //on Phone number we will ad it. System.debug('phoneNumber'+phoneNumber); Map<String,String> params = new Map<String,String> { 'To' => phoneNumber, 'From' => '+1xxxxxxxxxx', 'Body' => 'Thanks for applying with Fundwise. An email was sent to you for the next step that will expedite the process. An agent will contact you shortly.' }; TwilioSMS sms = client.getAccount().getSMSMessages().create(params); SMS_Lead__c sentSMS = new SMS_Lead__c(From__c = '+1xxxxxxxxxxx',To__c = phoneNumber, Body__c = 'Thanks for applying with Fundwise. An email was sent to you for the next step that will expedite the process. An agent will contact you shortly.'); insert sentSMS; } } }
and my trigger
Apex Trigger
trigger SMS_To_New on Lead (after insert, after update) { Send_SMS_ControllerLead.Send(); }
Let me know
Thanks!
I would also like to text out when a specific field with a picklist has a certain item. If they have that item i would like to send them a text message. I would set it up a very similar Apex Class most likely, not sure how to check if it has that field with the correct info. Thanks Again
You need to send Lead record from trigger to handler class like below
And your Handler class should be like below
Let us know if this will help you
Trigger like below
Let us know if this will help you
But it still isnt sending the texts...
Setup->Apex Jobs.
NOTE:- Please check your old code was working on not.