Find your content:

Search form

You are here

Test case fails in eclipse, same test case succeeds in webinterface. Click-through also succeeds


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| |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: []

Attribution to: Martin Peters

Possible Suggestion/Solution #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.

Attribution to: Martin Peters
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content