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
Medhanie HabteMedhanie Habte 

Creating a formula field for mail merges disambiguating between contacts and accounts

I am looking to reformat a formula field I've created for a custom object. This formula field, disambiguates between the account object and contact object, as we are on the one-to-one relationship model in Salesforce, in which a contact that is an individual is both contact/account and a contact representing a company is a group.

Currently my formula for the field is configured this way, I've created a concatenated formula in contact object which takes the first and last name and merges it into one. For instance First Name: Joe Last Name: Smith = Joe Smith

For the custom Object I've designed this formula in the field

IF(Account__r.Name = Contact__r.FullName__c , NULL,"Attn: " & Contact__r.FirstName & Contact__r.FullName__c)

However, at times, when I only input the last name and leave the first name field blank, in the instance that the contact does not have the first name, the Attention to formula returns a value when it should be blank.

Are there any customizations, I can make to my formula to make it so that even without the first name filled, it only returns when the account name and contact name do not match. IE Account Name SampleCO, Contact Joe Smith

Account                               Contact                                     Attention to

User-added image
Best Answer chosen by Medhanie Habte
Jayson Faderanga 14Jayson Faderanga 14
IF(OR(
Account__r.Name =  Contact__r.FullName__c,
Account__r.Name = Contact__r.FirstName,
Account__r.Name = Contact__r.LastName),
Null,
"Attn: " & Contact__r.FirstName & Contact__r.FullName__c)

// we are comparing the First Name and Last name. we used the OR operator to evaluation the other 2 conditions.

Hope that helps :D

All Answers

Hargobind_SinghHargobind_Singh
Hi, seems like the condition to check both FirstName and LastName should be blank needs to be added to this formula. Try this: 

IF( AND(NOT(IsBlank(Contact__r.FirstName), NOT(IsBlank(Contact__r.LastName),   Account__r.Name != Contact__r.FullName__c ),"Attn: " & Contact__r.FirstName & Contact__r.FullName__c, NULL)
 
Jayson Faderanga 14Jayson Faderanga 14
IF(OR(
Account__r.Name =  Contact__r.FullName__c,
Account__r.Name = Contact__r.FirstName,
Account__r.Name = Contact__r.LastName),
Null,
"Attn: " & Contact__r.FirstName & Contact__r.FullName__c)

// we are comparing the First Name and Last name. we used the OR operator to evaluation the other 2 conditions.

Hope that helps :D
This was selected as the best answer
Medhanie HabteMedhanie Habte
Hi Jayson, Amazing, This definitely works and has improved our processes greatly. Thanks!