You need to sign in to do that
Don't have an account?
Mohit Kashyap 14
when I clone an Opportunity all the related list should also be cloned
class:
public class CustomCloning
{
public String idOfRec {get;set;}
public CustomCloning()
{
}
public void cloneRec()
{
List<Business_Scenario_Qualification__c> cons = new List<Business_Scenario_Qualification__c>();
Opportunity acc = [SELECT ID, Name,StageName, CloseDate FROM Opportunity WHERE Id = : idOfRec];
Opportunity accCopy = acc.clone(false,true);
insert accCopy;
List<Business_Scenario_Qualification__c > quote = [SELECT Id, Name FROM Business_Scenario_Qualification__c WHERE Opportunity__c = : acc.Id];
for(Business_Scenario_Qualification__c c : quote)
{
Business_Scenario_Qualification__c conCopy = c.clone(false,true);
conCopy.Opportunity__c = accCopy.Id;
cons.add(conCopy);
}
insert cons;
}
}
Button on Opportunity:
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}
sforce.apex.execute("customCloning","cloneRec",{{!Opportunity.Id}:{!Opportunity.Id}}"});
It is giving me the error when I click on " Custom Cloning Button "
A problem with the onclick javascript for this button or link was encountered
Invalid or unexpected token
public class CustomCloning
{
public String idOfRec {get;set;}
public CustomCloning()
{
}
public void cloneRec()
{
List<Business_Scenario_Qualification__c> cons = new List<Business_Scenario_Qualification__c>();
Opportunity acc = [SELECT ID, Name,StageName, CloseDate FROM Opportunity WHERE Id = : idOfRec];
Opportunity accCopy = acc.clone(false,true);
insert accCopy;
List<Business_Scenario_Qualification__c > quote = [SELECT Id, Name FROM Business_Scenario_Qualification__c WHERE Opportunity__c = : acc.Id];
for(Business_Scenario_Qualification__c c : quote)
{
Business_Scenario_Qualification__c conCopy = c.clone(false,true);
conCopy.Opportunity__c = accCopy.Id;
cons.add(conCopy);
}
insert cons;
}
}
Button on Opportunity:
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}
sforce.apex.execute("customCloning","cloneRec",{{!Opportunity.Id}:{!Opportunity.Id}}"});
It is giving me the error when I click on " Custom Cloning Button "
A problem with the onclick javascript for this button or link was encountered
Invalid or unexpected token
you can take reference from this code, it will helps you :
Code:
If you find your Solution then mark this as the best answer.
Thank you!
Regards,
Suraj Tripathi
I ran your code but still the same error is coming up.