0

I am wanting the flow to select the opportunity with latest creation date from all related opportunities on the account.

I am struggling to define the Condition Requirements of the flow

This is the solution in APEX from this post, if there a way to modify this to work in flow?

Opportunity latestOpportunity = [SELECT Id FROM Opportunity WHERE AccountId = :myAccountVariable ORDER BY CreatedDate DESC LIMIT 1];

I have tried a flow with Configure Trigger: A record is created to check a checkbox. I am running into trouble with maintaining this checkbox only on the most recent opp as it will also need to uncheck when a new opportunity is created.

5/30/24 Update to original post to troubleshoot flow

Flow should work only on one opportunity record type

enter image description here

I want it to check a checkbox on the most recent opportunity enter image description here

enter image description here

Error received when attempting to create opp in testing enter image description here

2
  • 1
    Welcome to SFSE! Please take a look at how to ask a question. As of now, this question lacks significant detail to demonstrate what you've tried so far, what research you've done, or what particular issue you are having with your flow. The question is unlikely to get a good response and may be closed. Please edit your question to provide specific details about your challenge - we are here to help, not to do your work for you. Commented May 24 at 15:32
  • 4
    Does this answer your question? Get the last created Opportunity Record with Flow or Process Builder
    – cropredy
    Commented May 25 at 0:21

1 Answer 1

1

You can easily achieve this in a flow by using the "Get Element":

  1. Get Opportunity records
  2. Filter the retrieved Opportunity records by specifying that the AccountId should be the same as myAccountVariable
  3. Specify that only the first record should be stored
  4. Sort the Opportunity records by CreatedDate DESC

enter image description here

This will ensure that if the relevant Account record has more than one Opportunity, the "Get Element" will only store the latest one.

Updated after screenshots provided

Your Get_Latest_Opp Get Element is faulty. You used the variable myAccountVariable correctly, but you did not assign it a value before the Get Element.

You can also just use the global variable {!$Record.AccountId} to get the relevant Opportunity's related AccountId:

enter image description here

Also, with regards to your entry criteria, it would suggest not hardcoding Record Type Ids, as the Id can possibly change between orgs, which mean you have to change the flow every time you deploy it to another org.

Rather set the "Condition Requirements" to "Formula Evaluates To True" and use the formula:

{!$Record.RecordType.DeveloperName} == "YOUR_RECORD_TYPE_DEVELOPER_NAME"

Good luck!

6
  • Hello Adriaan, thank you! I have used this in my flow but am getting an unhandled fault error. The myAccountVariable is a Data Type = Text value, correct?
    – Labeau30
    Commented May 29 at 19:27
  • 1
    @Labeau30 that is correct. You can update your question with the flow you created together with the error you are receiving and then we can have a look at what is going on. Commented May 30 at 6:45
  • Adriaan thank you so much, I've added to the question my screenshots.
    – Labeau30
    Commented May 30 at 15:22
  • 1
    @Labeau30 I updated my answer - hopefully it solves your issue! Commented May 30 at 21:09
  • 1
    Changing to the global variable {!$Record.AccountId} works! Thank you!
    – Labeau30
    Commented May 31 at 14:28

You must log in to answer this question.

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