I have two methods and I just want to know how to call them in a invocable method. Could someone please provide some sample code?
1 Answer
Please try the below code :
public without sharing class SL_CreateAccountShare
{
@InvocableVariable
public String strAccountId;
@InvocableMethod
public static void createAccountSharing(List<Id> lstId)
{
if(!lstId.isEmpty())
{
Id accId = lstId[0];
try
{
Contact objCon = new Contact(AccountId = accId, LastName = 'Test Contact');
insert objCon;
createTask(objCon.Id);
}
catch(Exception ex)
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, ex.getMessage()));
}
}
}
//another method calling from @invocable method
public static void createTask(Id contactId)
{
insert new Task(WhoId = contactId, Status = 'Open', ActivityDate = Date.today(), Subject = 'Invocable');
}
}
-
2A little explanation is probably warranted here, e.g. it has to be
static
.– Adrian Larson ♦Commented Feb 23, 2016 at 15:01