Installing the Twilio library for Salesforce's Apex programming language is a little different.
To add the library to your installation, go to https://login.salesforce.com/packaging/installPackage.apexp?p0=04ti0000000XkE0, click on Continue, and then follow the instructions.
In your code, you'll then just need to create a client object (client.cls
):
String accountSid = 'ACXXXXXXXXXXXXXXXXX'; String authToken = 'YYYYYYYYYYYYYYYYYY'; TwilioRestClient client = new TwilioRestClient(accountSid, authToken);
Tip
The Salesforce platform doesn't have support for environment variables, so we're just going to store them in the code, unlike other examples.
To send an SMS, much like with the Ruby and Python libraries, we pass in a hash (or in Apex, a Map
) of arguments (send_sms.cls
), like this:
Map<String,String> params = new Map<String,String> { 'To' => '+441708300116', 'From' => '+441290211999', 'Body' => 'This is an SMS message.'};TwilioSMS message =...