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
Ashley KabakciAshley Kabakci 

IF statement formula help - getting an error

I am trying to do the following: 
On a contact record, if the Mobile Phone field is not blank, use it to populate the Phone in Use field on the same contact record. If the Mobile Phone field is blank, then use the Work Phone field to populate the Phone in Use field. If the Work Phone field is blank, then use the Home Phone field to populate the Phone in Use field. If the Home Phone field is blank, then use Other Phone field to populate the Phone in Use field. If the Other Phone field is blank, the Phone in use field remains blank. 

I created the formula below, but I am getting an error I don't know how to fix: "Error: Incorrect parameter type for function 'IF()'. Expected Boolean, received Text"

IF(NOT(ISBLANK(MobilePhone)), Phone_In_Use__c = MobilePhone,
IF (NOT(ISBLANK(npe01__WorkPhone__c)), Phone_In_Use__c =  npe01__WorkPhone__c,
IF (NOT(ISBLANK(HomePhone)), Phone_In_Use__c =  HomePhone,
IF (NOT(ISBLANK(OtherPhone)), Phone_In_Use__c =  OtherPhone,
" "
))))
 
Shri RajShri Raj
Phone_In_Use__c = 
  NOT(ISBLANK(MobilePhone)) ? MobilePhone :
  NOT(ISBLANK(npe01__WorkPhone__c)) ? npe01__WorkPhone__c :
  NOT(ISBLANK(HomePhone)) ? HomePhone :
  NOT(ISBLANK(OtherPhone)) ? OtherPhone :
  null;

 
AnkaiahAnkaiah (Salesforce Developers) 
Hi Ashely,

try with below formula,
IF(NOT(ISBLANK(MobilePhone)), MobilePhone,
IF (NOT(ISBLANK(npe01__WorkPhone__c)), npe01__WorkPhone__c,
IF (NOT(ISBLANK(HomePhone)), HomePhone,
IF (NOT(ISBLANK(OtherPhone)), OtherPhone,
""
))))

Refer the below link formula fuctions with an examples
https://developer.salesforce.com/docs/atlas.en-us.usefulFormulaFields.meta/usefulFormulaFields/customize_functions.htm

If this helps, Please mark it as best answer.

Thanks!!
 
RajivKocherlaRajivKocherla
// Hi, writing your requirement using Apex code if condition is easier, you can try the below piece of code, i can try the Salesforce formulas tomorrow, Salesforce formuals sometimes don't work as expected because the instance does not act the way the formula is written.

List<Contact> con = [Select Id, Name, MobilePhone, TestPhoneContact__c from Contact];
for(Contact cc:con){
// #1.  This piece of code will help you with if the Mobile Phone field is not blank, use it to populate the Phone in Use field on the same
// contact record
 
if(cc.MobilePhone !='') {
     cc.MobilePhone = cc.TestPhoneContact__c;   
    }}
// #2.  If the Mobile Phone field is blank, then use the Work Phone field to populate the Phone_in_Use__c field.
    if((isBlank(MobilePhone)){
        Work_Phone__c = Phone_In_Use__c;
    }
// #3. If the Work Phone field is blank, then use the Home Phone field to populate the Phone_in_Use__c field.
       if((isBlank(MobilePhone) && (Work_Phone__c))){
           Home_Phone__c = Phone_In_Use__c;
       }  
// #4. If the Home Phone field is blank, then use Other Phone field to populate the Phone_in_Use__c field.
       if((isBlank(MobilePhone) && (Work_Phone__c)) && (Home_Phone__c)){
           Other_Phone__c = Phone_In_Use__c;
       }
// #5. If the Other Phone field is blank, the Phone_in_use__c field remains blank.
       if((isBlank(MobilePhone) && (Work_Phone__c)) && (Home_Phone__c) && (Other_Phone__c)){
           Other_Phone__c = Phone_In_Use;
       }
}
// Note: from point number 2 until #5 you have to factor the previous fields that were mentioned blank too.
                                         Hope this helps