0
Account accountRecord =[Select Id From Account Where Id='001ABCABCABCABYAAQ'];

The above code results in an Exception(System.QueryException) in Apex as there is no Account with the given Id. But it didnt throw any exception in a flow. Is this expected behaviour with flows?

1
  • I assume you got an error like "List has no rows for assignment to SObject". In a flow it's a bit different because it assumes you are getting a collection of records (and if it's empty it is fine). If you use a List instead - it will not throw an error Nov 14, 2020 at 13:22

1 Answer 1

2

In Apex if you mimic what is happening in a flow - it is about retrieving a collection (not a single record).

So for example your code above if it's like this:

List<Account> accountRecord = new List<Account>();
accountRecord =[Select Id From Account Where Id='001ABCABCABCABYAAQ'];

You will not get an error. Of course the list will also be empty. This is usually where you want to check if anything was retrieved by checking the size of the list before you execute any logic - like:

if (accountRecord.size() > 0)
//Do something with the collection by looping through it

You must log in to answer this question.

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