function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Carter85Carter85 

Need Assistance with @InvocableMethod

I'm new to trying to use the @InvocableMethod with the process builder and could use a little guidance as I'm not finding the salesforce examples all that helpful.
My class with the method is below:
public without sharing class CM_KeyReplacementEmailSender {
	
	private static String displayName	= 'claims@maximusautogroup.com';
	private static String replyEmail = 'claims@maximusautogroup.com';
	
	@InvocableMethod	
	public static void send(List<ID> id){
		
		List<MG_Claim_Issue__c > iss = [SELECT ID, Name, Contact_Email__c, MAG_Claim__r.Name, Customer_Name__c, Where_will_repair_occur__c FROM MG_Claim_Issue__c WHERE ID =:id];
		Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); 
		
		String claimNum = iss[0].MAG_Claim__r.Name;
		String issNum = iss[0].Name;
		
		String subject = 'Information regarding open claim with Maximus Auto Group # ' + claimNum;
		
    	String address = iss[0].Contact_Email__c;
    	String[] toAddress = address.split(':', 0);
    	
    	email.setSubject(subject);
		email.setToAddresses(toAddress);
    	email.setSenderDisplayName(displayName);
    	email.setReplyTo(replyEmail);
    	
    	Note note = new Note();
	 	note.Title = 'Email RE: '+ issNum + ' (' + DateTime.now() + ')';
		note.ParentId = iss[0].Id;	
			
    	if(iss[0].Where_will_repair_occur__c == 'Selling Dealer'){
               
        	// Sets the paramaters of the email
			email.setHtmlBody('<p>Test</p>');
    		
    		
			}
		else{
			// Sets the paramaters of the email
			
			email.setHtmlBody('<p>Test2</p>');
    		
			
			}
			// Sends the email
			Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email}); 	
			note.Body = email.plainTextBody;
			insert note;
			
			
			}

}
I've gotten it to covered with a test class, but when I try and Invoke it from a process builder condition meant to supply the id variable in a practical test I'm not seeing any results.  I'm wondering what I may be missing and would appreciate any insight.
 
BalajiRanganathanBalajiRanganathan
WHERE ID =:id should be changed to WHERE ID in :id
Carter85Carter85
Thanks for the syntatic correction, but it looks like the error was somewhere in the process builder trigger criteria itself which was why it was working in my test class but not practically and once I tried a test with no criteria it fired with both versions of the query.
Amdrodd TechnologiesAmdrodd Technologies

Hi Carter,

Few clarifications needed.

- Can you perform emailing with Email Alerts in Process Builder and create note using invocable apex method?
- Try removing all emailing codes and check whether the class is been called.
- I believe you are passing MG_Claim_Issue__c record id to input parameter of the invocable method.
- Try debugging whether the method is called or not usung system.debug.

Please let me know how it turned out and can take it forward from there.

Mark RutterMark Rutter
I am also new to trying to use the @InvocableMethod with the process builder and could use some help.
I have successfully written an Apex class with an Invocable Method copied from an example:

public class AccountQueryAction {
  @InvocableMethod(label='Get Account Names' description='Returns the list of account names corresponding to the specified account IDs.')
  public static List<String> getAccountNames(List<ID> ids) {
    List<String> accountNames = new List<String>();
    List<Account> accounts = [SELECT Name FROM Account WHERE Id in :ids];
    for (Account account : accounts) {
      accountNames.add(account.Name);
      system.debug('Acct Name = '+ account.name);
      system.debug('ID = '+ account.id);
    }
    return accountNames;
  }
}

This gets the account ID and Name.  The account ID is supplied via the Process Builder as a Call Apex action
where the ID is specified in the 'Set Apex Variables' section of the Call Apex action.

This is fine if I want to know something about a specified Account record ID, but how can I get the current Account record ID? 

 
manan patel 7manan patel 7
when you select apex from process builder that time belove the apex class name plue symbol click on that and select " ids " -->" refrence " --> and Account id (this account id is your current Account record ID)
 
farukh sk hdfarukh sk hd
You should use like this ,

select id from Testobject2__c where Testobject1__c in:objId ,

For more details pleasee visit,
https://www.sfdc-lightning.com/2018/11/call-apex-code-from-process-builder-in.html