ObJective: I am attempting to create a new prospect in Pardot when a lead that had no email gets updated with an email (Pardot will sync accounts but until the lead email exist there is no prospect to sync, hence this trigger)
Problem: Using the afterUpdate trigger context I was able to verify the email status to make this call only when expected, but the problem is making the dynamically generated email "execute." So my Pardot class method creates the URL like so:
String add_prospect = 'https://pi.pardot.com/prospect/sync/email/'+l.Email+'?lead_id='+l.Id+'&sessionid='+UserInfo.getSessionId()+'&serverurl='+l.Partner_Server_URL__c;
Then I send the URL to the sendHttpRequest()
method and from what I can see the developer console shows success but my Pardot account does not show the new account. In addition when I take the generated URL from the developer console and paste into address bar and run it I get directed to Pardot where the prospect is successfully created.
Here is the Developer Console response:
13:02:58:065 CALLOUT_REQUEST [38]|System.HttpRequest[Endpoint=https://pi.pardot.com/prospect/sync/email/[email protected]?lead_id={my_lead_id}&sessionid={my_sessionid}&serverurl=https://cs10.salesforce.com/services/Soap/u/9.0/{org_id}, Method=POST]
13:03:00:421 CALLOUT_RESPONSE [38]|System.HttpResponse[Status=OK, StatusCode=200]
And here is the method in question:
@future (callout=true) // future method needed to run callouts from Triggers
static void sendHttpRequest(String url){
/* 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();
req.setEndpoint(url);
req.setMethod('POST'); //I tried GET as well
req.setTimeout(60000);
// Send the request, and return a response
HttpResponse res = h.send(req);
}
This is my first trigger/class so apologies if I'm missing something obvious but hoping if that's the case that the SF community can help me out. If there is a details I left out that you need let me know in comments and I'll get that added
System.debug(res.getBody());
or otherwise check what body comes back. If there is a problem with the session ID you are passing, a HTML login page is likely to be returned with a status of 200 and because the request is unauthenticated no change will be made.17:17:02:137 USER_DEBUG [39]|DEBUG|<!doctype html>
getBody()
comes back with html for what appears is the Pardot login screen as you predicted. So what do you suggest I do about this?