You need to sign in to do that
Don't have an account?
Biswajit Nath 9
Compare new and old values in apex without using double for loop
Hi All,
I am trying to optimize a code.
The code uses nested For loop to compare values from new trigger and old trigger. As a result, some time it hits the Apex CPU Time Limit error for a large volume of data.
I would like to ask if there is any better and efficient way to handle this situation.
Many thanks in advance!
I am trying to optimize a code.
The code uses nested For loop to compare values from new trigger and old trigger. As a result, some time it hits the Apex CPU Time Limit error for a large volume of data.
I would like to ask if there is any better and efficient way to handle this situation.
Many thanks in advance!
you can easily optimize your code by using map, store your old values into map and iterate over new trigger value
and then fetch value from map, please preffer below code
If you find your Solution then mark this as the best answer.
Thank you!
Regards,
Suraj Tripathi
if you are working on trigger then simply you can get reference from below code for getting data.
use trigger.oldMap.get(acc.Id) and get old field value.
trigger.new => it 's return new data
try above code and if it helps you ,don't forget to mark it as best answer.
Thank you
did you try my solution. try it once and don't forget to mark it as best answer if it help you so that it can help to others in future.
Your one best mark give us motivation to working in this direction.
Thank you