How to get help with Salesforce IF formula?
I am creating a Formula field that returns texts when:
Picklist_Status = Activated, the return text should be A else null
Picklist_Status = Sold, the return should be B else null
Picklist_Status = ChangeofMind , the return should be C else null
So these are 2 picklist fields that would update the formula field if a OR b OR C is true.
My FORMULA:
OR (
IF ( ISPICKVAL ( Status__c , 'Verified Complete' ), 'B' ,
IF ( ISPICKVAL ( OHSI_Status__c , 'Ok for Production' ), 'B+' ,
IF ( ISPICKVAL ( OHSI_Status__c , 'Activate' ), 'A'
'null' ))))
Error: Incorrect parameter type for function 'OR()'. Expected Boolean, received Text I do not know where to put the OR.. these 3 should be OR
I think that part of your confusion lies in what a Salesforce IF formula field is. A formula field is something that is computed every time it is accessed from a persisted SObject (i.e. when you query this field via SOQL, or view the field on a Visualforce page, the field value is re-computed). There's nothing that needs to be "updated", it happens automatically.
Let's take the following example where we update a field value in Apex. Keep in mind that this is an example, and not meant to be able to be copy/pasted verbatim.
// We can directly assign a query result to a single SObject instance, but this isn't
// safe.
// It only works when the query returns exactly 1 result
MyObject__c myObj = [SELECT Id, My_Formula__c, Status__c, OSHI_Status__c FROM MyObject__c LIMIT 1];
// For sake of example, let's say that Status__c == null, and OHSI_Status__c == 'Ok for Production'
System.debug(myObj.My_Formula__c); // This debug should then output 'B+'
// Now, let's update a field
myObj.OSHI_Status__c = 'Activate'
// This debug should output 'B+'
// We've updated the field value in memory only. The formula value is calculated on the database
// side of things
System.debug(myObj.My_Formula__c);
// Save our changes
update myObj;
// Now that we've made a change to the stored value of one of the fields that
// contributes to the formula field, we can ask for the same record again
// (which will cause the formula field to be recalculated
MyObject__c updatedObj = [SELECT Id, My_Formula__c, Status__c, OSHI_Status__c FROM MyObject__c WHERE Id = :myObj.Id];
// Re-querying the record, after its data has been updated, causes the formula to be
// re-calculated
System.debug(myObj.My_Formula__c); // This debug should output 'A'
Thus, the OR() you're trying to include is not necessary.