First, a little background information: I'm working on an end-to-end custom quoting solution that leverages the standard Quote object. We also utilize Sterling CPQ, which serves as the end-state for all quotes created using our VF page (the Sterling mashup is a little sluggish and lacks a few features that are much more easily-implemented by our custom solution). Users will create a standard Quote record using the page, and after they're satisfied with the changes they will be "promoting" the record to a CPQ quote.

Other unnecessary details aside, we have this process working quite well. That is, until I decided to add a Visualforce email template into the mix. An email alert that goes out upon successful Quote promotion previously used a standard HTML email template and things seemed to work fine...the email was sent out as it should have been, and test cases executed with no problems. However, because I wanted to show fields on other related objects without adding a bunch of formula fields to the Quote object, I decided to swap the email template out for a VF email template. Manual testing continued to work just fine, but now our Apex test executions are failing with the following message:

System.DmlException: Insert failed. First exception on row 0; first error:
    INSUFFICIENT_ACCESS_OR_READONLY, user does not have access to use approval
    assignment email template: []

I should note that we are not using any kind of approval process on the Quote object or a custom Apex controller for the VF email template, which is why the solution to this question didn't seem to help much. I also found this on the community boards, although I haven't attempted to deploy the application to production yet, since the test case is failing in the sandbox in which it was developed. The header for the email template looks something like:

    subject="Proposal for Opp {!relatedTo.Opportunity.Name} Promoted to Quote"
    recipientType="User" relatedToType="Quote">

Has anyone seen something like this, where text case execution works fine with an HTML template but not with a VF email template? Please let me know if I can add any additional information.

Update: Here's a watered-down version of one of the test cases that is failing. The failure never indicates the line number, but it would have to be at Test.stopTest(); because the call to promoteToQuote right above it is a future method and its execution would be delayed. The future method normally would make a webservice callout, process the response (although in the case of test execution, it uses a mocked-up response), and then update the quote record's status to "Promoted" if successful (this condition is what the workflow rule in question fires on, and that's the only place where it would be getting set to this).

static testmethod void testPromoteToQuoteSuccess() {
    User usrAE = UnitTestUtil.createAE();
    insert usrAE;
    System.runAs(usrAE) {
        Account a = UnitTestUtil.createAccount();
        insert a;
        Opportunity o = UnitTestUtil.createOpportunity(a.Id);
        insert o;

        Quote q = new Quote(OpportunityId=o.Id);
        q.Proposal_Status__c = 'Active';
        q.Name = o.Name + ' - Proposal';
        insert q;


And of course there are a bunch of assertions made after stopTest that have been removed. Record permissions should not be an issue, as the running user should be the owner of all records used in the test. I'm currently in the process of going through all of the UnitTestUtil methods I'm using line-by-line, although I'd be surprised if that was the issue since the test cases were executing successfully prior to using a VF email template.

  • Do users from which test is getting executed have object permissions ? Is the folder that consists the Vf template accessible by the user ? Is the User running the test has access to the record ? Feb 22, 2013 at 16:41
  • Yes, the object permissions should not be the issue as the tests executed fine before and the test user is assigned a specific profile with the necessary permissions. Both the HTML and VF templates are located in the same "Unfiled Public" folder. The test user creates the opportunity and quote in the test case, so it is the owner of both records.
    – JCD
    Feb 22, 2013 at 16:52
  • intresting and serious as to why this is occuring!Stumped infact! Feb 22, 2013 at 17:16
  • Can you try running your tests with seealldata=true? EmailTemplates should be visible even with that set to false but they are sobjects and maybe one of the related objects is not visible. Feb 24, 2013 at 19:08
  • It'd help if you posted a stripped down test method and indicate which line is generating the failure. I'd also go ahead and start working with Salesforce support. Seems 50/50 that this is going to be bug. Feb 24, 2013 at 23:56

4 Answers 4


I encountered the same problem today:

System.DmlException: Update failed. First exception on row 0 with id 006o0000003SSs7AAG; first error: INSUFFICIENT_ACCESS_OR_READONLY, user does not have access to use approval assignment email template: []

While the symptom was indeed a Visualforce Email Template, the true cause was that the running user context was the Site Guest User when firing the Workflow Rule.

It is not possible to send emails on behalf of Site Guest User. My workaround in this case was to change the Workflow Rule Email Action to a Create Task Action, which guests are permitted to own.


Just ran into this issue today.

Solution background:

  1. testmethod with System.runAs(myuser) updates an Opportunity.
  2. Opportunity fires a workflow with an email alert
  3. Email alert uses a VF email template that refers to a VF component with an APEX controller

Answer for me was to grant myuser's profile access to VF component's controller class.


Your testing user usrAE may be the key as to why this works when done manually but not when run in the test cases.

As a first step, could you try running the test as the user that works in the manual tests? I.e. select the existing User rather than creating a new one.

If that still fails, try using an existing Account, Opportunity and Quote objects with seealldata=true.

The idea is to simplify the test back towards what works in the UI until a cause is found. It certainly isn't a long term solution, but will hopefully provide more clues.

I did find a similar question: Test case fails in eclipse, same test case succeeds in webinterface. Click-through also succeeds. If I'm reading the answer correctly the issue there was profile permissions for the controller used by the Visualforce component included in the email template.

  • Thanks for your response @Daniel, I took a look at that other question but it seemed that the error message made much more sense in that case as it at least involved an approval process (where in this case I have no approval process). Right now I'm still working through the profile permissions - the thing that concerns me is the test case passed successfully prior to introducing the VF email template (usrAE had the exact same setup before and after).
    – JCD
    Feb 26, 2013 at 13:56

I've had:

 System.DmlException: Insert failed. First exception on row 0; first error:
 INSUFFICIENT_ACCESS_OR_READONLY, user does not have access to use approval
 assignment email template: []

Because the user who was running the test lacked access to the folder that the email was held in. It wasn't an 'approval/assignment' email though, it was just a workflow email.

  • Thanks @Steven, the email template in this case is in an "Unfiled Public" folder that all profiles in our org have access to. I suppose Salesforce just refers to any email template as an "approval assignment email template" whether it has anything to do with an approval process or not...odd.
    – JCD
    Feb 26, 2013 at 13:59

You must log in to answer this question.

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