I am attempting to start this Apex class with Process Builder, triggered by a field change. I've never done this before and I'm unsure what invoke code needs to be added in order to accomplish this. I tried adding @InvocableMethod but I'm getting an error telling me this :
Compile Error: Unsupported parameter type String.
Valid invocable parameters must be List types like List<T>
where T is a supported type at line 26 column 27
It is a class which is currently being invoked with a Lightning Component button in a record.
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);
if(contactToBeupdate.size() > 0){
update contactToBeupdate;
}
return 'Updated Successfully';
}
}
//Calling Http_Utility_Pardot class pardotCreateProspect method for the creation of Prospect record.
String returnedResponseFromPardot = Http_Utility_Pardot.pardotCreateProspect(new Set<Id> {contactToBeupdate[0].Id});
Thank you very much for any help you can give with this. It is very appreciated.
Best Answer
String
is not an allowed argument because Invocable Methods must be passed Lists. Below is taken from the Salesforce developer documentation on Invocable Methods. You will need to make your method accept aList<String>
and return aList<String>
or a another List type.InvocableMethod Considerations
Implementation Notes
Inputs and Outputs
If the return type is not Null, the data type returned by the method must be one of the following: