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
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.
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.
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
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:
I haven't tested it, but you get the idea.
Thanks.
I want to write above trigger dynamically
i want to compare fields from standard object with custom object fields in trigger how to do that?
Please state your requirements clearly.