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
Adam SamuelAdam Samuel 

Error message when uploading data

I tried to do a bulk upload of new contacts to our database but this message has come up:

CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY:npsp.TDTM_Contact: execution of AfterInsert\ncaused by: System.DmlException: Update failed. First exception on row 0 with id 0030o0000365ieHAAQ; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CTCT21.Contact_Trigger: execution of BeforeUpdate\ncaused by: System.LimitException: Apex CPU time limit exceeded\n(CTCT21): []\n(npsp)\n:--

Has anyone else experienced it?
Khan AnasKhan Anas (Salesforce Developers) 
Hi Adam,

Greetings to you!

This error usually arises from Apex triggers or processes running in the background which cause the maximum CPU time to exceed for a transaction. You can check the Debug logs/Event Monitoring.

The easiest way to overcome it would be to temporarily disable Apex triggers but it might produce some unwanted side-effects.

Another option (No need to deactivate the trigger) to try out is to set the "Batch Size" on the Apex Data Loader to a very small value say 10 or so.

Please refer to the below links which might help you further with the above requirement.

https://help.salesforce.com/articleView?id=configuring_the_data_loader.htm&type=5 (https://help.salesforce.com/articleView?id=configuring_the_data_loader.htm&type=5)

https://help.salesforce.com/articleView?id=000232681&language=en_US&type=1 (https://help.salesforce.com/articleView?id=000232681&language=en_US&type=1)

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Ajay K DubediAjay K Dubedi
Hi Adam,

There is no specific setting that will increase CPU time for bulk api.

What is happening is that when you schedule data load through bulk it put system under stress and it is not able to finish the given task in appropriate time and so throws error Apex CPU time limit exceeded.

To avoid CPU limit you need to optimize your code. Here are few tips:

Check the trigger execution and note the required time.
With the help of the developer console, you can figure out where CPU time is spent and then target the area which most CPU costly.
try and optimize those costly code blocks
Note for optimization of the trigger you can use anomalous block to fire trigger
Helpful link:

Salesforce Developers Blog: https://developer.salesforce.com/blogs/engineering/2014/09/apex-performance-troubleshooting.html



I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com