You need to sign in to do that
Don't have an account?
krishna casukhela 7
compare two fields in salesforce
Hello
I have a urgent requirement as follows.
There is historical data in account object , it has 2 million records.
Account object has two fields with same data type say shipcode and billcode and I need to compare values in these two fields.
I am thinking of batch apex but if the matching rows are say 1Lakh then I cannot store in a list variable.
somebody told me about formula field but I am not sure how to go about this.
The aim is to create a report by including the formula field, but I am assuming about 1Lakh matching can turn up,
Please advise , elaborate wherever possible
Thanks
Krishna
I have a urgent requirement as follows.
There is historical data in account object , it has 2 million records.
Account object has two fields with same data type say shipcode and billcode and I need to compare values in these two fields.
I am thinking of batch apex but if the matching rows are say 1Lakh then I cannot store in a list variable.
somebody told me about formula field but I am not sure how to go about this.
The aim is to create a report by including the formula field, but I am assuming about 1Lakh matching can turn up,
Please advise , elaborate wherever possible
Thanks
Krishna
https://developer.salesforce.com/forums/?id=906F00000008wuFIAQ
You can definitely use a formula field for this. The formula can compare the values in these two fields and give an output. However, can you elaborate more on what exactly do you want to compare and what should be the outcome so that we can help you build the formula ?
a) First , The idea is to build a report by including the formula field in the report.
so can u help me frame the formula field?
b) alternatively I could do something like this
use a loop , if the fields match capture them into a list variable , provided number of rows returned are less than 50000 to avoid hitting governor
limit, once in list variable then some other logic
c) pls clarify for me
assume I have 2 million historical records already
Now creating a new formula field won't help because then only new rows values can be added not the old ones
also if number of rows returned is greater than 50000 what should be the approach
Thanks
Krishna
You can update all records by executing code in anonymous window or batch and also for records above 50000 you can put the query in the For loop like below,
There is no limit on the number of items a collection can hold. However, there is a general limit on heap size.
You can get more than 50,000 using a Query Locator.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_database_batch.htm
This documentation says you can query up to 50 million records:https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_interface.htm
however, query locators have some risks where are well documented here:https://help.salesforce.com/apex/HTViewSolution?id=000004410&language=en_US
Regards