Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Apex class to call external webservice, This class can be called using trigger
- public class ActiveCampaignFieldUpdateCallouts {
- @future (callout=true)
- public static void UpdateActiveCompaign(String ContactIds){
- String username='';
- String password='';
- HttpRequest req = new HttpRequest();
- HttpResponse res = new HttpResponse();
- Http http = new Http();
- req.setHeader('Content-Type', 'application/x-www-form-urlencoded');
- req.setEndpoint('/admin/api.php?api_action=contact_edit');
- Blob headerValue = Blob.valueOf(username +':' +password);
- req.setMethod('POST');
- //req.setBody('userName=' +EncodingUtil.urlEncode(userName, 'UTF-8') +"&password=' + EncodingUtil.urlEncode(password, 'UTF-8') + '&cardNumber=' +cardNumber); // Request Parameters
- //req.setCompressed(true); // otherwise we hit a limit
- try{
- res = http.send(req);
- //check the response
- if(res.getStatusCode() == 200) {
- //update contact
- Contact conn = new Contact(id=ContactIds);
- conn.Description = res.getBody();
- update conn;
- }else{
- System.debug('Callout failed: ' + res);
- }
- }catch(System.CalloutException e){
- System.debug('Callout error: '+ e);
- System.debug(res.toString());
- }
- }
- }
Add Comment
Please, Sign In to add comment