Skip to content

Instantly share code, notes, and snippets.

@rubystar
Last active December 16, 2015 19:50
Show Gist options
  • Save rubystar/5487977 to your computer and use it in GitHub Desktop.
Save rubystar/5487977 to your computer and use it in GitHub Desktop.
1) Create an Apex Class
Steps: Click Your Name | Setup | Develop | Apex Classes and click New.
Paste the following code there.
global class asyncApex {
@future (callout=true)
public static void processAccount(Id accountId) {
sObject s = [SELECT Id, Name FROM Account WHERE Id = :accountId LIMIT 1];
// Instantiate a new http object
Http h = new Http();
// Instantiate a new HTTP request, specify the method (GET) as well as the endpoint
HttpRequest req = new HttpRequest();
// this is a test url
req.setEndpoint('https://evening-lowlands-4200.herokuapp.com/tt?id='+s.Id+'&name='+s.get('Name'));
req.setMethod('GET');
// Send the request, and return a response
HttpResponse res = h.send(req);
System.debug('hiii');
System.debug(res.getBody());
//return res.getBody();
}
}
2) Create an apex trigger that trigger the web service in the apex class
Steps: click Your Name | Setup | Customize, click the name of the object, then click Triggers and click New.
Paste the following code there.
trigger accountAsyncTrigger on Account (after insert, after update) {
for(Account a: Trigger.new){
asyncApex.processAccount(a.id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment