You need to sign in to do that
Don't have an account?
ryanschierholz
How to get field from Custom Object that's linked to an Event via the WhatId / Related To field
I have a list of Events, some of them are Related To a custom object (Closing__c). I have Apex and SOQL code to query the Events into a List. I would also like to get the data from a field (i.e. Summary__c) on the Closing that is related to the Event, so I can display that in a LWC. I can get basic info in SOQL using:
SELECT Id, Subject, WhoId, WhatId, What.Id, Who.Id, Who.Name, What.Name FROM EventBut I would like to access other fields on the Closing__c record. What's the best way to do that?
All Answers
You should be able to do something like this.
Regards
simply you can run following query and not only can get data of Summary__c field but also any field date is in parant object of event. or you can get all fields value like this => Closing__r.Field_1__c,Closing__r.Field_2__c,Closing__r.Field_3__c.
this is the way to get field value of parent object.
let me know if above info helpful to you and mark it as best answer.
Thank you
Greetings!
You can access the parent record using the dot(.) operator.
For example, If you want to access the account record of the specific contact.
SELECT Account.Name, Account.Website, FirstName, LastName FROM Contact WHERE LastName = 'XYZ'
Similarly, you can access WhatId Record from Event Object.
SELECT What.Name, What.Website FROM Event
If you find your Solution then mark this as the best answer.
Thank you!
Regards,
Suraj Tripathi
Thanks for these ideas, folks, but this is a different situation. I even tried the query and got an error:
yes, now i have understand your question completely and I'm sure below info will help you. Actually, you can't get data directly from related To because WhatId have a multiple objects. but you can get data from above info.
simply, I perfomed the same requirment on task object and in task object firstly I fetched all Insightsfirst_Document__c's record where Id Contains Into WhatId and stored into a set. and after that I did query of Insightsfirst_Document__c(my custom object) and get all fields of my custom object.
Note => Make sure you have a Field Level security on field which you want to get.
let me know if this info helpful to you and mark it as best answer. and if you are facing any issue than please mention here.
Thank you
I am wanting to return data about the Event along with the Closing to an LWC, so my plan is that I would create a new sObject type in the Apex controller, which would have a combination of Event info and Closing info, in a manner similar to what you proposed.