+ Start a Discussion

How do you use cross-object references in flow?

I'm just getting started with flow, but I'm very experienced with Apex and VisualForce so many concepts are familiar to me. However, I'm having trouble understanding how cross-object field references (https://help.salesforce.com/HTViewHelpDoc?id=vpm_designer_crossobject_reference.htm&language=en_US) are supposed to work.

How do I use cross-object references in screens or conditions?

If I use a cross object reference in a screen such as {!order.Customer__r.Name}, I don't see anything. If I try and query a field like Customer__r.Name in a Fast Lookup, validation fails and the name gets erased. Likewise, if I try to use something like {!order.Customer__r.Name} in a decision, validation fails and that reference is erased.

I have a custom object called Order__c with a lookup called Customer__c which points to an Account. In other words, Order__r.Customer__c is an Account Id.

What's the easiest way to display a screen with the order name and the customer's name?

What I tried
1. Create a Fast Lookup to get the Order__c that assigns to a variable called order and fetches the order's Name. If I try to add Customer__r.Name to fields, the value doesn't validate and gets erased. Therefore, I just query Customer__c (an account Id) as the help article seems to imply I need to do.
2. I create a screen and try to reference {!order.Customer__r.Name} and I see nothing. The article seems to imply that Salesforce might magically query the needed but missing info, but that doesn't seem to work.

Of course, I can do another fast lookup to query an Account query Account.Id = order.Customer__c and assign that to a variable named customer, the access {!customer.Name}. However, I'm trying to figure out how cross-object references work in flow to hopefully simplify things.

1. What am I doing wrong?
2. Should cross-object references result in some data being queried automatically? How is the cross-object data supposed to come in?
3. Can you use cross-object references with related children / lists in addition to lookups?

I fully understand how to add additional fast lookups to my flows to get the necessary data and I'm try just trying to see if there's some cross-object reference magic that can take a few explicit steps out.


Karen MadiganKaren Madigan
Hi JonWu,

Here is the easiest solution that has worked for me:

Put the cross-object reference in a formula element and use the formula in your screen display.  This is a super easy way to reach out to a field on a related object.  Here is an example from one of my Flows where "NewRnwlGrpRec" is an Opportunity sObject.User-added image

Something that I have found also works when I need to reach out a couple levels is to create a temporary sObject to help point to the end object. For instance, in the example you gave, if you wanted to access a field on the Account and you know the ID of the Account, you would create a Customer sObject and put the ID of the Account you wanted to access into the Account field, and then use a formula to retrieve information from the Account. So if you needed the Account Name your formula would be something like:  CustomerSObject.Account.Name (for standard objects) or CustomObject__r.NextObject__c.ObjectName (for custom objects).

Like you, I was struggling with how to access information on related objects without using up additional Lookups. There may be better solutions out there, but these are the ones I've worked out so far.

'Hope this helps!
Hi Karen,

Your insight helps a lot and I'm glad I'm not the only one confused. It seems like we can enter cross-object references into textareas that are used for a screen and it looks like for formulas too. However, anywhere there's a dropdown, the validation just erases whatever you type if it's not in the dropdown so maybe that's a bug.

It seems like with your formula workaround, you could probably use your formula within a decision to solve that. However, I'm actually having trouble getting it to work now on a new test flow I'm creating. I've actually been able to use a cross-object reference within a screen directly once before, but in a test I just created, I was unable to get the cross-object reference to work in either a screen directly or by putting it in a formula as you suggested. For example, I did a Fast Lookup for an Order__c object and assigned it to order, then referenced {!order.Customer__r.Name} in both a screen and an account object but had no luck.

At the end of the day, even with a formula, it doesn't seem worth it to be using this seemingly buggy feature. If we have to create a formula to grab a cross-object value, then adding another fast lookup is just as good if not better since you'd be able to fetch multiple fields at once vs having a make another formula for each value you wanted to use.

Thanks for your response!
Andy Kallio 7Andy Kallio 7
@JonWu   I'm having the same issue. My situation is a fast lookup on Quoteline items where I want to limit the line items by a field on the Product2 object. In other words Select * quotelineitem where Product2.Custom_Field__c = True

Looks like Fast lookup won't allow that and the only recourse is to create a cross object formula field on the Quote Line Item object to get the value from Product2 onto QuoteLineItem, which can then be referenced in the flow. 
Rick UptonRick Upton
Vote for the Idea Flow to Allow Cross Object Filters in Lookups (https://success.salesforce.com/ideaView?id=0873A000000TqtmQAC)  The workaround to add a formula field doesn't work if you're working with objects that don't allow formula fields.