function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
cfishercfisher 

vCard if statement

Hi - I'm new to Apex Coding and would like some help concerning adding a Country Code to a vCard export application.  We have a custom field in our Contacts called Country Code.  We would like this to appear before the relevant phone/fax/cell number when we export it out of Salesforce and into Outlook via a vCard.   If we just concatenate the code (underlined), the Country Code will appear even if there isn't a number in that field.  The entire code is below, but the modified code for fax is bolded. Thanks for any help!

 

apex:page title="GeneratevCard.vcf" cache="True" contentType="text/x-vcard#{!Contact.LastName + Contact.FirstName}.vcf" standardcontroller="Contact">BEGIN:VCARD

VERSION:2.1

N;CHARSET=utf-8:<c:EscapeVCard sValue="{!Contact.LastName}"/>;<c:EscapeVCard sValue="{!Contact.FirstName}"/>

FN;CHARSET=utf-8:<c:EscapeVCard sValue="{!Contact.Name}"/>

ORG;CHARSET=utf-8:<c:EscapeVCard sValue="{!Contact.Account.Name}"/>

TITLE;CHARSET=utf-8:<c:EscapeVCard sValue="{!Contact.Title}"/>

 

 

TEL;CELL;VOICE:<c:EscapeVCard sValue="{!Contact.CountryCode__c + Contact.MobilePhone}"/>

TEL;WORK;VOICE:<c:EscapeVCard sValue="{!Contact.Phone}"/>

 

if (Contact.Fax != null) {

                   TEL;WORK;FAX:<c:EscapeVCard sValue="{!Contact.CountryCode__c + Contact.Fax}"/>

}      else   {

                   TEL;WORK;FAX:<c:EscapeVCard sValue="null" /> }

 

TEL;Home;VOICE:<c:EscapeVCard sValue="{!Contact.HomePhone}"/>

EMAIL;PREF;INTERNET:<c:EscapeVCard sValue="{!Contact.Email}"/>

ADR;CHARSET=utf-8;WORK;PREF:;;<c:EscapeVCard sValue="{!Contact.MailingStreet}"/>;<c:EscapeVCard sValue="{!Contact.MailingCity}"/>;<c:EscapeVCard sValue="{!Contact.MailingState}"/>;<c:EscapeVCard sValue="{!Contact.MailingPostalCode}"/>;<c:EscapeVCard sValue="{!Contact.MailingCountry}"/>

X-MS-OL-DEFAULT-POSTAL-ADDRESS:0

X-MS-OL-DESIGN;CHARSET=utf-8:

END:VCARD

</apex:page>

Best Answer chosen by Admin (Salesforce Developers) 
vishal@forcevishal@force

Hey,

 

If I have understood your requirement correctly, you want the country code to appear only when there's a MobilePhone number. If it is blank, even the country code shouldn't go.

 

Since you are passing the values directly to a custom component, you can add your IF clause directly there:

 

TEL;CELL;VOICE:<c:EscapeVCard sValue="{!IF(Contact.MobilePhone != NULL, Contact.CountryCode__c + Contact.MobilePhone, '')}"/>

All Answers

vishal@forcevishal@force

Hey,

 

If I have understood your requirement correctly, you want the country code to appear only when there's a MobilePhone number. If it is blank, even the country code shouldn't go.

 

Since you are passing the values directly to a custom component, you can add your IF clause directly there:

 

TEL;CELL;VOICE:<c:EscapeVCard sValue="{!IF(Contact.MobilePhone != NULL, Contact.CountryCode__c + Contact.MobilePhone, '')}"/>

This was selected as the best answer
cfishercfisher

Thank you very much. it works perfectly!