Trigger for creating record without relationship

By | January 10, 2020

Hi, here we have shown, how to create a record when a record is inserted in one object, another object record should create.

Here we are used People and contact objects, both dont have any relationship, but if people object record is created then contact object record should be created.

Trigger

trigger Createcontactrecord on People__c (after insert,before update) {
list<contact> conlist = new list<contact>();
   
    for(People__c p:trigger.new){
        if(p.IsLearner__c==true || p.IsTrainer__c==true){
        contact con = new contact();
        con.FirstName=p.First_Name__c;
        con.LastName=p.Last_Name__c;
        con.Email=p.Email__c;
        con.IsLearner__c=p.IsLearner__c;
        con.IsTrainer__c=p.IsTrainer__c;
       
        conlist.add(con);
        system.debug(conlist);
        }
    }
    insert conlist;
   
}
Share this...
Share on Facebook
Facebook
Email this to someone
email

Leave a Reply

Your email address will not be published. Required fields are marked *