Monday 13 June 2022

System.LimitException: Regex too complicated

I came across this issue recently in production & The root cause is the length of the string which used in the regex.

Our use case it should verify combination of 2 words in received string & It started failing if the received string length is >369 characters

Ex: Card , Delivery keywords should be verified in the received string and it could be of any order. 

Actual Issue : Its hitting the heap size error 6 MB for synchronous 

Solution :

1. Move the logic to asynchronous as heap size will be 12 MB.

But in our case its not possible to move the asynchronous, Because its should be real time on every record insert this need to be tested and batch job cant be run that many time and future method also has 24 hrs limitation 250000 and on every record entry if that future method called that also hits another governor limit.

2.Split the message and verify the keywords in the smaller chunk message, This approach has been taken and working fine. 



No comments:

Post a Comment