apex-enterprise-patterns / fflib-apex-mocks

An Apex mocking framework for true unit testing in Salesforce, with Stub API support
BSD 3-Clause "New" or "Revised" License
423 stars 214 forks source link

renderStoredEmailTemplate returns with an error System.EmailTemplateRenderException: INVALID_CROSS_REFERENCE_KEY: invalid cross reference id when passing Ids generated from fflib_IDGenerator #127

Closed raffaelle09 closed 3 years ago

raffaelle09 commented 3 years ago

Is there anyway to render the email template body in the test class without committing the referenced records in the database?

just a quick sample:

@isTest
private static void renderEmailTemplate (){

    EmailTemplate temp = [SELECT Id from EmailTemplate LIMIT 1];
    Id accId = fflib_IDGenerator.generate(Account.SObjectType);
    Id conId = fflib_IDGenerator.generate(Contact.SObjectType);

    Messaging.SingleEmailMessage email = Messaging.renderStoredEmailTemplate(temp.Id, conId, accId);
}
ImJohnMDaniel commented 3 years ago

@raffaelle09, thanks for reaching out. There is no feature in ApexMocks to achieve this. You may have success by querying the EmailTemplate table and try your own merge to the template.