+ Start a Discussion
Shephali SwarnkarShephali Swarnkar 

How to check Accessibility of merge field

Hi All,
    
            'Schema.sObjectType.Contact.fields.Account.Name.isAccessible()'
 using above code trying to check the Accessibility of Merge field  "Account.Name" in Contact object but getting Error that Account is not a field in Contact.
"Compile Error: account is not a field of Contact ".
How to resolve this issue??

Thanks



         
Best Answer chosen by Shephali Swarnkar
Rahul SharmaRahul Sharma
Ah I misunderstood the question:

For checking access of Account, Try something like this:
Schema.sObjectType.Account.fields.Name.isAccessible()

You might be aware of the following syntax:
Schema.sObjectType.ObjectApiName.fields.FieldApiName.isAccessible()
 

All Answers

Rahul SharmaRahul Sharma
Try:
Schema.sObjectType.Contact.fields.AccountId.isAccessible()
Shephali SwarnkarShephali Swarnkar
Hi Rahul
          Thank You so much...Its working!!!

One more question on it. As you suggested to check the accessbility for parent object field we can do using ID field (eg. AccountId), is it like we dont need to check for other fields of parent object in child object???
Rahul SharmaRahul Sharma
You still would need to check access for individual parent fields.
Account Id will only check for the lookup field, Imagine if the FLS is turned off for other fields but not for AccountId.
 
Shephali SwarnkarShephali Swarnkar
This was my actual question that i am unable to check accessibility on merge field like Account.name in contact object. Now how to check it ??

Thanks
Rahul SharmaRahul Sharma
Ah I misunderstood the question:

For checking access of Account, Try something like this:
Schema.sObjectType.Account.fields.Name.isAccessible()

You might be aware of the following syntax:
Schema.sObjectType.ObjectApiName.fields.FieldApiName.isAccessible()
 
This was selected as the best answer
Rahul SharmaRahul Sharma
Ah I misunderstood the question:

For checking access of Account, Try something like this:
Schema.sObjectType.Account.fields.Name.isAccessible()

You might be aware of the following syntax:
Schema.sObjectType.ObjectApiName.fields.FieldApiName.isAccessible()
Shephali SwarnkarShephali Swarnkar
Hey Thanks,
                   I think we dont need to check the fields accessibility on child object rather check on parent itself. please correct me if wrong.

 
Rahul SharmaRahul Sharma
Depends on your requirement or design.