Apex Tip: check if field exists on SObject

This small function check if any SObject contains a field, really useful on many cases.

For instance if you want to know if country Picklist is active, you could check countryCode field active.

Other approach using JSON serializer

Sample use:

2 thoughts on “Apex Tip: check if field exists on SObject

  1. Newlog


    I am new to Salesforce and I appreciate your tip to check if field exists on SObject.

    Now, I could not figure out how to use this for the CURRENT object.

    To be clear, I have a trigger on the Note object calling a function in a dedicated class, and this function needs to know if a given field exists, then to retrieve its value.
    The point is that this is supposed to work an ANY object having Notes & Attachment as a related list.

    Any clues?

    Thanks in advance

  2. Sathmatahtatd Vishaysharaman

    This method is great however it doesn’t checks system fields. Do you have solution for this?


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">