0

Use case:

  1. Trigger subscribes to Platform Event (hence running user = Automated Process)
  2. Trigger creates SObject w/ checkbox field set to TRUE
  3. Process Builder executes based on SObject values, generates VF Email

Result: In the rendered VF Email, the Boolean field displays as FALSE, even though the relatedTo value in the database is true

If the SObject is inserted manually by anyone other than the Automated Process user, the VF email renders the database field correctly as TRUE

Highly-related issue although symptoms observed are different than mine.

Here's the markup of the VF Email template:

<messaging:emailTemplate subject="Test VF template for platform events" recipientType="Contact" relatedToType="Log__c">
<messaging:htmlEmailBody >
This is a VF email template with embedded VF components. By way of reference, 
these are the values from the relatedTo object:
<ul>
 <li>ID:{!relatedTo.Id}</li>
 <li>Source__c:{!relatedTo.Source__c}</li>
 <li>Is_Success__c:{!relatedTo.Is_Success__c}</li>  <!-- The boolean field -->
 <li>CreatedDate:{!relatedTo.CreatedDate}</li>
 <li>CreatedBy.Name:{!relatedTo.CreatedBy.Name}</li>
</ul>
</messaging:htmlEmailBody>
</messaging:emailTemplate>

Rendered email (Running User = Automated Process)

This is a VF email template with embedded VF components. By way of reference, these are the values from the relatedTo object:
ID:a2jq0000001aveTAAQ
Source__c:PEVFTest Subject
Is_Success__c:false . <<<--- WRONG value !!?!!
CreatedDate:Fri Sep 21 15:07:36 GMT 2018
CreatedBy.Name:Automated Process

Rendered email (Running User != Automated Process)

This is a VF email template with embedded VF components. By way of reference, these are the values from the relatedTo object:
ID:a2jq0000001aveYAAQ
Source__c:PEVFTest Subject
Is_Success__c:true .  <<<----- correct value
CreatedDate:Fri Sep 21 15:10:29 GMT 2018
CreatedBy.Name:Fred Fubar

N.B. I'm also aware of (and can duplicate) this Automated Process user issue with VF Components with their own controller wherein you get Process builder Flow Error:

CANNOT_EXECUTE_FLOW_TRIGGER, We can't save this record because the “xxx” process failed. 
Give your Salesforce admin these details. 
This error occurred when the flow tried to create records: 
INSUFFICIENT_ACCESS_OR_READONLY: 
user does not have access to use approval assignment email template
  • Can you confirm that the checkbox field on the record is set to True when it's created as a result of the platform event firing? It does seem like a strange permissions issue. I'm wondering whether it's on the field or the record...or both...or neither! – Shane Steinfeld Sep 22 '18 at 18:17
  • @ShaneSteinfeld yes - i did soql query on the sobject in question. Platform event invokes trigger that simply inserts an sobject with various fields; then PB runs using that sobject - when i insert sobject as me, not via Platevt, same data in database, diff results in email – cropredy Sep 22 '18 at 20:11
  • @cropredy I have duplicated your example (simplified) using a Trigger on PE to insert an Account with a custom checkbox field, with a Process configured to fire on the insert of the Account. The Process checks if the Success__c field is true, and if so, logs the record using Apex, and sends out an email alert (code copied from your example). The context variable inside the Process evaluates to TRUE and Apex logging shows TRUE, but the email shows FALSE -- so it appears to be an discrepancy with the Email template binding. I also confirmed that sending template from Apex shows Success__c=False. – John Brock Sep 23 '18 at 19:47
1

I've found a few other similar posts. No answers yet, but they all point to the context user being the automated process user.

Try subscribing to the event using Process Builder or Visual Flow, instead of with a trigger. That way you can avoid the automated process user, and run in context of the user who initiated the event.

Take a look:

https://help.salesforce.com/articleView?id=000270230&language=en_US&type=1

  • I saw that article - it contradicts doc that states that processes execute as Automated Process – cropredy Sep 22 '18 at 20:21
  • Yeah, that's what I thought too, but I'm seeing both in form posts. I'm playing with it now to see what actually happens! – Shane Steinfeld Sep 22 '18 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.