function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Update Account after Lead Conversion before opportunity is created?

We have a required filter on the Account field in opportunity that only lets one type of account be selectable for the opportunity.  I wrote a trigger on Leads (after update) to change the record type of the account that was created to the correct account type via a SOQL update. When the opportunity is generated after lead conversion I get the error:


Error: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_FILTER_VALIDATION_EXCEPTION, Value does not exist or does not match filter criteria.: [AccountId] (System Code) External entry point 


This sounds like the opportunity is trying to be created before the trigger can update the account record to the correct type.  Is there a way around this so that I can update account fields before SFDC tries to create the opportunity?


I was doing something similar with old lead convert, but I needed to do all account manipulations in the account before trigger.


You need to check if you are running old convert or Apex Convert, or even if Apex Convert made it to market.


Even though you have access to the AccountId in the after trigger of the lead, I almost sure that the database doesn't let you edit it quite yet.

But the account trigger fires as in any account insert so you have full access to the account within the normal trigger. You can test if this is an account from the convert by checking the status of a field that is only mapped from lead convert, or something like that.