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 java script does'not working on this.so below error occour during click on the button.
How should i do this ?
List has no rows for assignment to SObject
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('id');
List<Master_Service_Agreement_Version__c> msalist = new List<Master_Service_Agreement_Version__c>();
Master_Service_Agreement_Version__c msa = [SELECT ID, Name, Status__c FROM Master_Service_Agreement_Version__c WHERE Id = : msaid];
Master_Service_Agreement_Version__c msaCopy = msa.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 = : msa.Id];
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);
}
system.debug('===msaList===='+msaList);
if(msaList.size() > 0){
msaList.get(0).Name = msaList.get(0).Name + Datetime.now();
}
update msaList;
}
}
Visualforce Page
<apex:page controller="CloneVersionwithTextController" >
<apex:detail subject="{!msaid}" relatedList="true" title="false"/>
</apex:page>
List button code
{!URLFOR("/apex/CloneVersionwithText", "")}?msaid={!Master_Service_Agreement_Version__c.Id}