Trigger to create child object after checking some condition in parent record

Sample Trigger:

trigger ageInterest on Member__c (after insert, after update)
{
    for(Member__c mem:trigger.New)
    {
        if(mem.Age__c == 18)
        {
            Interest__c it = new Interest__c(Name = 'Ghost Movies',Member__c = mem.ID);
            insert it;
        }
    }
}


Here Member__c is Parent object and Interest__c is child object.

No comments:

Post a Comment