You need to sign in to do that
Don't have an account?

determine if Event whatid is an account
I have a custom button on the Event Page Layout designed to summarize the account/contact/event information from an event.
However, we require that an account be associated to the event in order to use the button.
The What field can be a number of different object types.
How can I programmatically ensure that the what is in fact an account and not something else?
Using javascript, I attempted to use the accountid:
var eventAccount = '{!Event.accountId }';
but there is no actual accountid field on Events.
"Field Event.accountId does not exist. Check spelling."
Is there a way to access accountid via javascript?
Thanks for the help!
You could also do:
SObject WhatIdObj = event.What.Id;
if(whatIdObj.getsObjectType() == Account.sObjectType){
}
All Answers
You'll notice in the URL for accounts that they all have an Id that starts with 001, https://ssl.salesforce.com/00100000003Kvh5.
Now that's just sneaky. Thanks!
You could also do:
SObject WhatIdObj = event.What.Id;
if(whatIdObj.getsObjectType() == Account.sObjectType){
}
Hey Anand@SAAS,
I am attempting something similar. I need to determine the object type for WhatId on some tasks. I've tried your example above and am getting the error "Illegal assignment from Id to SObject". Any help would be appreciated.
My Code is
You might want to try