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
Steve Connelly 5Steve Connelly 5 

How to user merge call with an invocable method to merge contact records.

Good afternoon all, I am working in Lightning.

I have a flow that i will be using for a self service deduping tool. I find that I need to pass data out of the flow and into Apex using an invocable method and i am not sure how to do that. i have very limited coding skills and could use some pointers.

I have looked up how to build an invocable method and how to use the merge call and tried to piece something togethe rthat will work but there are a few things I really need help with. 

For example, the code I have has places for the contact IDs but I am unsure how these are passed into the code from the flow. Do I enter the variable the IDs are stored in from the flow?

Following is what I have so far so maybe you can point me in the right direction. As I mentioned, i am very new to coding so please forgive me for any glaring mistakes. 

It is fine if you can just point me in the direction of some example sthat might help too.

All I need to do is pass two contact IDs through an ivocable method from a flow and have the method merge the two and delete the duplicate once merged.

Any help at all will be greatly appreciated.
Best regards,
Steve
Best Answer chosen by Steve Connelly 5
Danish HodaDanish Hoda
Hi Steve,
You can refer to - https://developer.salesforce.com/forums/?id=9060G0000005nusQAA

All Answers

Danish HodaDanish Hoda
Hi Steve,
You can refer to - https://developer.salesforce.com/forums/?id=9060G0000005nusQAA
This was selected as the best answer
Steve Connelly 5Steve Connelly 5
Forgot to add my code in the first section:

public class InvocableMethodsTest {
          @InvocableMethod(label='Invocable Methods test' description='Testing the appearance of Invocable Methods in Flow Builder')
        public static void  InvocableMethodsTest(List<et4ae5.JBIntFireEventParams> fireEventParamList) {

    }
    
// Insert new Contacts 
List<Contact> ls = new List<Contact>{ 
    new Contact(Id='0034100002GrtDTAAZ'), 
        new Contact(Id='0034100001tHiVeAAK')  
        };                                         
{
insert ls; 
// Queries to get the inserted Contacts  
Contact masterCont = [SELECT Id, Name FROM Contact WHERE Id = '0034100002GrtDTAAZ' LIMIT 1];  
Contact mergeCont = [SELECT Id, Name FROM Contact WHERE Id = '0034100001tHiVeAAK' LIMIT 1]; 

try {
    merge masterCont mergeCont;
} catch (DmlException e) {
    // Process exception
    System.debug('An unexpected error has occurred: ' + e.getMessage());
}
}