3

This is my scenario:

 - Object Name: Contact . 
 - Field:
    -Status__c (Picklist) contains: Active ,Inactive or NULL
    -StatusDetail__c (Text)

The requirement is whenever Status not null , we don't want user to update StatusDetail if the StatusDetail previously is not null. Meaning if currently StatusDetail contains value, it won't be updated if Status is not null. This validation should apply in UI and also update through backend such as Apex class or DataLoader.

Initially I created Validation Rule on StatusDetail__c such as:

AND(NOT(ISBLANK( TEXT(Status__c )) ) ,NOT(ISBLANK( PRIORVALUE(StatusDetail__c ))),ISCHANGED(StatusDetail__c ))

But I have problem when I try to edit Status field through UI, not StatusDetail, it won't allow to Save at all. While it should allow me to save because I only update Status not StatusDetail. Then I read here that Validation rule won't apply on certain case as below:

Validation rules continue to run on individual records if the owner is changed. If the Mass Transfer tool is used to change the ownership of multiple records, however, validation rules won’t run on those records.

Now I am thinking maybe doing in trigger is the best way, but is there any other method that I need to try first before proceeding with trigger? Or is TRIGGER actually the best for my situation?

5
  • Does Status__c have a default value of Inactive or can it also be left Blank? It appears to me that may be at the root of your problem. A picklist can have data entered into it other than what's in the list. If the default is None, that may not necessarily be Blank if you entered a space, carriage return or other character in the 3rd placeholder of the list or other data somehow got entered into into your database.
    – crmprogdev
    Oct 23, 2014 at 16:38
  • @crmprogdev , yes the picklist also can be NULL .We don't want user to update StatusDetail__c if Status__c is not null/blank and previous value of StatusDetail__c not blank.
    – unidha
    Oct 24, 2014 at 2:27
  • 1
    If that's the case, you may want to test for the other two conditions instead, meaning TEXT(Status__c) = "Active" OR "Inactive" rather than testing against the NOT(ISBLANK(TEXT(Status__c)) ) condition used at the beginning of your rule. The two are equivalent but allow for what can happen with data populated in picklists. I agree with @UweHeim, no need for a trigger here.
    – crmprogdev
    Oct 24, 2014 at 2:54
  • Thanks a lot, but I m trying to figure out this statement :'Validation rules continue to run on individual records if the owner is changed. If the Mass Transfer tool is used to change the ownership of multiple records, however, validation rules won’t run on those records. ' What is it mean?Is it will not apply on back end update?
    – unidha
    Oct 27, 2014 at 7:27
  • 1
    That's correct. If there's a mass transfer of records to a new owner, the validation rules will not be run. Unless you have a validation rule that depends on who the Owner is, there really should be no need to be concerned about this. Note that this is distinct from a workflow rule used for something like case assignment or lead assignment where other criteria would come into play when assigning ownership. That's workflow, not validation.
    – crmprogdev
    Oct 27, 2014 at 8:02

1 Answer 1

2

In my opinion your approach is fine and I see no pressing need for a trigger here. If it can be done with validation, I would suggest to avoid the trigger as long as possible.

I implemented the scenario you have described in a DE org and wasn't able to see that it does not work, i.e. I'm able to change Status__c whether or not StatusDetail__c is NULL and I can change StatusDetail__c as long Status__c is NULL. Hope, that I got your requirements right so far.

If you think you have some reproducible clicking sequence which does not do what you want, please let me no and I will have a look on it.

I hope that no other settings or other validation rules may interfere on your org.

1
  • Based on your answer, I will take it as better use validation rule.Using trigger only when there no option for Validation rule.
    – unidha
    Nov 3, 2014 at 1:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .