0

I have to accomplish this - The System should prevent users from changing any values on the Opportunity record except the Opportunity Stage when the Opportunity Stage is set to "Final Bid Submitted" for Opportunities with ‘Testing’ Record Type.

Can this be achieved with Validation rule or I need to write trigger for this

3 Answers 3

3

Too long; didn't read version:

A validation rule can be used, but, for your intended use, cannot be guaranteed to work 100% of the time.

If you need 100% assurance that your rule won't be circumvented, it's better to write a trigger (or a workflow rule with a field update) to change the recordType of your Opportunity and assign it (the recordType, that is) a page layout where every field except StageName is set to read only.

long version

This can be accomplished using a validation rule...to some extent.

It appears to be less of an issue in your case, but for sake of example let's take the following simplified case:

You want to create a validation rule on Opportunity, which for this example we'll say has only 3 fields, StageName, Amount and Description.

You want to prevent changes to all fields, except StageName, when StageName is Contract Sent or Closed Won

A potential validation rule to enforce this could be

AND(
  NOT(ISCHANGED(StageName)),
  OR(
    ISPICKVAL(StageName, 'Contract Sent`),
    ISPICKVAL(StageName, 'Closed Won')
  )
)

The issue with this is that if StageName is currently Contract Sent, and you change it to Closed Won, you can also change Description and Amount.

Now, I have no experience in accounting, but changing the Amount of an Opportunity after a contract has been sent seems like a bad idea.

To fix this loophole, we need to modify our example validation rule

AND(
  NOT(ISCHANGED(StageName)),
  OR(
    ISPICKVAL(StageName, 'Contract Sent`),
    ISPICKVAL(StageName, 'Closed Won')
  ),
  OR(
    ISCHANGED(Description),
    ISCHANGED(Amount)
  )
)

That was a fairly simple modification, and captures changes attempting to be made to the other fields. It still allows changes to Description and Amount when the stageName isn't Contract Sent or Closed Won.

The issue with this, however, is that we needed to add, into the validation rule, every field we want to prevent changes to. In practice, Opportunity has more than 3 fields. You would also need to update the validation rule every time you added or removed a field from Opportunity

Validation rules do have a character limit (I don't remember if the limit is 3900 or 5000), but given enough fields, you will not be able to include all of them.

The conclusion here is that validation rules don't work too well when you try to enforce something of the form If condition x is true, prevent changes to all fields except field y.

If you choose to go this route, the basic validation rule you would end up with could look like this

AND(
  RecordType.Name == 'Testing',
  ISPICKVAL(StageName, 'Final Bid Submitted')), 
  NOT(ISCHANGED(StageName))
)

It can be easily circumvented, and you'd be relying on users not knowing about how to defeat your validation, or being too lazy to do so (if there's one thing that I know about salespeople, or users in general, they hate making extra clicks).

A more robust solution would be to either have a trigger or a workflow rule (with a field update) to change the recordType when your Opp's StageName reaches Final Bid Submitted.

The advantage to changing the recordType is that you can assign a different page layout to it. In that different page layout, you can mark your fields (save for StageName) as read-only.

Using this method, it's impossible for your users (except system administrators) to directly change any field except for the field(s) you want them to change.

0
IF( 
(NOT(ISNEW()) && RecordType.Name == 'Testing' && ISPICKVAL(StageName, 'Final Bid Submitted')), 
IF(ISCHANGED(StageName), 
FALSE, 
TRUE 
), 
FALSE 
)
0

I am not sure this is the best answer, but maybe it can help you. Here is the pseudo code. You can replace field names with the correct field names in your Validation Rule later.

AND(
ISCHANGED(Opportunity.LastModifiedDate),
Opportunity.Stage='Final Bid Submitted',
Opportunity.RecordType='Testing')
1
  • Its not working unidha
    – Samir
    Commented Aug 3, 2016 at 9:42

You must log in to answer this question.

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