You need to sign in to do that
Don't have an account?
Ricardo Ortega
Apex trigger after insert
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 ?
All i got so far was
trigger calendar_event on Trip__c (after insert) {
Event evt = new Event();
}
Thank you
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