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
Tyler HarrisTyler Harris 

CASE() throwing Incorrect Argument Type Error

Hello,
 
CASE( First_Touch__c, ISNULL(First_Touch__c), Days_to_Lead_Touch_Today__c,NOT(ISNULL(First_Touch__c)), Days_LeadTouch_Business_Hours_FirstTouch__c,Days_LeadTouch_Business_Hours_FirstTouch__c )
I'm getting a  Error: Incorrect argument type for function 'CASE()' with this formula. I need to conditionally show a different formula field value based on certain criteria. IF() statement not working as I'm getting a compile error. Want to see if CASE() will avoid that.

Thanks in advance.
 
Best Answer chosen by Tyler Harris
pconpcon
If that's the case then sorry to tell you, you're out of luck.  You'll either have to do what you are trying to do in a trigger or at the display layer via a Visualforce page.  That is unless you can trim down the size of your formula [1]

[1] http://resources.docs.salesforce.com/198/11/en-us/sfdc/pdf/salesforce_formula_size_tipsheet.pdf

All Answers

pconpcon
Case is not what you want to use here.  Case only iterates over a list of values and doesn't do what you're looking for here.  A simple IF would do the trick.
 
IF(
    ISEMPTY(First_Touch__c),
    Days_to_Lead_Touch_Today__c,
    Days_LeadTouch_Business_Hours_FirstTouch__c
)

 
Tyler HarrisTyler Harris
Problem is this is referencing another formula field and when I use an If() statement it throws a compile error. It goes over the limit. My Days_to_Lead_Touch_Today__c is referencing this formula below and Days_LeadTouch_Business_Hours_FirstTouch__c is referencing another version of this formula. I want to conditionally show one value based on  if "First_Touch__c" is empty or not. Can't seem to dodge my compilation error.
 
IF(DATEVALUE( Owner_Assignment_Date__c ) <> TODAY(), 

/* If TRUE */ 
IF( 
/* Is same business week? */ 
AND( 
(CASE(MOD( DATEVALUE(First_Touch__c) - DATE(1985, 1, 5), 7), 0, 0, 1, 0, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 0) 
+ CASE(MOD(DATEVALUE(Owner_Assignment_Date__c) - DATE(1985, 1, 5), 7), 0, 0, 1, 
5, 2, 5, 3, 4, 4, 3, 5, 2, 6, 1, 0) 
>5), 
DATEVALUE(First_Touch__c) - DATEVALUE(Owner_Assignment_Date__c) < 6 ), 
/* Then work out the number of business days with this formula */ CASE(MOD(DATEVALUE(First_Touch__c) - DATE(1985, 1, 5), 7), 0, 0, 1, 0, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 0) 
+ CASE(MOD(DATEVALUE(Owner_Assignment_Date__c) - DATE(1985, 1, 5), 7), 0, 0, 1, 
5, 2, 5, 3, 4, 4, 3, 5, 2, 6, 1, 0) 
- 6, 
/* Otherwise use this formula */ 
FLOOR( 
( DATEVALUE(First_Touch__c) 
-(DATEVALUE(Owner_Assignment_Date__c) 
+ CASE(MOD(DATEVALUE(Owner_Assignment_Date__c) - DATE(1985, 1, 5), 7), 0, 0, 1, 
6, 2, 5, 3, 4, 4, 3, 5, 2, 6, 1, 0)) 
)/7)*5 
+CASE(MOD(DATEVALUE(Owner_Assignment_Date__c) - DATE(1985, 1, 5), 7), 0, 0, 1, 
5, 2, 5, 3, 4, 4, 3, 5, 2, 6, 1, 0) 
+CASE(MOD(DATEVALUE(First_Touch__c) - DATE(1985, 1, 5), 7), 0, 0, 1, 0, 
2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 0) 
), 

/* If FALSE */ 
0) 

+ 

/* Compensate depending on start and end time */ IF( 
/* End datetime's time of the day in minutes referred to 0:00 GMT */ VALUE(LEFT(RIGHT(TEXT(DATEVALUE(First_Touch__c)),9),2))*60 + 
VALUE(LEFT(RIGHT(TEXT(DATEVALUE(First_Touch__c)),6),2)) 
/* Start datetime's time of the day in minutes referred to 0:00 GMT */ < VALUE(LEFT(RIGHT(TEXT(DATEVALUE(Owner_Assignment_Date__c)),9),2))*60+VALUE(LEFT(RIGHT(TEXT(DATEVALUE(Owner_Assignment_Date__c)),6),2)) 
, -1, 0)

 
pconpcon
If that's the case then sorry to tell you, you're out of luck.  You'll either have to do what you are trying to do in a trigger or at the display layer via a Visualforce page.  That is unless you can trim down the size of your formula [1]

[1] http://resources.docs.salesforce.com/198/11/en-us/sfdc/pdf/salesforce_formula_size_tipsheet.pdf
This was selected as the best answer
Tyler HarrisTyler Harris
Thanks. I had a feeling I was running into a wall.