Last active
April 28, 2023 15:47
-
-
Save mhamzas/e9d2dfc70611b7b0e00a9a7e17bf3778 to your computer and use it in GitHub Desktop.
Apex Invocable Class with multiple variables/parameters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| global class InvocableMethodcls { | |
| /*An invocable variable used as input or output variables in the process builder*/ | |
| global class ActionRequest { | |
| @InvocableVariable(required = true) | |
| public ID leadId; | |
| @InvocableVariable | |
| public String phone; | |
| @InvocableVariable | |
| public String email; | |
| @InvocableVariable | |
| public Lead leadObj; | |
| @InvocableVariable | |
| public String firstName; | |
| @InvocableVariable | |
| public String lastName; | |
| } | |
| //This invocable method is used for processing the business by taking the input from process builder | |
| @InvocableMethod(label = 'Invoke Business Logic') | |
| global static void invokeService(List < ActionRequest > requests) { | |
| for (ActionRequest requestObj: requests) { | |
| //Accessing the values from process builder when record is inserted | |
| System.debug('requestObj.leadId@@:' + requestObj.leadId); | |
| System.debug('requestObj.firstname@@:' + requestObj.firstname); | |
| System.debug('requestObj.lastname@@:' + requestObj.lastname); | |
| } | |
| //We can write our own business logic herer. | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @isTest | |
| public class UpdateFieldActionTests { | |
| @isTest | |
| public static void InvocableMethod_Success(){ | |
| // arrange | |
| final String firstName = 'John'; | |
| final String lastName = 'Wick'; | |
| final String phone = '1112223333'; | |
| final String email = '[email protected]'; | |
| Lead lead = new Lead(); | |
| lead.lastName = lastName; | |
| lead.email = email; | |
| insert lead; | |
| InvocableMethodcls.ActionRequest request = new InvocableMethodcls.ActionRequest(); | |
| request.leadId = lead.Id; | |
| request.phone = phone; | |
| request.firstName = firstName; | |
| request.lastName = lastName; | |
| request.email = email; | |
| request.leadObj = lead; | |
| // act | |
| InvocableMethodcls.updateFields(new List<InvocableMethodcls.ActionRequest> {request}); | |
| // Your Logic | |
| /* | |
| Lead updatedLead = [SELECT Id, lastName FROM Lead WHERE Id = :lead.Id]; | |
| // assert | |
| System.assertEquals(lead.lastName, updatedLead.lastName); | |
| */ | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment