You need to sign in to do that
Don't have an account?

Is it possible to create multiple events in trigger?
In our scenario,i need to create set of random events for contacts ,we tried with trigger ,
that create only one event for an instance.
how do we create bulk events?
Anybody have solution or valuable suggestion for this query would greatly appreciated !
Thanks in advance!
Santhanam,
This is easy to do. An example of this is below.
trigger addMultipleEvents on Contact (after insert)
{
// Create a list to store the new events.
List<Event> newEvents = new List<Event> ();
// loop through new Contact records being inserted
for (Contact currentContact : Trigger.new)
{
// Create a loop to generate your Events
for (Integer i = 0; i < 10; i ++)
{
// Instanciate a new Event
Event newEvent = new Event(Subject = 'New Event '+i, ActivityStartDateTime = System.Now().addDays(i), WhoId=currentContact.Id);
// and add it to the list to be inserted.
newEvents.add(newEvent);
}
}
// After looping through all the Contacts in the trigger, if any new Events were created by the code, insert them into SalesForce.
if (newEvents.size() > 0)
insert newEvents;
}
All Answers
Santhanam,
This is easy to do. An example of this is below.
trigger addMultipleEvents on Contact (after insert)
{
// Create a list to store the new events.
List<Event> newEvents = new List<Event> ();
// loop through new Contact records being inserted
for (Contact currentContact : Trigger.new)
{
// Create a loop to generate your Events
for (Integer i = 0; i < 10; i ++)
{
// Instanciate a new Event
Event newEvent = new Event(Subject = 'New Event '+i, ActivityStartDateTime = System.Now().addDays(i), WhoId=currentContact.Id);
// and add it to the list to be inserted.
newEvents.add(newEvent);
}
}
// After looping through all the Contacts in the trigger, if any new Events were created by the code, insert them into SalesForce.
if (newEvents.size() > 0)
insert newEvents;
}
Thank you very much m_roark