To fix the issue, change your code so that the number of SOQL fired is less than 100. If you need to change the context, you can use @future annotation which will run the code asynchronously.
Avoid SOQL queries that are inside FOR loops. Follow the key coding principals for Apex Code in our Developer's Guide. Review our best practices for Trigger and Bulk requests: Here are some best practices that will stop the error messages and/or help you avoid hitting the Governors Limit: 1. Since Apex runs on a multi-tenant platform, the Apex runtime engine strictly enforces limits to ensure code doesn’t monopolize shared resources. Learn about the Governors Limit. 2. Avoid SOQL queries that are inside FOR loops. 3. Check out the Salesforce Developer Blog where you can find Best Practices for Triggers. 4. Review best practices for Trigger and Bulk requests on our Force.com Apex Code Developer’s Guide. 5. Be sure you’re following the key coding principals for Apex Code in our Developer’s Guide. Important: Salesforce cannot disable the Governors Limit or raise it. Following the best practices above should ensure that you don’t hit this limit in the future.
For Example from this code
for (Bids__c bid : recentBids){
String recentProfileName = [SELECT Profile.Name FROM User Where Id = :bid.CreatedById LIMIT 1].Profile.Name;
String bidId = profilePrefixMap.get(recentProfileName);
bid.Bid_unique_label__c = ((bidId == null) ? defaultPrefix : bidId);
}
upsert recentBids;
Easiest example is this:
for(Account objAcc : [Select Id from Account])
{
system.debug(objAcc.Id);
}
*Mark this as a best answer if this resolve your concern*
If you need to change the context, you can use @future annotation which will run the code asynchronously.
Avoid SOQL queries that are inside FOR loops.
Follow the key coding principals for Apex Code in our Developer's Guide.
Review our best practices for Trigger and Bulk requests:
Here are some best practices that will stop the error messages and/or help you avoid hitting the Governors Limit:
1. Since Apex runs on a multi-tenant platform, the Apex runtime engine strictly enforces limits to ensure code doesn’t monopolize shared resources. Learn about the Governors Limit.
2. Avoid SOQL queries that are inside FOR loops.
3. Check out the Salesforce Developer Blog where you can find Best Practices for Triggers.
4. Review best practices for Trigger and Bulk requests on our Force.com Apex Code Developer’s Guide.
5. Be sure you’re following the key coding principals for Apex Code in our Developer’s Guide.
Important: Salesforce cannot disable the Governors Limit or raise it. Following the best practices above should ensure that you don’t hit this limit in the future.
For Example from this code
To