Skip to main content
ivvvan
Level 2
January 19, 2021
Solved

How to find if a boolean field is true on the latest Opportunity

  • January 19, 2021
  • 1 reply
  • 3552 views

Hi there,

I am having trouble finding a solution for my email script. Here I am trying to find if a boolean field is true or false on a customer's latest opportunity. 

Depending on the result, I would like to display different text. 

This is the code I am using: 

 

#set( $sortedList = $sorter.sort( $OpportunityList,["createdAt:desc"]) ) #if ($sortedList.get(0).HP_Payment_Protect__c) True, you have Payment Protect #else False, you do not have Payment Protect. #end

 


Please, and thank you.

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

If it's truly a Boolean field then use

 

#if( $sortedList[0].HP_Payment_Protect__c.equals(true) )

 

 

Don't rely on truthy and falsy coercion. It will lead to unexpected behavior. Use explicit comparison to the expected values.

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
January 19, 2021

If it's truly a Boolean field then use

 

#if( $sortedList[0].HP_Payment_Protect__c.equals(true) )

 

 

Don't rely on truthy and falsy coercion. It will lead to unexpected behavior. Use explicit comparison to the expected values.

ivvvan
ivvvanAuthor
Level 2
January 19, 2021

Thanks Sanford! 

I'm now having an issue with sorting. I'm using..

#set( $sortedList = $sorter.sort( $OpportunityList,["createdAt:desc"]) )

but it keeps returning the first Opportunity (null).

{HP_Payment_Protect__c=null, MarketoCreatedAt=2017-02-20 23:03:50} {HP_Payment_Protect__c=null, MarketoCreatedAt=2017-02-20 23:17:48} {HP_Payment_Protect__c=1, MarketoCreatedAt=2017-02-20 23:25:11} {HP_Payment_Protect__c=null, MarketoCreatedAt=2017-09-27 03:22:52} {HP_Payment_Protect__c=0, MarketoCreatedAt=2017-09-27 19:08:46} {HP_Payment_Protect__c=null, MarketoCreatedAt=2018-10-25 00:56:11} {HP_Payment_Protect__c=null, MarketoCreatedAt=2018-12-14 14:10:35} {HP_Payment_Protect__c=null, MarketoCreatedAt=2018-12-14 14:48:17} {HP_Payment_Protect__c=1, MarketoCreatedAt=2018-12-14 15:09:51} {HP_Payment_Protect__c=1, MarketoCreatedAt=2019-09-05 03:23:26}

 

SanfordWhiteman
Level 10
January 20, 2021

You're sorting on createdAt but you haven't selected a field of that name in the tree in Script Editor.