+ Start a Discussion
sunny.sfdcsunny.sfdc 

WhoId (Name) and WhatId (Related To) fields not getting populated through apex in Event object

Hi

I am working on a functionality where I need to copy my custom Meeting object's record to standard event object. In my custom Meeting object WhoId is a Contact lookup with a filter that only those records whcih belongs to WhatId (Account) should appear as choice. While saving custom object record I create an Event object record and assign values to standard Event object's record.

All values are getting copied but 'Type', 'WhatId' and 'WhoId'. I have tried putting hard coded values as well but of no use. It simply creates a standard Event object's record without these values.

I tried executing the same code as anonymous from force.com ide and it worked fine and populated all values correctly. I am not sure whats happening in there.

Please let me know if anybody has any solution to this.

Regards
Sachin
GlynAGlynA
Sachin,

A couple questions - Does your org have Shared Activities enabled?  Are you also setting the AccountId field on the Event?

Can you share the relevant part of the code?

-Glyn
sunny.sfdcsunny.sfdc
Hi Glyn

AccountId field is not a writable field for Event. Shared acitivities are not enabled on my org. 

Sachin
sunny.sfdcsunny.sfdc
Hi Glyn

Sorry for responding late. I found the mistake I was doing. Actually I thought the 'who' and 'what' are just like normal lookups to store Ids. But its not the case.

Here is what I was doing:
On update of my custom meeting object:
Step 1: Updating standard Event object.
Step 2: Clean the EventRelation object if any related records already exists based on EventId.
Step 3: Insert new EventRelation records for the Event.

And here is the mistake in Step 2. The 'Who' and 'What' fields are mapped to EventRelation record and when I cleaned all the existing records in EventRelation, this relation is gone. And thats why the fields were appearing blank.

Solution: In query where I was fetching existing EventRelations I put a where clause as 'IsInvitee = true'. It gives me all records except the Who and What relations.

Hope I am able to describe properly and thankyou for your time and suggestions.

Regards
Sachin