1

Facing 'System.EmailTemplateRenderException: Too many SOQL queries: 101' exception while using visual-force email template with custom controllers.

Api - Messaging.SingleEmailMessage templateInstance = Messaging.renderStoredEmailTemplate(email template Id, user Id, record Id);

Not able to figure out how SOQL is reached. Any idea on same? Following is Debug log information :

  13:28:43.439 (1439878776)|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 11 out of 100
  Number of query rows: 788 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 0 out of 113000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10
  • 1
    Could you post your controllers code? – Martin Lezer Feb 16 '17 at 8:24
  • No, I cannot do that :( – Needhi S Feb 16 '17 at 8:41
  • According to my assumption, you're retrieving data inside a for loop using SOQL and then binding that data with email template followed by sending email. You should place SOQL query outside of for loop to avoid that error – Rohit Mourya Feb 16 '17 at 8:49
  • 1
    Go through Exception :Too many SOQL queries: 101 and understand what causes issue since you cannot post the code – Reshma Feb 16 '17 at 8:58
  • 1
    @NeedhiS It's difficult to answer your question without looking at code – Rohit Mourya Feb 16 '17 at 9:09

Your Answer

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

Browse other questions tagged or ask your own question.