function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
chaitanya motupallichaitanya motupalli 

why child record is not generating when parent record is inserted as per below code? is there any mistake?

In the below trigger account(parent) and wow(child object) connected through a lookup already. Still, I can not create a record on wow object.

trigger AccPhone on Account (after insert) {
    for(account a: trigger.new){
        
            wow__c w= new wow__c();
            w.name='chaitusri';
            w.phone__c='545454';
            w.WowAccount__c= a.id;
        
    }

}
Best Answer chosen by chaitanya motupalli
GovindarajGovindaraj
Hi Chaitanya,

As this trigger is for event after insert so we need to use DML statement. Please try below code,
trigger AccPhone on Account (after insert) {
list<wow__c> lstWow = new list<wow__c>();
    for(account a: trigger.new){        
            wow__c w= new wow__c();
            w.name='chaitusri';
            w.phone__c='545454';
            w.WowAccount__c= a.id;
        lstWow.add(w);
    }
       insert lstWow;
}
Thanks,
Govindaraj.S

All Answers

GovindarajGovindaraj
Hi Chaitanya,

As this trigger is for event after insert so we need to use DML statement. Please try below code,
trigger AccPhone on Account (after insert) {
list<wow__c> lstWow = new list<wow__c>();
    for(account a: trigger.new){        
            wow__c w= new wow__c();
            w.name='chaitusri';
            w.phone__c='545454';
            w.WowAccount__c= a.id;
        lstWow.add(w);
    }
       insert lstWow;
}
Thanks,
Govindaraj.S
This was selected as the best answer
chaitanya motupallichaitanya motupalli
Perfect bro...I miss the logic earlier. thanks for your time. I appreciate it.