You need to sign in to do that
Don't have an account?
Lee Sin
I am trying to build a report in apex and send an html email.
The report is basicly counting records number. But it has cross queries.
Can you look my code and comments and give me some advice?
Thank you!
Do I need to use batch apex in this scenario? How can I avoid gonernor limits in my code?
I am trying to build a report in apex and send an html email.
The report is basicly counting records number. But it has cross queries.
Can you look my code and comments and give me some advice?
Thank you!
You can refer below code:
If this solves your problem, kindly mark it as the best answer.
Thanks,
Vatsal
All Answers
You can refer below code:
If this solves your problem, kindly mark it as the best answer.
Thanks,
Vatsal
Part of your issue is that your querying in a for loop. Not only that, but you're querying 3 times in each instance. You'll want to look into how to "bulkify" your code. In otherwords, you'll want to handle scenarios where you have multiple accounts, not just one account.
Part of being on a multi-tennant architecture means Salesforce has to make all of it's applications work nicely with one another. One of the ways it does this is by enforcing Governor Limits. In particular, there is a governor limit on the number of SOQL queries you can make in a single transaction. This limit is 100 queries.
In your case, this means that if your Account query returns more than 33 rows, then you'll hit a governor limit.
You can fix your code by moving your queries outside of the for loop.
Below is an example of what you might modify lines 10-19 in your code above to look like:
No guarantees on whether or not it compiles though.
where is advisorList defined?
Replace the 21st line with below code: