We have a rather elaborate setup where we have partner portal users approve/reject account-records using a visualforce page. We've got a test case doing this whole flow and it succeeds when you run the tests in the SF web interface.

Running the tests in eclipse fails with an error message: INSUFFICIENT_ACCESS_OR_READONLY, user does not have access to use approval assignment email template.

This is apparently because as part of the approval rejection we send the account owner an email with a visualforce template showing the approval history, the partner portal users don't have access to this template. But as I've said before, this is only an issue in Eclipse. The approval of an account sends a simpler text-only email template and that works without issues.

If anyone can give me a fix/explanation for this I'll be very impressed+happy.

Clarification: Running the tests under "Apex Classes > TheClass > Run Test" OR "Apex Test Execution" leads to test success. This is a snippet of the log from the critical section doing it this way:

09:38:43.537 (5537523000)|DML_BEGIN|[403]|Op:Process|Type:ProcessRequest|Rows:1 09:38:43.554 (5554630000)|CODE_UNIT_STARTED|[EXTERNAL]|Workflow:ApprovalProcessActions 09:38:43.563 (5563888000)|WF_APPROVAL|Reject|[Account: TestAccount 001R000000kezhK]|Final Approval(Approval based on first response) 09:38:43.563 (5563921000)|WF_SPOOL_ACTION_BEGIN|Reject 09:38:43.565 (5565867000)|WF_HARD_REJECT 09:38:43.565 (5565898000)|WF_SPOOL_ACTION_BEGIN|Reject 09:38:43.575 (5575457000)|WF_FIELD_UPDATE|[Account: TestAccount 001R000000kezhK]|Field:Account: Approval Step|Value:null|Id=04Y20000000H2VF 09:38:43.578 (5578537000)|WF_FIELD_UPDATE|[Account: TestAccount 001R000000kezhK]|Field:Account: Approval Status|Value:Rejected|Id=04Y200000000cEF 09:38:43.578 (5578562000)|WF_RULE_INVOCATION|[Account: TestAccount 001R000000kezhK] 09:38:43.578 (5578571000)|WF_EMAIL_ALERT|Id=01W200000000S4i 09:38:43.642 (5642762000)|WF_EMAIL_SENT|Template:00X20000001D9X4|Recipients:[email protected] |CcEmails: 09:38:43.644 (5644438000)|CODE_UNIT_STARTED|[EXTERNAL]|01q200000005Pg7|AccountTriggers on Account trigger event BeforeUpdate for [001R000000kezhK]

This is the same critical section when the test is run in Eclipse:

09:35:04.051 (7051335000)|DML_BEGIN|[403]|Op:Process|Type:ProcessRequest|Rows:1 09:35:04.095 (7095087000)|CODE_UNIT_STARTED|[EXTERNAL]|Workflow:ApprovalProcessActions 09:35:04.111 (7111585000)|WF_APPROVAL|Reject|[Account: TestAccount 001R000000kezgb]|Final Approval(Approval based on first response) 09:35:04.111 (7111624000)|WF_SPOOL_ACTION_BEGIN|Reject 09:35:04.114 (7114612000)|WF_HARD_REJECT 09:35:04.122 (7122293000)|WF_SPOOL_ACTION_BEGIN|Reject 09:35:04.129 (7129414000)|WF_FIELD_UPDATE|[Account: TestAccount 001R000000kezgb]|Field:Account: Approval Step|Value:null|Id=04Y20000000H2VF 09:35:04.131 (7131898000)|WF_FIELD_UPDATE|[Account: TestAccount 001R000000kezgb]|Field:Account: Approval Status|Value:Rejected|Id=04Y200000000cEF 09:35:04.131 (7131932000)|WF_RULE_INVOCATION|[Account: TestAccount 001R000000kezgb] 09:35:04.131 (7131941000)|WF_EMAIL_ALERT|Id=01W200000000S4i 09:35:04.270 (7270385000)|CODE_UNIT_FINISHED|Workflow:ApprovalProcessActions 09:35:04.270 (7270471000)|DML_END|[403] 09:35:04.270 (7270575000)|EXCEPTION_THROWN|[403]|System.DmlException: Process failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_OR_READONLY, user does not have access to use approval assignment email template: []

  • Have you compared the test logs when running the test case from Eclipse versus the web? Can you post some of the code around the line that throws the INSUFFICIENT_ACCESS_OR_READONLY error?
    – tomlogic
    Oct 10, 2012 at 17:05
  • When you say web interface do you mean the class listing page and clicking Run All Tests or from the Apex Test Execution page? Not that this would necessarily be the cause, but the Apex Test Execution runs tests in parallel whereas the class listing page doesn't, I believe, and I have seen tests fail when run in parallel that don't when run serially. Oct 10, 2012 at 17:31
  • Is this issue what you are experiencing? Oct 11, 2012 at 2:15
  • @DanielBlackhall - I don't think that issue has anything to do with this. It's not even an "issue" since it works in practice, it's just that the tests around it in Eclipse fail. Oct 11, 2012 at 8:24

1 Answer 1


Ok, after much head scratching I've found a fix for my own question. In the off chance someone has a similar issue, where an email as part of the approval process uses visualforce components which the user running the test cases as fails in eclipse, but not anywhere else.. Anyway.

The fix for this issue was to grant the partner portal profile which is used by the user running the test, apex class permissions to the controller used by the visualforce component included in the email template which generated the "INSUFFICIENT_ACCESS_OR_READONLY, user does not have access to use approval assignment email template" error. After this, the test case succeeds in eclipse too.

EDIT: Sometime during this project (probably related to tweaks in sharing rules) the nature of the error changed. At least it got consistent in that it produced the same result no matter how you ran the tests, except that running it through a real click-through worked and the tests doing the same thing consistently failed (we got this instead: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: [])

I found no other way than to cheat in the test cases and add a sharing rule to the account in question, just before the critical section:

AccountShare aShare = new AccountShare(); aShare.AccountId = theAccount.Id; aShare.UserOrGroupId = thePortalUser.Id; aShare.AccountAccessLevel = 'Read'; aShare.OpportunityAccessLevel = 'None'; insert aShare;

Don't know why but formatting of code doesn't play nice, sorry about the mess.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .