0

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?

5

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');
    }
}
| improve this answer | |
  • 1
    A little explanation is probably warranted here, e.g. it has to be static. – Adrian Larson Feb 23 '16 at 15:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.