Hi ,Please refer below code:- You have to do little bit enhancement here.
Hope this helps you.If this helps you, please mark it as solved---------------------------------------------------------------------------------------------
<apex:page controller="CustomMerge">
<apex:form>
<apex:pageBlock>
<apex:commandButton value="merge" action="{!mergeRecords}"/>
<apex:pageBlockSection>
<apex:inputField value="{!childrecord.Parent__c}" label="Merge Into"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
----------------------------------------------------------------------------------------------------
public class CustomMerge{
public MergeObj__c childRecord{get;set;}
public List<Batch__c> btList = new List<Batch__c>();
public List<Batch2__c> bt2List = new List<Batch2__c>();
public CustomMerge(){
childRecord = [Select id,name,Parent__c,(select id,name,MergeObj__c from Batches__r),(select id,name,MergeObj__c from Batches2__r) from MergeObj__c where id =: apexpages.currentpage().getparameters().get('id')];
}
public void mergeRecords(){
if(childRecord != Null){
MergeObj__c parentRecord = [Select id,name from MergeObj__c WHERE id=: childRecord.Parent__c];
for(Batch__c bt : childRecord.Batches__r){
bt.MergeObj__c = parentRecord.id ;
btList.add(bt);
}
for(Batch2__c bt : childRecord.Batches2__r){
bt.MergeObj__c = parentRecord.id ;
bt2List.add(bt);
}
update btList ;
update bt2List ;
delete childRecord ;
}
}
}
1 respuesta