0

I have built a flow that displays the closest accounts within a 10 mile radius. The flow is launched via a button on the account the user is currently viewing. Below is the flow:

enter image description here

This works perfectly fine in my Sandbox. However on my production org it fails due to the following error: "Error Occurred: Too many query rows: 50001"

I assume its working on my Sandbox because there are only about 20 accounts.

How can I resolve this issue on my production org? Is there something I can change to my flow?

Any help much appreciated

Thanks

2 Answers 2

2

Your issue is indeed because you query all accounts and not a subset of them. Check if you can use DISTANCE function when getting accounts in a flow and use it if you can.

If that is not possible, you may need to write an Apex method where you can query accounts filtered on the distance from a given location. For more info read this documentation, especially the part about the WHERE clause:

Usage: DISTANCE(mylocation1, mylocation2, 'unit') and replace mylocation1 and mylocation2 with two location fields, or a location field and a value returned by the GEOLOCATION function. Replace unit with mi (miles) or km (kilometers).

Example:

SELECT Name, Location__c 
FROM Warehouse__c 
WHERE DISTANCE(Location__c, GEOLOCATION(37.775,-122.418), 'mi') < 20
1
  • thanks for the reply Novarg. I think I may need to do this on APEX, unfortunately I have no experience in this.
    – Timmy
    Jan 19 at 8:52
1

Instead of looping over all accounts and checking the radius in for loop, you can try adding the same condition in the Get Accounts.

That is, the field you are checking in the Decision statement, add the filter criteria in the Get Accounts itself.

So instead of getting all the accounts, the query will provide only those accounts which are within the radius.

You must log in to answer this question.

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