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
Ricardo OrtegaRicardo Ortega 

Help with an apex trigger

I have a custom object called trip. This object has a name, its owner id, a date field and some other fields. I want to create a trigger that executes after (or before) the insertion of the new trip, to create a new event with the information some of the info of the newly created trip. I am new to apex code so I am asking for help. To select the information I want to extract from the newly created trip do I need to look it up using a list ?

 

Thank you

souvik9086souvik9086

Try this

 

trigger CreateEvent on trip__c(after insert){

List<Event> eventList = new List<Event>();

for(Trip__c tripObj : Trigger.new){

Event event = new Event();

event.FieldToInsert = tripObj.FieldToAssign;

event.FieldToInsert = tripObj.FieldToAssign;

event.FieldToInsert = tripObj.FieldToAssign;

eventList.add(event);

}

if(eventList.size()>0){

upsert eventList;

}

}

 

Note: Blue colored text, you write the field names you want to insret in event and you want to assign from trip.

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks