Thursday, May 2, 2019

How to check field exists or not on sobject using Apex?

Some scenarios, we need to validate field is exists or not on the object.
use below simple code it checks the field on an object if the field has existed on the object it returns true otherwise it returns false.

Example:

Boolean bHasField = Account.getSobjectType().getDescribe().fields.getMap().keySet().contains('phone');
System.debug('bHasField =====> '+bHasField);

Result:

No comments:

Post a Comment