You need to sign in to do that
Don't have an account?
karthik Jonnalagadda
I need to copy a record from One object to another object on button click
Hi,
Anybody suggest me a simple process to copy a record from one custom object to another custom object on button click.
Anybody suggest me a simple process to copy a record from one custom object to another custom object on button click.
1. A custom button with JavaScript.
2. A custom button with a call to an Apex class using apex.sforce.execute(). The method in the class should be marked as a webservice.
3. A custom button and a visualforce page. Visual force page would just have an Action attribute on <apex: page> and a method returning PageReference to the page you want to redirect to and logic to copy/dml on new object. This method will be called from Action on <apex: page>.
3 is the best option from simplicity and peformance perspective.
1 and 2 are also simple but each call would be an API request since JavaScript will connect via API and 2 is a webservice callout :).
All Answers
There is no other way that Apex Code to copy records from one object to other object.
However to simplify or limit the code you can choose different approach i.e. instead of writing all 100+ fields in apex trigger, use Custom setting to store these fields and then use sObject get() and set() methods do the data copy stuff.
As custom setting is like an object you can create 2 custom fields on that and then create records 100+ in the custom setting to populate the field API Names.
For Example:
List type custom setting: Copy Values (Copy_Values__c)
Custom Fields:
Source Field Name (Source_Field_Name)
Dest Field Name (Dest_Field_Name)
Then you have to click on manage button and insert record to this custom setting. lets say you have fields as Source_A__c, Source_B__c etc and have to copy to Dest_A__c, Dest_B__c etc.
then you have to create records in custom setting.. one for each pair.
Once you done with this configuration then you have to write code in your trigger to create map of source field name to destination field name.
Please let me know if this helps
Best Regards
Naga Kiran
Cal me @7829250877.
1. A custom button with JavaScript.
2. A custom button with a call to an Apex class using apex.sforce.execute(). The method in the class should be marked as a webservice.
3. A custom button and a visualforce page. Visual force page would just have an Action attribute on <apex: page> and a method returning PageReference to the page you want to redirect to and logic to copy/dml on new object. This method will be called from Action on <apex: page>.
3 is the best option from simplicity and peformance perspective.
1 and 2 are also simple but each call would be an API request since JavaScript will connect via API and 2 is a webservice callout :).
If none of the answers helped you significantly, please post the solution. You may also mark your solution as the best answer.