0

I have an <apex:component> that is tied to a VF email template. I am assigning the AccountId as the attribute. The issue now is that when I try to do a field update in the Account record (DML) in getter method, I get an error.

<apex:component controller="AccountController" access="global" allowDML="true">
    <apex:attribute name="accountId" assignTo="{!accountId}" type="String" description="Id of the account object"/> 

Apex Class:

Setter:

public void setRecipientName(String accountId) {
        accountInfoId = accountId;
    }

Getter: I am trying to do a DML here and as per the documentation, it is not allowed.

 public User getRecipientName(){
     // Here I am updating the field account status to the value based on the approval process instance step status.
}

I looked into this post but it's not helpful. Can you perform DML operations from visualforce email templates?

Is there any other workaround?

4
  • What's the Use Case behind this? Maybe there are other possible solutions. Jul 27, 2022 at 8:07
  • The use case is that when the approver is reassigned using approval process, I need to update the record field to a new value. I am unable to accomplish this using flow or trigger since trigger on ProcessInstance is not possible. That's why I came up with this solution since I was using visualforce email templates. Jul 27, 2022 at 8:09
  • Why not use the Field Update option in approval process after approval actions? Jul 27, 2022 at 8:45
  • @AnnaWalach There’s no field update for reassign. Jul 27, 2022 at 8:46

1 Answer 1

1

Judging from the fact that there is an Idea for this: https://ideas.salesforce.com/s/idea/a0B8W00000GdfDIUAZ/assign-actions-to-reassign-functionality-in-approval-process

And since a similar question has been asked earlier without a response: Performing an action when user reassigns an approval step

I'm afraid there is no straightforward solution.

The Email Service solution described here in Satya's answer seems like the best option: Can you perform DML operations from visualforce email templates?

A workaround could be to use a 3rd party approvals app that has it's own datamodel (so you can link whatever logic you want) but that might have a large impact on your org and will also have extra costs associated. An example is Approvals Pro: https://appexchange.salesforce.com/appxListingDetail?listingId=a0N3A00000FMcp7UAD (full disclosure: I'm associated with Approvals Pro)

You must log in to answer this question.

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