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
Tom FarringtonTom Farrington 

OR Validation to force pick list but avoid Email to salesforce fail

Hi All,

Wouldn't consider myself a developer but this seemingly simple bit of code I can't get working.

What i'm trying to do:  I want to enforce picklist values for the task 'subject' field.  That I can do.  However, that also stops email to salesforce working as that inputs in the subject.... "Email: [subject line from email]".  This doesn't work if my validation rule to enforce picklist is active.

Therefore I thought simple OR rule to say picklist or begins with 'Email: ' so it would still work but also enforce the rule.  Heres what I've tried with no success:

Or(
 Begins(Subject,”Email: “),
   and(
   Subject <> 'Email',
   Subject <> 'Call',
   Subject <> 'Letter',
   Subject <> 'Fax',
   Subject <> 'Other',
   Subject <> 'In Person',
)
)

Any help would be appreciated.

Thanks
Best Answer chosen by Tom Farrington
RD@SFRD@SF
Hi Tom,

Sorry for late reply, I think i have faced some similar scenario. Can you have a look at the ISNEW() function in the validation rule formulas. using this we can check if the record is getting created or updated.

I am assuming here that while conversion the status value would not be completed. You can add NOT(ISNEW()) in your validation rule 

AND((NOT(ISNEW()),Status,"Completed"),(ISBLANK(outcome__c))

this should help you to solve it.

Regards
RD

All Answers

RD@SFRD@SF
Hi Tom,

By enforcing means you want the picklist to hold only these value right?
 in this case you can delete the unwanted values from the task picklist definition itself
Does this solve your problem?

Regards,
RD
Tom FarringtonTom Farrington
Hi RD,  sorry no that doesn't solve the problem.  The subject field allows both picklist entry and text entry.  So deleting all but the picklist fields still allows the user to input anything they like.

My problem with this code has actually changed slightly (sorry), as now we are happy users entering free text into the subject box, (which also solves my email to salesforce problem), but want to force them to enter a text field 'outcome' before being able to save it as completed.

That seems simple enough, validation something like this:
and(
  (Status,"Completed"),
  (isblank(outcome__c)
)

I've got that working no problem but this creates a new issue.  Now, whenever a user converts a lead, or complets any action where there is an empty task section at the bottom, the validation kicks in and stops them converting the lead.

I therefore tried the following which I couldn't get working:
if(
   and(
      (isblank(Subject)),
      (isblank(ActivityDate)),
   ),
Null,
   and(
      (Status,"Completed"),
      (isblank(outcome__c)
   )
)

So above basically says if the subject and activity date are blank, do nothing (i.e. false don't trigger rule), if not, and the status is marked as completed, and the outcome field is blank then show validation.

If the task is empty I don't want to validate anything, but if it is actually a task, and is actually completed, I want to force entry in the outcome field.

Hope that all makes sense.  I'm now trying to sort out a roll up field work around, salesforce joys!

Thank you in advance for any help you can offer,

Tom
 
RD@SFRD@SF
Hi Tom,

Sorry for late reply, I think i have faced some similar scenario. Can you have a look at the ISNEW() function in the validation rule formulas. using this we can check if the record is getting created or updated.

I am assuming here that while conversion the status value would not be completed. You can add NOT(ISNEW()) in your validation rule 

AND((NOT(ISNEW()),Status,"Completed"),(ISBLANK(outcome__c))

this should help you to solve it.

Regards
RD
This was selected as the best answer
Tom FarringtonTom Farrington
Thanks RD, you helped me solve this problem ages ago I just never replied.  On to a whole new set of issues now, thanks for the help!