SOLVED

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

Go to solution
Jo_Pitts1
Level 10 - Community Advisor

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

@SanfordWhiteman ,

we must stop meeting like this.

SNAP (Again)

Jo_Pitts1
Level 10 - Community Advisor

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

@SanfordWhiteman ,

Should the empty guard be && or || ?

Cheers

Jo

SanfordWhiteman
Level 10 - Community Moderator

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

&& because they both need to be non-empty.

Jo_Pitts1
Level 10 - Community Advisor

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

Ahh.. I misread what you'd done there (it's been an overly  long day 🙂 ).

Somewhere in my head I'd seen that you'd only had a single ! and bracketed the two .empty tests (goodness knows how)

i.e. (!( myList.isEmpty() && myOtherList.isEmpty() )

which would have have required an ||.

 

michaelstancil
Level 3

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

This is the error I get trying that

 Screen Shot 2021-12-16 at 9.06.44 PM.png

Jo_Pitts1
Level 10 - Community Advisor

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

@michaelstancil ,

try wrapping all your core code in this #if( ! $display.alt($myList,"").isEmpty() )

(replacing myList with your lists)

#if( ! $display.alt($myList,"").isEmpty() )
  #foreach(myItem in myList)
    #set($thing=myItem.thing)
  #end
#end

 

(This code was provided by @SanfordWhiteman  when I was getting a similar error).  

 

So, assign your lists to local variables.  However, before you do any iterations of them test for emptiness

 

Cheers

Jo_Pitts1
Level 10 - Community Advisor

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

@SanfordWhiteman ,

I'm curious.  When I was having the same conundrum as @michaelstancil , you gave me a 'long form' version..

namely: 

 

#if( ! $display.alt($myList,"").isEmpty() )

 

 

Since then you've gone with the simpler 

 

#if( !$myList.isEmpty() )

 

 

For my continuing education and edification, why the change in recommendation (sorry if this seems like a **bleep** question, I'm just trying to get my Velocity as good as it possibly can be)?

Cheers

SanfordWhiteman
Level 10 - Community Moderator

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

Sorry, missing a dollar sign up there. Edited.

michaelstancil
Level 3

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

@Jo_Pitts1 Thanks for that! Silly question but how do I input the no value check?

 

@SanfordWhiteman I updated based on the edit, and now I get:

Screen Shot 2021-12-16 at 9.33.27 PM.png

Could it be where I'm placing the Token?

SanfordWhiteman
Level 10 - Community Moderator

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

Sure you don’t have another {{my.token}} in the email that’s specifically pointing to the 0th element?