I have an after insert flow that fires on opportunity.
I have a test class that needs to create an opportunity.
public static Account CreateAccount (){
Account newAcc = new Account ();
newAcc.name = 'Test Account Name';
newAcc.BillingCountry = 'United States';
newAcc.Industry = 'Finance';
newAcc.Account_Category__c = 'Commercial';
insert newAcc;
system.debug('newAcc.id:: ' + newAcc.Id);
return newAcc;
}
And Also a CreateOpportunity
public static Opportunity CreateOpportunity(){
Account newAcc = CreateAccount();
Opportunity oppNew = new Opportunity();
oppNew.RecordTypeId = '0124H000000seDZQAY';
oppNew.Name = 'Test Opp';
oppNew.CloseDate = System.now().date();
oppNew.StageName = 'New';
oppNew.account = newAcc;
insert oppNew;
return oppNew;
}
However, when the test class is executed, I get an error on the testmethod:
13:27:28:404 EXCEPTION_THROWN [52]|System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_EXECUTE_FLOW_TRIGGER, We can't save this record because the “After Insert - Opportunity” process failed. Give your Salesforce admin these details. An unhandled fault has occurred in this flow
An unhandled fault has occurred while processing the flow. Please contact your system administrator for more information.: []
The log shows the following error, mentioning that the field: Account_Category__c is not set. But it exists in the create record:
13:27:28:396 FLOW_ELEMENT_ERROR The flow failed to access the value for Get_Account_Category_from_Account.Account_Category__c because it hasn't been set or assigned.|FlowDecision|No_Account_Category_For_Errors
The Account insert is successful, as shown in the log entry:
16:41:13:052 USER_DEBUG [32]|DEBUG|newAcc.id:: 0017E00001DY8XZQA1
Being around computers for many years:: Where's my mistake? What's wrong with the flow of data in this scenario?
Tried as in the suggested edit: Error: Illegal assignment from Id to Account
I added a debug print, just before the insert oppNew
Looks like the 'Account Category' exists.
I think the error is that the 'After Insert' Flow - does not recognize the Account object. Even that the account was created before.
Get_Account_Category_from_Account
is not set. Sharing the details of the node that tries to get said account might help.