i am doing an callout to a third parity using a trigger. and I am getting the error.
CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY message: LeadCallout: execution of AfterInsert caused by: System.NullPointerException: Argument cannot be null. Class.System.EncodingUtil.urlEncode: line 30, column 1 Class.PostLeadtoBP.makePostLeadtoBP: line 13, column 1 Trigger.LeadCallout: line 3, column 1 errorCode: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY
This is the error I got from workbench doing a test with Rest Explore post to the Lead API. here is my Trigger:
trigger LeadCallout on Lead (after insert) {
For (Lead l: Trigger.new){
PostLeadtoBP.makePostLeadtoBP(l.Id, l.Phone);
}
}
Here is the Class:
public class PostLeadtoBP {
public static void makePostLeadtoBP(String leadId, String phoneNo){
Http http = new Http();
HttpRequest req = new HttpRequest();
long unixTime = System.currentTimeMillis() / 1000L;
HttpResponse res = new HttpResponse();
req.setEndpoint('/clientweb/api/v1/chats?tenantUrl=sprout.brightpattern.com×tamp='+unixTime);
req.setMethod('POST');
// Set Header for the Authorization
req.setHeader('Content-Type', 'application/json;charset=UTF-8');
req.setHeader('Authorization', '********************* appId=\"*********************\", clientId=\"WebChat\"' );
// Set the body as a JSON object
req.setBody(',parameters: {LeadID='+EncodingUtil.urlEncode(leadId,'UTF-8')+'phone='+EncodingUtil.urlEncode(phoneNo,'UTF-8') );
req.setCompressed(true); // otherwise we hit a limit of 32000
try {
res = http.send(req);
} catch(System.CalloutException e) {
System.debug('Callout error: '+ e);
System.debug(res.toString());
}
}
}