Tuesday, January 31, 2017

Find WhoId and WhatId object name in Apex and Visualforce


We frequently use WhatId and WhoId attributes of Event and Task object.

According to Salesforce documentation those are:

The WhatId represents nonhuman objects such as accounts, opportunities, campaigns, cases, or custom objects. WhatIds are polymorphic. Polymorphic means a WhatId is equivalent to the ID of a related object. The label is Related To ID.


The WhoId represents a human such as a lead or a contact. WhoIds are polymorphic. Polymorphic means a WhoId is equivalent to a contact’s ID or a lead’s ID. The label is Name ID.
If Shared Activities is enabled, the value of this field is the ID of the related lead or primary contact. If you add, update, or remove the WhoId field, you might encounter problems with triggers, workflows, and data validation rules that are associated with the record. The label is Name ID.
Sometimes, we need to find out actual object reference instead of generic WhatId or WhoId


To display the Actual Object Name instead of WhatId use this

WhatId Object is: <apex:outputLabel>{!Event.What.Type}</apex:outputLabel>

It will display like this:
What Id Object

Similarly, to find the Object name of WhoId use this:

WhoId Object is: <apex:outputLabel>{!Event.Who.Type}</apex:outputLabel>

Who Id



Similarly, to find the name of Object from Id in Apex use this code:
Pass WhatId or WhoId which you are retrieving from this SOQL query into that method.

Event eventRec = [SELECT WhatId, WhoId FROM Event Where Id = '00U9000001NgqWF'];

public static String getSobjectNameById(Id inputId)
    {
        Schema.SObjectType sobjectType = inputId.getSObjectType();
        return sobjectType.getDescribe().getName();
    }

18 comments:

  1. Excellent post!!! The future of cloud computing is on positive side. With most of the companies integrate Salesforce CRM to power their business; there is massive demand for Salesforce developers and administrators across the world.Salesforce Training in Chennai | Salesforce Training Institutes in Chennai

    ReplyDelete
  2. Nice article Thanks for sharing this article Wonderful information from this website Thanks !!!

    Embedded training in chennai | Embedded training centre in chennai | PLC Training institute in chennai

    ReplyDelete
  3. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.

    Hadoop training in bangalore

    ReplyDelete
  4. I feel really happy to have seen your webpage and look forward to so many more entertaining times reading here. Thanks once more for all the details.
    angularjs training in chennai
    Click here:
    angularjs2 training in chennai
    Click here:
    angularjs4 Training in Chennai
    Click here:
    angularjs5 Training in Chennai

    ReplyDelete
  5. Awesome..You have clearly explained …Its very useful for me to know about new things..Keep on blogging..
    Click here:
    Microsoft azure training in chennai
    Click here:
    Microsoft azure training in online
    Click here:
    Microsoft azure training in tambaram
    Click here:
    Microsoft azure training in chennai

    ReplyDelete
  6. This is a nice article here with some useful tips for those who are not used-to comment that frequently. Thanks for this helpful information I agree with all points you have given to us. I will follow all of them.
    Blueprism training in Chennai

    Blueprism training in Bangalore

    Blueprism training in Pune

    Blueprism online training

    Blueprism training in tambaram

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. This is a nice article here with some useful tips for those who are not used-to comment that frequently. Thanks for this helpful information I agree with all points you have given to us. I will follow all of them.
    Java Training From India

    Workday Training From India

    Mule Esb Training From India

    ReplyDelete
  9. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.

    best rpa training in chennai |
    rpa training in chennai |
    rpa training in bangalore
    rpa training in pune | rpa online training

    ReplyDelete
  10. I have read a few of the articles on your website now, and I really like your style of blogging. I added it to my favourites blog site list and will be checking back soon.

    Data Science training in rajaji nagar | Data Science with Python training in chenni
    Data Science training in electronic city | Data Science training in USA
    Data science training in pune | Data science training in kalyan nagar

    ReplyDelete
  11. This comment has been removed by the author.

    ReplyDelete
  12. I’m planning to start my blog soon, but I’m a little lost on everything. Would you suggest starting with a free platform like Word Press or go for a paid option? There are so many choices out there that I’m completely confused. Any suggestions? Thanks a lot.
    Best AWS Training in Marathahalli | AWS Training in Marathahalli
    Amazon Web Services Training in Anna Nagar, Chennai |Best AWS Training in Anna Nagar, Chennai
    AWS Training in Velachery | Best AWS Course in Velachery,Chennai
    Best AWS Training in Chennai | AWS Training Institutes |Chennai,Velachery

    ReplyDelete
  13. My rather long internet look up has at the end of the day been compensated with pleasant insight to talk about with my family and friends.
    safety course in chennai

    ReplyDelete
  14. Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.

    angularjs-Training in tambaram

    angularjs-Training in sholinganallur

    angularjs-Training in velachery

    angularjs Training in bangalore

    angularjs Training in bangalore

    ReplyDelete
  15. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.

    advanced excel training in bangalore

    ReplyDelete
  16. Thanks you for sharing the article. The data that you provided in the blog is infromative and effectve. Through you blog I gained so much knowledge. Also check my collection at Salesforce Online Training Blog

    ReplyDelete