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
Anil DuttAnil Dutt 

Formula Filed to return value

Hi,

 

I have some fileds for Passenger like

 

p1_First_Name__c , p1_Last_Name__c

p2_First_Name__c , p2_Last_Name__c

p3_First_Name__c , p3_Last_Name__c

 

I want to create a Formula Filed which return value on following condition

 

int i =0;

if(p1_First_Name__c !=null && p1_Last_Name__c !=null)

then  i = i +1;

if(p2_First_Name__c !=null && p2_Last_Name__c !=null)

then i= i +1;

 

and so on

 

So of all filed are not null then total of 4 value will return

If 3 fileds  not null then value will be 3

 

Please help

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
Anil DuttAnil Dutt

SRK

 

Thanks for all you help

 

but following did the trick

 

IF(OR(ISBLANK(p1_First_Name__c) ,ISBLANK(p1_Last_Name__c)),0,1) + IF(OR(ISBLANK(P2_First_Name__c) , ISBLANK(P2_Last_Name__c)),0,1) +
IF(OR(ISBLANK(P3_First_Name__c) , ISBLANK(P3_Last_Name__c)),0,1) + IF(OR(ISBLANK(P4_First_Name__c) , ISBLANK(P4_Last_Name__c)),0,1)  +
IF(OR(ISBLANK(P5_First_Name__c) , ISBLANK(P5_Last_Name__c)),0,1)

 

and looks very cleaner

All Answers

SRKSRK

If u start int i =0; & all 3 have value the max value is 3 not 4

if we start with  i = 0
if 1 & 3 rd is null & 2nd hava data then value is 1 rite ??
correct me if i was wrong

Anil DuttAnil Dutt

yes , you are right

SRKSRK

hmmmm
i put the logic

int x = 1;

if(p1_First_Name__c !=null && p1_Last_Name__c !=null)

   x = x + 1;

if(p2_First_Name__c !=null && p2_Last_Name__c !=null)

  x = x+ 1;

if(p3_First_Name__c !=null && p3_Last_Name__c !=null)

  x = x+ 1;


if i understand it correct u can try the below mention formula

 

IF(AND(ISBLANK(p1_First_Name__c),ISBLANK(p1_Last_Name__c)),IF(AND(ISBLANK(p2_First_Name__c),ISBLANK(p2_Last_Name__c)),IF(AND(ISBLANK(p3_First_Name__c),ISBLANK(p3_Last_Name__c)),4,3),IF(AND(ISBLANK(p3_First_Name__c),ISBLANK(p3_Last_Name__c)),3,2)),IF(AND(ISBLANK(p2_First_Name__c),ISBLANK(p2_Last_Name__c)),IF(AND(ISBLANK(p3_First_Name__c),ISBLANK(p3_Last_Name__c)),3,2),IF(AND(ISBLANK(p3_First_Name__c),ISBLANK(p3_Last_Name__c)),2,1))

Anil DuttAnil Dutt

Can't we use some temporary variable to hold incremneted value?

 

like

int  x = 0;

X = X + 1;

 

 

SRKSRK

No i dont think so

hmmmm i look for it if i find anything i will let u know

Anil DuttAnil Dutt

Thanks, If we use variables it will be much cleaner and understandable

Anil DuttAnil Dutt

SRK,

 

Also you have created it for Null check

 

but i want to check not null condition

 

Will you please re-write it with not null check?

SRKSRK

try this
IF(NOT(AND(ISBLANK(p1_First_Name__c),ISBLANK(p1_Last_Name__c))),IF(NOT(AND(ISBLANK(p2_First_Name__c),ISBLANK(p2_Last_Name__c))),IF(NOT(AND(ISBLANK(p3_First_Name__c),ISBLANK(p3_Last_Name__c))),4,3),IF(NOT(AND(ISBLANK(p3_First_Name__c),ISBLANK(p3_Last_Name__c)),3,2))),IF(NOT(AND(ISBLANK(p2_First_Name__c),ISBLANK(p2_Last_Name__c))),IF(NOT(AND(ISBLANK(p3_First_Name__c),ISBLANK(p3_Last_Name__c))),3,2),IF(NOT(AND(ISBLANK(p3_First_Name__c),ISBLANK(p3_Last_Name__c))),2,1))

Anil DuttAnil Dutt

SRK

 

Thanks for all you help

 

but following did the trick

 

IF(OR(ISBLANK(p1_First_Name__c) ,ISBLANK(p1_Last_Name__c)),0,1) + IF(OR(ISBLANK(P2_First_Name__c) , ISBLANK(P2_Last_Name__c)),0,1) +
IF(OR(ISBLANK(P3_First_Name__c) , ISBLANK(P3_Last_Name__c)),0,1) + IF(OR(ISBLANK(P4_First_Name__c) , ISBLANK(P4_Last_Name__c)),0,1)  +
IF(OR(ISBLANK(P5_First_Name__c) , ISBLANK(P5_Last_Name__c)),0,1)

 

and looks very cleaner

This was selected as the best answer
SRKSRK

Grate  :)

swamyswamy

Hi,Anil you are writing is that for what purpose.....we can't understood that.....Just give me a small description....

Anil DuttAnil Dutt

@swamy

 

The purpose is to get How many passengers name has been entered