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
firstqa systemfirstqa system 

how to save custom events in an custom object?

I have created a custom object FirstQA_Leads. I am creating a event that needs to store in the object. How to do so?
AnudeepAnudeep (Salesforce Developers) 
Here is a sample code
 
trigger CreateCustomEvent on Object_Custom__c (after insert) {

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

  for (Object_Custom__c  oc : Trigger.new) {
    
    Event e = new Event();
    e.StartDateTime = oc.Start__c;
    e.EndDateTime = oc.End__c;
    e.Subject = oc.Subject__c;
    e.WhoId = oc.User__c;	 
    lstNewEvents.add(e);
  
}
  insert lstNewEvents;

}

Here is another example from the documentation. It references a standard object. However, you can modify the code to use the custom object
 
public void createEventNew(Contact[] contacts) {
	String[] contactIds = new String[contacts.size()];
	for (int i = 0; i < contacts.size(); i++) {
		contactIds[i] = contacts[i].getID();
	}
	Event event = new Event();
	event.setSubject("New Event");
	event.setEventWhoIds(contactIds);
	SaveResult[] results = null;
	try {
		results = connection.create(new Event[] {
			task
		});
	} catch (ConnectionException ce) {
		ce.printStackTrace();
	}
}

If you find this information helpful, please mark this answer as Best. It may help others in the community

Thanks, 
Anudeep