How to lookup a value in one SFDC field (like Vlookup) | Community
Skip to main content
michaelstancil
New Participant
December 15, 2021
Solved

How to lookup a value in one SFDC field (like Vlookup)

  • December 15, 2021
  • 1 reply
  • 5910 views

Hi there,

 

So I'm more versed in Excel, so that's how I'll explain what I'm trying to do. I have a data set on a contact level that contains several items based off zip code. My opportunities have a zip code as well, and I want to get those items (one at a time) based on that zip code. 

 

Would creating a token that had a function of iF opportunityZIP matches contactZip, pull contactItem1 work?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

Well... not quite. (For one thing, you’re continually referencing the first/zero-th object in the list, which is a mistake a lot of people make.)

 

The shape of the new AVM object isn’t really clear, but it now sounds like you’re trying to intersect 2 different lists based on the equality of a specific property. Originally, it seemed like you were trying to intersect a list (the Opportunities) with a single object (the Lead).

 

Here’s one way to do a list intersection:

#set( $mergedOpptyAndAVMList = [] ) #foreach( $oppty in $OpportunityList ) #foreach( $avm in $AVM_Values__cList ) #if( $oppty.Zipcode__c.equals($avm.Zip_Code__c) ) #set( $void = $oppty.putAll($avm) ) #set( $void = $mergedOpptyAndAVMList.add($oppty) ) #end #end #end

This will leave you with the list $mergedOpptyAndAVMList — a new list where each member is an Opportunity object + AVM object merged into a single meta-object.  The objects are “joined” on their respective zip code properties.

1 reply

SanfordWhiteman
New Participant
December 15, 2021

Would creating a token that had a function of iF opportunityZIP matches contactZip, pull contactItem1 work?


Well, that’s not actual code. So hard to say if it would “work” or not. 🙂

 

In Velocity, if you want to match objects in List A (= Opportunities) based on whether a certain property value matches equals some property value in Object B:

  • #foreach over List A
  • check if each $iteratorVariable.property1.equals($lead.property2)
  • do something interesting on a match
michaelstancil
New Participant
December 16, 2021

I think I follow, so would this be correct in theory? Forgive me for sounding it out

 

 

#foreach over (${OpportunityList) #if(${OpportunityList.get(0).Zipcode__c}.equals(${AVM_Values__cList.get(0).Zip_Code__c})) #set( $TOKEN = $ITEM FROM CONTACT LIST) #end

 

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
December 16, 2021

Well... not quite. (For one thing, you’re continually referencing the first/zero-th object in the list, which is a mistake a lot of people make.)

 

The shape of the new AVM object isn’t really clear, but it now sounds like you’re trying to intersect 2 different lists based on the equality of a specific property. Originally, it seemed like you were trying to intersect a list (the Opportunities) with a single object (the Lead).

 

Here’s one way to do a list intersection:

#set( $mergedOpptyAndAVMList = [] ) #foreach( $oppty in $OpportunityList ) #foreach( $avm in $AVM_Values__cList ) #if( $oppty.Zipcode__c.equals($avm.Zip_Code__c) ) #set( $void = $oppty.putAll($avm) ) #set( $void = $mergedOpptyAndAVMList.add($oppty) ) #end #end #end

This will leave you with the list $mergedOpptyAndAVMList — a new list where each member is an Opportunity object + AVM object merged into a single meta-object.  The objects are “joined” on their respective zip code properties.