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
SelvaSelva 

Can we capture the fields which are modified before save?

Hi,

Is it possible to determine what fields were modified by a user when saving an object in Salesforce.  For example, a user accesses the Account object and updates the Description and Customer Group values.  When they click Save, can that action be captured and those 2 fields identified as modified for further processing in an easy fashion?

regards
 
mtbclimbermtbclimber
Yes. This is a down-the-middle use case for Apex triggers.
SelvaSelva

Hi Andrew,

Thanks for your response. Could you please share us more about this down-the-middle use case,as you are saying it is possible.

It would be very useful, if you could guide me on this , as this is the first time am going to do this.

Regards

 

mtbclimbermtbclimber
The down-the-middle use case I refer to here is inspecting the old and new values of particular fields on an object during a save operation and taking whatever action is deemed necessary and possible once the condition is satisfied.

The article I referred to in my last response introduces Apex and discusses triggers at a basic level. If this is indeed your first exposure to Apex then you will probably be best off checking out the developer guide and working through the workbook tutorials on Apex and if you get really thirsty for knowledge there is a new book titled "Force.com Developer Guide: An Introduction to the Force.com Platform" in the developer library that will help.
SelvaSelva

Thanks again.

I've used to writer Apex trigger which is very critical thing and sensitive code. There is Governor limits which say how many times the SOQL query can run , after that it would throw Too many SOQL queries error. :-(

If you or anyone could lead me to some sample apex code which capture the fields which are mdofied while saving the object then that would be great. Wish to get into that code directly, as i have deadline. :-( I've sforce guide apex api guide documents and see if they specified any coding for down the middle use case. It would be helpful,if someone already done this kind of piece of code.

very much obliged.

werewolfwerewolf
Look in the Force.com Cookbook (listed on that link that mtbclimber sent) for examples of the use of oldMap.  It's a pretty sure bet that anyone using oldMap is comparing the old fields to the new.

If you're hitting SOQL query limits, chances are you're doing SOQL queries inside for loops.  Don't do that.