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
Jaffer Ali.Jaffer Ali. 

one million record processing in apex

Hey guys,

I got a critical case, as present below.

Problem:
In one of my objects there are five long text area fields. I want to perform search on those fields and update all records , once it is done. My expected result set contains 600 thousand records.

My Solution:
I created a btach class to perform this task, as Like statement is not allowed for long text area so I am scanning all records and then using "contains" function in apex to see if it is matched.Right now, it is taking 45 minutes to complete that job for 100 thousand records which is really too long.

Is there any other way I can make this process faster. Need suggestions.
Vinita_SFDCVinita_SFDC
Hi,

Instead of using CONTAINS try using "Equal to", this is because the CONTAINS operator requires a full scan of the index and takes more time. Please refer section "More Efficient SOQL Queries" in following help document in order to optimize your query: 

https://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_SOQL_VLSQ.htm
Jaffer Ali.Jaffer Ali.
In my case, I have to use contains function because i want to search a sub string from the complete string.
Vinita_SFDCVinita_SFDC
Hi,

If you can not avoid use of "Contains" filter then try optimizing the query by other means provided in the above document. Query has to be optimized to make it run fast.

Can you share you query for further suggestions?