0

I have an after insert flow that fires on opportunity. enter image description here

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 enter image description here


I added a debug print, just before the insert oppNew enter image description here 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.

1
  • Seems like Get_Account_Category_from_Account is not set. Sharing the details of the node that tries to get said account might help. – Lafexlos Jan 28 at 15:53
1

Would you please try passing just the newAcc.Id to the oppNew in the create new opportunity APEX snippet.

oppNew.accountid = newAcc.Id;

I think this is the core of the issue.

7
  • 1
    i think you meant oppNew.AccountId = newAcc.Id – cropredy Jan 28 at 17:05
  • 1
    Yes it is AccountId, my bad – Boris Gichev Jan 28 at 20:21
  • Thank you for the offer, but that's not it: I get error: 'Illegal assignment from Id to Account' (picture added to OP) – Saariko Jan 31 at 7:21
  • Did you tried this, exactly. oppNew.AccountId = newAcc.Id – Boris Gichev Feb 1 at 8:26
  • Take into consideration the first comment of cropredy – Boris Gichev Feb 1 at 8:27

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.