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 : Trigger.new) {
for (string fieldName : caseFields.keySet()) {
if ( cs.get(fieldName) != Trigger.oldMap.get(cs.id).get(fieldName)) {
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
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
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP