Guest User

Untitled

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