Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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.

Thanks!

> trigger calup on Schedule_Onsite_Technician__c (after insert, after
> update) {   List<Event> NewFSEvent = new List<Event>();
> 
>   for (Schedule_Onsite_Technician__c  eve : Trigger.new) {
>     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 eve.id. You don't need to set what.type. –  sfdcfox May 11 at 2:39

1 Answer 1

up vote 1 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: Trigger.new) {
        events.add(new Event(WhatId=record.Id, Subject='Hello', ActivityDateTime=DateTime.now()));
    }
    insert events;
}
share|improve this answer
    
Thanks. Should have included my code as I am still having a problem. –  Steven J May 11 at 0:37

Your Answer

 
discard

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.