Guest User

Untitled

a guest
Oct 23rd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. trigger LeadCallout on Lead (after insert) {
  2. For (Lead l: Trigger.new){
  3. PostLeadtoBP.makePostLeadtoBP(l.Id, l.Phone);
  4. }
  5.  
  6. public class PostLeadtoBP {
  7. public static void makePostLeadtoBP(String leadId, String phoneNo){
  8. Http http = new Http();
  9. HttpRequest req = new HttpRequest();
  10. long unixTime = System.currentTimeMillis() / 1000L;
  11. HttpResponse res = new HttpResponse();
  12. req.setEndpoint('/clientweb/api/v1/chats?tenantUrl=sprout.brightpattern.com&timestamp='+unixTime);
  13. req.setMethod('POST');
  14. // Set Header for the Authorization
  15. req.setHeader('Content-Type', 'application/json;charset=UTF-8');
  16. req.setHeader('Authorization', '********************* appId="*********************", clientId="WebChat"' );
  17. // Set the body as a JSON object
  18. req.setBody(',parameters: {LeadID='+EncodingUtil.urlEncode(leadId,'UTF-8')+'phone='+EncodingUtil.urlEncode(phoneNo,'UTF-8') );
  19. req.setCompressed(true); // otherwise we hit a limit of 32000
  20. try {
  21. res = http.send(req);
  22. } catch(System.CalloutException e) {
  23. System.debug('Callout error: '+ e);
  24. System.debug(res.toString());
  25. }
  26. }
Add Comment
Please, Sign In to add comment