1

Clone record with its related list and update the picklist value i have created one button on record top beside the clone button, when clicked, execute code that would make a new version record with the same name and append today's date on the end of the name to distinguish it from the original.i created apex class and custom list button but the i clicked on button so my logic does'not working on this.

How should i do this ?*

Apex class

Public Class CloneVersionwithTextController{

Public List<Master_Service_Agreement_Version__c> msalist{get;set;}
public string msaid{get;set;}

Public CloneVersionwithTextController(){

    msaid = ApexPages.CurrentPage().getParameters().get('msaid');

    List<Master_Service_Agreement_Version__c> msalist = new List<Master_Service_Agreement_Version__c>();
    msalist = [SELECT ID, Name, Status__c FROM Master_Service_Agreement_Version__c WHERE Id = : msaid];
    insert msaList;
    if(msaList.size() > 0){
        msaList.get(0).Name = msaList.get(0).Name + Datetime.now();
    }
    //insert msaList;
    Master_Service_Agreement_Version__c msaCopy = msalist[0].clone(false,true);
    insert msaCopy;
    system.debug('===msaCopy===='+msaCopy);
    List<MSA_Text_Block__c> mtext = new List<MSA_Text_Block__c>();
    system.debug('===mtext===='+mtext);
    mtext = [SELECT Id, Name, Service__c, Order_within_Service__c,Master_Service_Agreement_Version__r.ID,LastModifiedBy.Name FROM MSA_Text_Block__c WHERE Master_Service_Agreement_Version__r.ID = : msaid];
    for(MSA_Text_Block__c c : mtext)
    {
        MSA_Text_Block__c mtextCopy = c.clone(false,true);
        mtextCopy.Master_Service_Agreement_Version__c = msaCopy.Id;
        mtext.add(mtextCopy);
    } 

}
}

Visualforce Page

<apex:page controller="CloneVersionwithTextController" >
   <apex:detail subject="{!msaid}" relatedList="true" title="false"/>
</apex:page>

Custom List button in Sobject

{!URLFOR("/apex/CloneVersionwithText", "")}?msaid{!Master_Service_Agreement_Version__c.Id}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.