• pratap singh 10
  • 0 Points
  • Member since 2017

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 3
I have Custom Object A and Custom Object B which is a child of A.
I also have Custom Object C and Custom Object D which is a child of C.
When records are created in Custom Object A and B, I need to copy values from A and B to C and D. I have a trigger to copy A to C but need help with adding code to copy B to D. Can anyone help? It would be greatly appreciated.
trigger createCFromA on Custom_Object_A (after insert, after update) {

	Id RecTypeId =  [Select Id from RecordType where name = 'recordtype' and sObjectType = 'Custom_Object_C' limit 1].Id;

    List <Custom_Object_C> cToInsert = new List <Custom_Object_C>();

    for (Custom_Object_A a : Trigger.new){        

        if (a.Status__c == 'New' ) {
        Custom_Object_C c = new Custom_Object_C (); 
                c.Field_1__c = a.Field_1__c;
				c.Field_2__c = a.Field_2__c;
				c.Field_3__c = a.Field_3__c;
				c.RecordTypeId = RecTypeId;


    try {
        insert bToInsert; 
        catch (system.Dmlexception e) {
        system.debug (e);

Hi, I am adding a new drop down field to Contacts object. The drop down is Defaulted to Yes. I need to have all the old records in contact to be updated to Yes value as well. do i write a trigger? if so how do I write it?