function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Shivkumar SheteShivkumar Shete 

i want to clone opportunity object in custom object and then if i insert new opportunity in opportunity object it should get updated in custom object how to do this dynamically by using trigger

Neha AggrawalNeha Aggrawal
Hi Shiv,
I think there are some apps available on app exchange to clone any standard or custom object. Since it is a one time activity, you can easily do through any of the free apps.
As for creating same record in the new cloned object when a record is created in opportunity object, you can create an after insert trigger something along the lines:
List<Cloned_object__c> newclonedobj= new list<Cloned_object__c{};
Opportunity[] Opp = [SELECT Id,Name,Stage, CloseDate FROM Opportunity
                      WHERE OpportunityId IN :Trigger.new];
for(Opportunity o: Opp)
{
//Add all the fields that you want to update
Cloned_object__c temp= new Cloned_object__c(Name=o.Name, Stage=o.Stage, CloseDate=o.CloseDate);
newclonedobj.add(temp);
}
insert newclonedobj;

I haven't tested it, but you get the idea.
Thanks.
 
Shivkumar SheteShivkumar Shete
Hi neha,
I want to write above trigger dynamically
Neha AggrawalNeha Aggrawal
What do you mean by dynamic. Can you explain more ?
Shivkumar SheteShivkumar Shete
Hi Neha,

i want to compare fields from standard object with custom object fields in trigger how to do that?
Shivkumar SheteShivkumar Shete
i want to clone object dynamically in your code you are doing hardcode 
Neha AggrawalNeha Aggrawal
What do you mean by dynamic ? Do you want to give some kind of user input that this is the object in which opportunity record should get cloned.
Please state your requirements clearly.
Shivkumar SheteShivkumar Shete
i have two objects opportunity and opportunity_clone ,if i insert opportunity in standard object it should reflect in custom object, you have givencode above is working but i have to do through soql query to get fields i want to use sobject to do it dynamically
Shivkumar SheteShivkumar Shete
http://christopheralunlewis.blogspot.com/2011/05/how-to-dynamically-clone-salesforce.html please refer this link