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
vinni shreevinni shree 

Merge requires a concrete SObject type: List<Account>

Hi i wrote this code and getting this error. what I wanted to do is there is checkbox field on account so when user checks that field then all its duplicate accounts have to be merged to this main account on which checkbox is enabled but I am getting this error :Merge requires a concrete SObject type: List<Account>

I didn't understand this. please help me Thanks in advance

This is my code

 

Public class MergeAcct{
Public static void invoke(list<account> accounts){
    list<account> masterAcct=new list<account>();
    for(Account a: accounts){
        if(a.Merge__c==true){
            masterAcct.add(a);
        }
    }
    list<account> acclist=[select id, name, Merge__c from account];
    
   
    for(account acc:masterAcct){
        for(account dupacc:acclist)
        {
            if(acc.Name==dupacc.Name && dupacc.Merge__c==false){
                Merge masterAcct dupacc;
            }
        
            
        
    }  
    }
}
}

Trigger 

 

trigger mergetrig on Account (after insert, after update) {
   MergeAcct.invoke(Trigger.new);
}

Best Answer chosen by vinni shree
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Vinni,

Apologies  for the delay in the respose as I was trying many ways for the same and due to some customization in my personal org it got failed, Please check if below trigger logic works.
 
trigger MergeAccount on Account (after update) {
    Set<Id> accids= new Set<id>();
    
    For(Account acc:Trigger.new){
        if(acc.Merge__c==true && Trigger.oldmap.get(acc.id).merge__c !=TRue){
            accids.add(acc.id);
            FutureMethodRecordProcessing.processRecords(accids);
        }
    }
    
    
        
        
}
 
public class FutureMethodRecordProcessing {
@future
    public static void processRecords(set<ID> recordIds){   
   
    Account acc = [SELECT Name FROM Account WHERE Id IN :recordIds and merge__c=true];
        
        List<Account> duplicate= [select id,name from Account where Name =:acc.name and  merge__c=false];
     Database.merge(acc, duplicate, true);
    }
}

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

How do we identify which record do we need to merge. I understand that with Merge__c = true then it should be merged with some Accounts. How do we know which accounts need to be merged.

Do we need to consider the Name or some field?

Thanks,
 
vinni shreevinni shree

Hi,

On Account there is a merge field Merge__c (check box) if we check that then trigger should fire which will merge duplicate accounts (same name) and its associated contacts to the Main account, main account here is the one which has check box field.

Thank you
 

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Vinni,

Thanks for confirmarion. If there are multiple account each account having diffenet values like one has Rating as Hot and other as Cold and other as Warm so in merged Account what should be value and how is that determined?

Thanks,
 
vinni shreevinni shree

Hi praveen,

If there are different values then whatever main account has only that value should be taken.(Here the account with Merge__c field checked values are primary)

Thank you

vinni shreevinni shree

Could someone please help me with this 

Thank you

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Vinni,

Apologies  for the delay in the respose as I was trying many ways for the same and due to some customization in my personal org it got failed, Please check if below trigger logic works.
 
trigger MergeAccount on Account (after update) {
    Set<Id> accids= new Set<id>();
    
    For(Account acc:Trigger.new){
        if(acc.Merge__c==true && Trigger.oldmap.get(acc.id).merge__c !=TRue){
            accids.add(acc.id);
            FutureMethodRecordProcessing.processRecords(accids);
        }
    }
    
    
        
        
}
 
public class FutureMethodRecordProcessing {
@future
    public static void processRecords(set<ID> recordIds){   
   
    Account acc = [SELECT Name FROM Account WHERE Id IN :recordIds and merge__c=true];
        
        List<Account> duplicate= [select id,name from Account where Name =:acc.name and  merge__c=false];
     Database.merge(acc, duplicate, true);
    }
}

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
This was selected as the best answer
vinni shreevinni shree

Hi praveen,

This worked and understood as well. You are awesome Thanks a lot