You need to sign in to do that
Don't have an account?

Can I call this class with a trigger ?
I'm trying to call this class which uses @Future with a trigger. I'm unsure how to reference the class in the trigger. Also, since I am attempting to trigger the code with a field change it is difficult because I can't have the callout execute after an update. So, I'm not sure what trigger context should be used as well.
Here is my trigger :
trigger Trigger_ProgramContactRole on Program_Contact_Role__c (after insert, after update, before insert, before update ,after delete) { //Checking for the event type if(Trigger.isAfter){ if(Trigger.isInsert){ } if(Trigger.isUpdate){ }
But I don't know how to start this class with it :
public class UpdateContactPCRController { @InvocableMethod public static String updateContact(String recordId){ String contactId = ''; List<Contact> contactToBeupdate = new List<Contact>(); if(String.isNotBlank(recordId)){ List<Program_Contact_Role__c> programContacList = [SELECT Id,Contact__c,Program_Name__c FROM Program_Contact_Role__c WHERE Id =:recordId AND Contact__c != null]; contactId = programContacList[0].Contact__c; if(String.isNotBlank(contactId)){ contactToBeupdate = [Select Id,Pardot_Action_Trigger__c,PCR_Register_Button_Link__c,PCR_URL_for_UI__c FROM Contact Where Id =: contactId Limit 1]; contactToBeupdate[0].Program_Contact_Role_Id__c = recordId; } List<Program_Communication_Recipients__c> programCommunicationRecs = [Select Id,Name, Program_Communication__r.Program__r.Buyer__r.Name,Receipient__c, From Program_Communication_Recipients__c Where Program_Communication__r.Program__c =: programContacList[0].Program_Name__c AND Receipient__c =: programContacList[0].Id]; contactToBeupdate[0].PCR_Welcome_Message__c = String.valueOf(programCommunicationRecs[0].Program_Communication__r.Welcome_Message__c); pardotCallout(contactToBeupdate[0].Id); { @future(callout=true) public static void pardotCallout(String contactId) { String returnedResponseFromPardot = Http_Utility_Pardot.pardotCreateProspect(new Set<Id> {contactId}); // new treatment here with the returned value included DML operations. } if(contactToBeupdate.size() > 0){ update contactToBeupdate; } return 'Updated Successfully'; } }
Any help you can give would be very appreciate. Thank you.
Hi Leo,
Try the below code
pardotCallout needs to be defined as a separate method.
Hope this helps.
All Answers
The below article mentions a way to call a future method where callout is true.
>> https://www.mstsolutions.com/technical/passing-sobject-to-future-methods-in-salesforce/#:~:text=The%20Future%20Annotation%20is%20used,only%20return%20void%20data%20type.
>> https://help.salesforce.com/articleView?id=000330691&type=1&mode=1
I hope this helps and in case if this comes in handy can you please choose this as the best answer so that it can be useful for others in the future.
Regards,
Anutej
Anutej,
I've looked through those articles and I still don't see what is wrong with my code. I moved the IF( up to be within the same section as @future and I am still getting the error :
The future method appears to be in correct syntax.
Hi Leo,
Try the below code
pardotCallout needs to be defined as a separate method.
Hope this helps.
Thank you very much for this. Do I need to include these lines within that method ?
You cannot call the whole class technically, but since all your logic is inside methods and maybe constructor, you can call them.
Please mark the answer that helped you fix this as the best answer.