I am getting error at following line

 List<Group> groupMembers = [SELECT Id, RelatedId, Type FROM Group WHERE RelatedId IN: sRoleIds AND Type =: 'Role'];
  • 4
    It will be helpful if you can share from where this method/class is called. Sometimes the error is not in the class where the error is reported but the class which execute before this class as well as they exhaust the queries . – manjit5190 Dec 8 '16 at 6:52
  • 2
    go thru the debug log or use developer console and ascertain where in the transaction it appears you are executing the same SOQL in a loop (typical reason for this issue) – cropredy Dec 8 '16 at 7:00
  • 1
    certainly no "Too many SOQL" error in this piece of code. It's very likely that you have 99 SOQL queries earlier in this transaction(classes/methods that are run earlier and that call this method) and then it hits the second query in this code and that throws the error. – Novarg Dec 8 '16 at 7:03
  • You should optimize your code for function calls as well; – itzmukeshy7 Dec 8 '16 at 7:06
  • Go through this doc developer.salesforce.com/page/… and take care of governor limits before any DML call. – Amjad khan Dec 8 '16 at 7:12

There are only two (out of 100) SQOL queries in your code, so we can exclude a governor limits problem with it.

Most simple solution would be to look at the relative debug log (if your code runs only with partner users you can set up one of them to generate a debug log for you in setup > debug logs). Look at the end of the log and you should see a list of all governor limits, along with your usage. You should be able to notice that the 100 limit on SOQL queries has been reached.

Look in the log file to spot which other Apex classes/methods are running besides the one you posted, either one of them has a SOQL query in a loop (most likely) or you are recursively calling this - or another SOQL containing - class.

In both cases you have to refactor the offending class/method, there's no avoidance of a Too many SOQL error just by editing shareEndCustomersWithPartnerCommunity.

| improve this answer | |

You're building a collection and then inserting it - are there any triggers on the inserted object that may be firing SOQL calls?

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy