function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
HelloSanHelloSan 

i want to check whether the field is update or not in the apex trigger on opportunity obejct how can this be done using apex coding

Abhishek BansalAbhishek Bansal
Hi,

You can do this with the help of below code:

trigger checkUpdate on Opportunity(after insert, afetr update) {
    for(Opportunity opp : trigger.new){
        //Get Old Values
        Opportunity oldOpp = trigger.oldMap.get(opp.id);
        
        //Check if value is updated
        if(oldOpp.FieldYouWantToCheck__c != opp.FieldYouWantToCheck__c) {
            //Do anything which you want to do if field is updated
        }
    }
}

Thanks,
Abhishek.
Krishnan MishraKrishnan Mishra
If you want to check whether the field is UPDATABLE or not use the schema class.
Following is the code:
Schema.DescribeSObjectResult[] descResult = Schema.describeSObjects(new String[]{'Opportunity'});
Map <String,Schema.SObjectField> m = descResult[0].fields.getmap();
for(String fieldName : m.keySet()) {
       if(m.get(fieldName).getDescribe().isUpdateable()) {
           System.debug('Yes ' + fieldName);
       }
       else{
           System.debug('No ' + fieldName);
       }
   }