Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I created a custom object which when saved creates a calendar Event using an Apex trigger. Am able to populate all of the desired fields in the Event except the Related To field. I want the Related To Object to inherent the custom object name and the Related To field the customer object record name.


> trigger calup on Schedule_Onsite_Technician__c (after insert, after
> update) {   List<Event> NewFSEvent = new List<Event>();
>   for (Schedule_Onsite_Technician__c  eve : {
>     Event e = new Event();
>     e.StartDateTime = eve.Onsite_Arrival_date_Time__c;
>     e.EndDateTime = eve.Return_date__c;
>     e.Location = eve.Location_Address__c;
>     e.Description = eve.Equipment__c;
>     e.OwnerId = eve.Assigned_Tech__c;
>     //e.WhatId = eve.RecordID;
>     //e.What.Type = 'ScheduleOnsiteTechnician';
>     e.ShowAs = 'OutofOffice';
>     e.Subject = eve.Field_Service_Activities__c;
>     e.WhoId = eve.Contact__c;
>     NewFSEvent.add(e);   }
>   insert NewFSEvent; }
share|improve this question
eve.recordid should be You don't need to set what.type. – sfdcfox May 11 '14 at 2:39
up vote 2 down vote accepted

Set the WhatId on the event record to your custom object's ID. Here's an example:

trigger createEventForCustomObject on CustomObject__c (after insert) {
    Event[] events = new Event[0];
    for(CustomObject__c record: {
        events.add(new Event(WhatId=record.Id, Subject='Hello',;
    insert events;
share|improve this answer
Thanks. Should have included my code as I am still having a problem. – Steven J May 11 '14 at 0:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.