You need to sign in to do that
Don't have an account?
sfadm sfadm
System.LimitException: Apex CPU time limit exceeded issue
Hello,
I have setup a new SalesForce environment and I have to transfer my Apex classes on it.
In order to deploy my code I use a test class with test methods.
A validation process is started when I try to deploy the changes.
This validation invokes all existing test methods and the environment throws the following exception:
System.LimitException: Apex CPU time limit exceeded
Oddly enough on the old environment there is no such exceptions
I'm sending you a method of my source code where the Apex CPU time limit exceeded is most likely to happen:
Please advise how to solve the issue with my deploy and avoid such System.LimitException: Apex CPU time limit exceeded exception?
I have setup a new SalesForce environment and I have to transfer my Apex classes on it.
In order to deploy my code I use a test class with test methods.
A validation process is started when I try to deploy the changes.
This validation invokes all existing test methods and the environment throws the following exception:
System.LimitException: Apex CPU time limit exceeded
Oddly enough on the old environment there is no such exceptions
I'm sending you a method of my source code where the Apex CPU time limit exceeded is most likely to happen:
private List<LeadConversionContainer> checkByWebsite(Lead leadObj) { List<LeadConversionContainer> accountWebsites = new List<LeadConversionContainer>(); String website = leadObj.Website; String leadId = leadObj.Id; List<Account> accWebsiteList = [SELECT Website, Url__c, Status__c FROM Account]; if(website != null && !website.equals('') && accWebsiteList != null) { List<String> leadWebsites = extractWebsites(website); for (String leadUrl : leadWebsites) { String normWebsite = normalizeWebsite(leadUrl); String leadWebsite = normWebsite.trim(); for(Account acc : accWebsiteList) { String accountWebsite = acc.Url__c; String accountId = acc.Id; List<String> extractedAccountWebsite = extractWebsites(accountWebsite); for(String accWebsite :extractedAccountWebsite) { String accountSite = normalizeWebsite(accWebsite); if(accountSite != null) { List<String> leadSplitWebsitesList = leadWebsite.split('[,;\\s]'); for(String leadSplitUrls :leadSplitWebsitesList) { if(accountSite.equals(leadSplitUrls)) { boolean isAccountStatusActive = isAccountActive(acc); boolean isMerchantApplication = isMerchantApplicationsAttached(acc); if(isAccountStatusActive || isMerchantApplication) { String reasonToStopConversion = 'Lead Website coincide with Account Website'; LeadConversionContainer leadConvert = new LeadConversionContainer(acc.Id, '', reasonToStopConversion); accountWebsites.add(leadConvert); } } } } } } } } return accountWebsites; }
Please advise how to solve the issue with my deploy and avoid such System.LimitException: Apex CPU time limit exceeded exception?
All Answers
Here is an article from Salesforce on how you can address this Apex CPU timelimit exceeded error with best practices : https://help.salesforce.com/apex/HTViewSolution?id=000232681&language=en_US (http://help.salesforce.com/apex/HTViewSolution?id=000232681&language=en_US)
Pls. mark as best answer if it answers your question.
Thanks,
Harshit Garg
Could you please suggest an example code on what I need to modify in my code because although the reason of this limit exception is due to the nested for loop I do not see how to modify my code to avoid such exception.