Aravind
Aravind

Reputation: 221

Getting accessible fields of a Salesforce object using REST API

I have a SOSL query where I search for an email address in both Contact and Lead SObject. I instruct the query to return some fields like FirstName, MobilePhone, etc., Now, if my SF org does not have the MobilePhone field visibility to true, the query returns "Invalid Column MobilePhone".

Is there a way where I can fetch the available fields for a given object using the Force.com REST API before firing my query?

My SOSL query is

FIND {[email protected]} IN EMAIL FIELDS RETURNING Contact(Phone, Id, Department, Email, isDeleted, Name, MailingCity, Title ), Lead(Id, City, Company, Country, Name, MobilePhone, Phone, State, Status, Street, Title)

Upvotes: 2

Views: 6852

Answers (1)

Matt Lacey
Matt Lacey

Reputation: 8255

You can find the information you need using the SObject Describe functionality or the REST API equivalent, the /services/data/v24.0/sobject/[SObject]/describe REST API Describe call. If a field such as MobilePhone is not in the child "fields" list returned by the REST describe call, then it is not accessible. So if you have a list of fields you would like to return, you should check to see if they are returned in the "fields" list, and not include them in your SOSL query if they are not there.

Upvotes: 5

Related Questions