Dynamically get Modified fields in trigger

Salesforce Asked by user52080 on July 24, 2020

We have a case with 100 fields if i updated 1 or 2 fields, to know that field iterating all 100 fields. How to get that field without iterating 100 fields.

Below Trigger was implemented

trigger fields on Case (before update) {

Map<string, Schema.SobjectField> caseFields = Schema.SObjectType.Case.fields.getMap();
case caseold = trigger.old[0];

if(caseold.get(fieldName) != null)
For (Case cs : {

    for (string fieldName : caseFields.keySet()) {

        if ( cs.get(fieldName) != Trigger.oldMap.get( {
            string oldvalue = string.valueOf(caseold.get(fieldName));

            string newvalue= string.valueOf(cs.get(fieldName));

            cs.IterateField__c = 'Changed '+fieldName +' From '+oldvalue +' to '+newvalue;
            system.debug('Changed field values:'+ cs.IterateField__c);


But, faced issue those trigger for iterating all fields. I want to iterating only Modified fields.anyone help me

One Answer

I dont think you can do it through trigger, an alternate solution is to use Change data capture feature of salesforce. with summer 2019 you can write trigger on CDC for any object.

It just gives you a json with just changed fields.

Receive near-real-time changes of Salesforce records, and synchronize corresponding records in an external data store. Change Data Capture publishes change events, which represent changes to Salesforce records. Changes include creation of a new record, updates to an existing record, deletion of a record, and undeletion of a record

It's a paid feature with configuration options for salesforce objects which can be propagated to middleware/external system

documentation here:

Answered by RedDevil on July 24, 2020

Add your own answers!

Related Questions

Using the Pardot API with Sandbox Accounts

1  Asked on December 21, 2021


Calculation not working

1  Asked on December 19, 2021 by gnatrae


How to Send Salesforce Document to External API using POST

2  Asked on December 17, 2021 by davis-handler


Task relationship to Opportunity in sub query

2  Asked on December 17, 2021 by cory-o-bennett


Validation rule on Picklist value on Global Action

1  Asked on December 17, 2021 by groundtocloud


Call JS method from IF loop in Visualforce

1  Asked on December 17, 2021 by shaleen-yadav


Ask a Question

Get help from others!

© 2022 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir