You need to sign in to do that
Don't have an account?
Nirmal9114
Clone record with its related list by clicking on custom button
I am facing the error saying "A problem with the OnClick JavaScript for this button or link was encountered''
CLASS:
global class customClone
{
webservice static void cloneAccount(Id acctId) // you can pass parameters
{
List<Contact> cont = new List<Contact>();
Account acc = [SELECT ID, Name FROM Account WHERE Id = : acctId];
Account accCopy = acc.clone(false,true);
accCopy.Name = acc.Name +'-'+system.today();
insert accCopy;
//cloning Related contact Records
for(Contact c : [SELECT Id, LastName, AccountId FROM Contact WHERE AccountId = : acc.Id]){
Contact conCopy = c.clone(false,true);
conCopy.AccountId = accCopy.Id;
cont.add(conCopy);
}
insert cont;
}
}
MY JAVASCRIPT CODE for the custom button
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}
sforce.apex.execute("customClone","cloneAccount",{acctId:{!Account.Id}}"});
CLASS:
global class customClone
{
webservice static void cloneAccount(Id acctId) // you can pass parameters
{
List<Contact> cont = new List<Contact>();
Account acc = [SELECT ID, Name FROM Account WHERE Id = : acctId];
Account accCopy = acc.clone(false,true);
accCopy.Name = acc.Name +'-'+system.today();
insert accCopy;
//cloning Related contact Records
for(Contact c : [SELECT Id, LastName, AccountId FROM Contact WHERE AccountId = : acc.Id]){
Contact conCopy = c.clone(false,true);
conCopy.AccountId = accCopy.Id;
cont.add(conCopy);
}
insert cont;
}
}
MY JAVASCRIPT CODE for the custom button
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}
sforce.apex.execute("customClone","cloneAccount",{acctId:{!Account.Id}}"});
If you do not have Namespace in your Org try this
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}
sforce.apex.execute("customClone","cloneAccount",{acctId:"{!Account.Id}"});
If you have Namespace in your Org try this
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}
sforce.apex.execute("YourOrgNameSpace.customClone","cloneAccount",{acctId:"{!Account.Id}"});
I dont have namespace in my org. so i tried the above code.
Now the clone button is not working itself.
global class customClone
{
webservice static void cloneAccount(Id acctId) // you can pass parameters
{
List<Contact> cont = new List<Contact>();
Account acc = [SELECT ID, Name FROM Account WHERE Id = : acctId];
Account accCopy = acc.clone(false,true);
accCopy.Name = acc.Name +'-'+system.today();
insert accCopy;
//cloning Related contact Records
for(Contact c : [SELECT Id, LastName, AccountId FROM Contact WHERE AccountId = : acctId]){
Contact conCopy = c.clone(false,true);
conCopy.AccountId = accCopy.Id;
cont.add(conCopy);
}
System.debug(cont.size());
insert cont;
}
}
this is what u asked.
Iit displays this error.
{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}
I tried the same i posted and its working totally fine for me.
Did you try to paste the code i gave you?
Thanks,
but if the user want to change anything then they cannot. we have to go back and edit it
u got my point?
window.location.href="/"+newAccid+'/e';
window.location.href="/"+newAccid+'/e';
i meant the data its not fetching. why so? can you please tell
If i cancel then also the record is made and saved.
and another one that its redirecting to HOME page even on cancelling and saving
Were u able to fix the record creation upon cancel button too. And how about redirecting issue?
I have similar requirement to be implemented. Can you please let me know the fix.