Guest User

Untitled

a guest
May 24th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. trigger CloneOpp on Opportunity( after insert, after update ) {
  2. Set<String> fields = Opportunity.getSobjectType().getDescribe().fields.getMap().keySet();
  3. Map<Id,opportunity_clone__c> co2 = new Map<Id,Opportunity_clone__c>();
  4. for(Opportunity record: Trigger.new) {
  5. co2.put(record.opportunity_clone__c,new opportunity_clone__c(id=record.opportunity_clone__c));
  6. for(String field:fields) {
  7. if(field.indexOf('__c')>-1) { // This is a custom field.
  8. try {
  9. Opportunity_clone__c.getSobject(record.opportunity_clone__c).put(field,record.get(field));
  10. } catch(exception e) { /* NOTE: This just means copy failed. */ }
  11. }
  12. }
  13. }
  14. update co2.values();
  15. }
Add Comment
Please, Sign In to add comment