You need to sign in to do that
Don't have an account?
viktorV
Activity - referenced opportunity's details
I'm creating a trigger in which I'd like to check some Opportunity details. I tried
for(Event e: trigger.new){ if(e.What.CloseDate == ...){ } }
but it gives Invalid field CloseDate for SObject Name error.
Is there a way to get these details? I don't want to use SOQL,
Thank you,
Viktor
Hi Victor,
sorry I missread your first post. This error you see is probably because the What-field is a polimorfic key, it can point to different kind of sObjects. You need to cast it to the correct type for it to work. You can check the type by looking at e.What.Type .
Hope that brings you closer to the solution.
Cheers!
Martin
All Answers
I assume that you have created trigger on Opportunity object.
You can add something like below in your trigger.
for (Opportunity op: trigger.new)
if(op.CloseDate == ...){
Hi Victor,
have you tried removing "What" from your if-statement?
if (e.CloseDate == ...)
Cheers!
Martin
Nope. I've created an Event trigger. It is possible to get details on sObjects of the referenced object.
For example, if I create an Opportunity, I have the ability to work with the given Accounts all details. (e.g. using opp.Account.BillingAddress)
The reference name on Activities for Related To field is 'What' but I don't know if its waiting more parameters (beacuse related to field can include not just account, than some other objects)
Try to use WhatId instead of what.
The foreign key relationship is What, WhatId only gives the referenced id. In spite of that, I tried WhatId and doesn't work.
Hi Victor,
sorry I missread your first post. This error you see is probably because the What-field is a polimorfic key, it can point to different kind of sObjects. You need to cast it to the correct type for it to work. You can check the type by looking at e.What.Type .
Hope that brings you closer to the solution.
Cheers!
Martin
Hi Martin, thank you for the answer!
Then how could I get the referenced Opportunity field value? Only with SOQL?
Thank you,
Viktor
Hi Viktor,
the documentation probably states it somewhere, but I usually just try it since I never can remember how much data is available int the trigger. If the references is all null values, try to query for them with SOQL.
Cheers!
Martin
Thanks Martin!