You need to sign in to do that
Don't have an account?
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>
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
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, '')}"/>
Thank you very much. it works perfectly!