You need to sign in to do that
Don't have an account?
Shivkumar Shete
I Want to copy all fields from opportunity object to my custom object i.e opportunity_clone_cc i'm writing below code but getting error
trigger CloneOpp1 on Opportunity( after insert, after update ) { Set<String> field = Opportunity.getDescribe().fields.getMap().keySet(); Map<Id,Opportunity_clone__c> opp = new Map<Id,Opportunity_clone__c>(); for(Opportunity record: Trigger.new) { opp.put(record.Opportunity_clone__c,new Opportunity_clone__c(id=record.Opportunity_clone__c)); for(String field:fields) { if(field.indexOf('__c')>-1) { // This is a custom field. try { Opportunity_clone__c.get(record.Opportunity_clone__c).put(field,record.get(field)); } catch(exception e) { /* NOTE: This just means copy failed. */ } } } } update Opportunity_clone__c.values(); }
can you share the error what you are getting.
Thanks
Niraj
erorr is : Variable does not exist: opportunity_clone__c
thanks
I resolved that issue but getting error as Non static method cannot be referenced from a static context: Object opportunity_clone__c.get(String)
But this error context is not matching with your script posted above.
Any how this syntax is not proper:
"Opportunity_clone__c.get(record.Opportunity_clone__c)".
This "record.Opportunity_clone__c" will return field value where "get" methos expecting "field api name".
Set<String> fields = Opportunity.getSobjectType().getDescribe().fields.getMap().keySet();
Map<Id,opportunity_clone__c> co2 = new Map<Id,Opportunity_clone__c>();
for(Opportunity record: Trigger.new) {
co2.put(record.opportunity_clone__c,new opportunity_clone__c(id=record.opportunity_clone__c));
for(String field:fields) {
if(field.indexOf('__c')>-1) { // This is a custom field.
try {
co2.get(record.opportunity_clone__c).put(field,record.getSObject(field));
} catch(exception e) { }
}
}
}
System.debug('------------------>'+co2);
insert co2.values();
}
i havw written above code it's not giving error but it is inserting null