function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Integration to pull data from Pardot - Need help with approach

We have Pardot integrated with our Salesforce (Enterprise) org. The integration isn't great. In particular, we have a custom setup in Salesforce to manage the opt-in or opt-out status of Contacts / Leads. It's a drop-down called Communication Status and it's value drives workflow rules that auto-update the fields Email Opt Out and a custom checkbox called Receive Marketing. The problem is that Pardot tries to sync directly with the Email Opt Out field, which my workflows override. So the two systems end up out of sync in terms who has opted out.


As a first step, I want to use the Pardot API to bring back the opted out status for a record in Pardot and put it into a field on that record in Salesforce. Trouble is, I need to do issue an HttpRequest to do that, which can't be done from a Trigger. I want the status in Salesforce to be as "real-time" as possible. 


I'm looking for guidance in how I should approach building this feature and improving the integration between the two systems. I think my best bet is a scheduled Apex class, but I'm not entirely sure.


It's true you can't do a callout from a trigger, but you can call an @future method, which can perform a callout.  It operates in a different context, and the ETA isn't known - but it might get you closer to something "realtime"


What's the syntax for that exactly? I tried using that in several ways, both by marking the Trigger @future, and creating a separate class, marking that @future, and then calling the class function from the Trigger. Couldn't get either one to work.


More the latter, create an Apex class with the @future annotation on the method and call that from the trigger.


The secret handshake, however, maybe declaring the @future with callout equal to true:



public static void updateInfo(string Id) {