-2

Create apex class that can be lunched from Process Builder (for Account). Apex class should make next logic: When new Account is created, create new Task object with Subject “Negotiations with {Account.Name}”, link created Account with this Task.

public with sharing class AccountProcessBilder {
    @InvocableMethod
    public static void createTask(){
        Task newTask = new Task();
        newTask.Subject = 'Negotiations with ' + Account.Name;
    }
}
3
  • 1
    Welcome to SFSE! It looks like you have a good start on a class to suite your requirements. What is the problem you're facing? If you're getting an error message, you should include the full text of the error. You can edit your question to add these details.
    – Derek F
    Aug 2 '21 at 14:22
  • i dont know how get Account.Id and use him in newTask.Subject(( i need add account.Id in picklist ( api name = WhatId)! next my step, i need newTask.subject = Account..name
    – Moscow dev
    Aug 2 '21 at 14:28
  • Does this question about a similar issue help answer your question?
    – Derek F
    Aug 2 '21 at 14:39
0

You need to use @InvocableVariable, the first example is perfectly suitable for your problem (link to docs). You'll need to create request class, set it as List to method params and left return type as void. Code example is listed below:

public with sharing class AccountProcessBilder {
    public class requestObject {
        @InvocableVariable(required=true label='Account ID')
        public Id accountId;
        @InvocableVariable(required=true label='Account Name')
        public String accountName;
    }

    @InvocableMethod(label='Create Task')
    public static void createTask(List<requestObject> requests) {
        List<Task> toInsert = new List<Task>();
        
        for (requestObject request_i : requests) {
            toInsert.add(new Task(WhatId = request_i.accountId, Subject = 'Negotiations with ' + request_i.accountName));
        }
        
        insert toInsert;       
    }
}

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