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 ?

enter image description here

Apex class:-

global class CloneVersionwithText
webservice static void cloneMSAVersion(Id msaId) // you can pass parameters
   List<MSA_Text_Block__c> MText = new List<MSA_Text_Block__c>();
   Master_Service_Agreement_Version__c msa = [SELECT ID, Name FROM Master_Service_Agreement_Version__c WHERE Id = : msaId];
   Master_Service_Agreement_Version__c msaCopy = msa.clone(false,true);
   msaCopy.Name = msa.Name +'-'+system.today();
   insert msaCopy;
   //cloning Related MSA Text Records
   for(MSA_Text_Block__c c : [SELECT Id, Name, Service__c,         Order_within_Service__c,Master_Service_Agreement_Version__r.ID FROM      MSA_Text_Block__c WHERE Master_Service_Agreement_Version__r.ID = : msa.Id]){
     MSA_Text_Block__c textCopy = c.clone(false,true);
     textCopy.Master_Service_Agreement_Version__r.ID = msaCopy.Id;
   insert MText; 

create a java script button to call the apex class


believe its a syntax issue in passing the parameter to the apex method

you need a semicolon between the parameter name and value.

its always better to declare and initialize your param value and use it wherever you need it.


var myParam = "{!Master_Service_Agreement_Version__c.Id}";
sforce.apex.execute("CloneVersionwithText","cloneMSAVersion", {msaId : myParam});
| improve this answer | |
  • this is not working error show is that : unexpected token and krinshna how to pass id in java script? – Ravi Vadher Aug 17 '15 at 7:00
  • there was an extra } in the code which i removed. updated the answer. – Vamsi Krishna Aug 17 '15 at 7:04
  • thank's krishna i solve this error but show new error id is not defined so how can i pass id in this script? – Ravi Vadher Aug 17 '15 at 7:06
  • krishna i need your small help – Ravi Vadher Aug 17 '15 at 7:12

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.