[Apex] List all non-editable fields

When we want to customize a FieldHistory object, such as the Opportunity Field History, we would write a small program to check the modification status of all fields when the Opprotunity record is updated.


However, some fields are unnecessary, or even should not be checked.
For example, some system fields like CreateDate and IsDeleted.


In concept, if a field is not Updateable, there is no need to check it.
So how do we confirm if a field is Updateable or not?
Here is a ready-made method:

(Using Opportunity as an example):

Opportunity.sObjectType.getDescribe().fields.getMap().get(fieldName).getDescribe().isUpdateable()


The plain translation of the above line is roughly as follows: Retrieve the field map of the Opportunity object, and then extract the properties of the specified field from the field map. One of the properties that can be checked is isUpdateable. 

留言

這個網誌中的熱門文章

Salesforce證照考試心得 (Administrator and Advanced Administrator)

ISC2 CC (Certified in Cybersecurity Certification) 考試心得