8

Is "REGEX too Complicated" error while attempting to upload a CSV via Apex into SFDC an undocumented limit? What should be the optimal data volume for a CSV upload via Apex? I was trying with 10,000 rows of 8 columns each?

2
  • Where is your Regex? Is it in a trigger, workflow, the upload code? Can you post the regex that is causing the error?
    – Mike Chale
    Mar 28, 2013 at 18:54
  • Hi Mike, the error is while uploading the CSV file via Apex. It seems to me an undocumented Limit pertaining to the data volume in the CSV. Is any CSV data limit documented anywhere? What would be the optimal Data Volume in the CSV that could be successfully processed?
    – KaLi
    Mar 28, 2013 at 19:15

2 Answers 2

7

Looks like you found the solution, but for other folks, I've seen this error occur in three different ways.

  1. Calling String.replace() on very large strings (somewhere around 500k from memory, but it varied based on heap usage). This is extra confusing since String.replace() doesn't support regexes. The solution is to chunk up the string into smaller chunks and call replace on those.
  2. Calling String.replaceAll() or the Pattern/Matcher classes on very large strings. Similar solution to #1; in both cases, be careful that your chunk-and-replace algorithm doesn't skip replacements of target strings that span two chunks.
  3. Calling String.replaceAll() or the Pattern/Matcher classes using a regex that has too much branching logic. Simplest repro I've seen is to take a large multi-line file and run a match on the regex (\n|\r|.) (seems silly but this is a valid regex since Apex doesn't support DOTALL). In all these cases I've seen, I've had to refactor the regex to actually make it less complex, although "complex" is a misnomer in the example here.
4

I got the below posts which exactly addresses the problem ... it might be useful to others facing the issue....

http://boards.developerforce.com/t5/Apex-Code-Development/Pattern-and-Matcher-Question/m-p/135986

http://boards.developerforce.com/t5/Apex-Code-Development/Regex-too-complicated-error-for-large-volume-of-data-and-a/m-p/178769

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .