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
kfrankfran 

Validation Rules

How do I creat a Validation Rule that affects one particular field only?  I have a Validation Rule in the Stage field of Opportunities that says my sales team cannot advance to one stage without selecting another.
 
The problem is...if they need to Edit another field within the Opportunity record, the validation rule kicks in.  How can I write a formula so the validation rule is only applicable for one specific field?
 
Please help.
 
Thanks,
Kim
JonPJonP
Check out the ISCHANGED() function.  From online help:

"Compares the value of a field to the previous value and returns TRUE if the values are different. If the values are the same, this function returns FALSE."

You can use ISCHANGED() to limit your validation rule so that it only raises an error if the opportunity stage field was changed.
kfrankfran
I will give this a try.  Thanks so much! :)
Reeses498Reeses498
Do you mind sharing your validation rule with me?  I am trying to do the exact same thing and I'm having a terrible time...new to salesforce and not an IT person
kfrankfran

Here is the formula that seems to have done the trick:

AND (
     ISPICKVAL( StageName, "Won-Contract Signed") ,
NOT(ISPICKVAL( StageName ,"Visited") ) )

In the stage field, the formula makes it so my sales team cannot advance to one stage without making sure they select another stage first.  This validation rule only affects the "Stage Field."  I think its because of the 'AND.' 

I originall had both AND and OR on there, which I think was causing the problem.

 

Good luck.

 

 

JonPJonP
If I'm reading this correctly, your validation rule will always shows an error if StageName is "Won-Contract Signed" regardless of what the previous StageName was.  ISPICKVAL() evaluates the current (new) value of StageName, not the previous value.

If StageName = "Won-Contract Signed" then:

A = ISPICKVAL(StageName, "Won-Contract Signed") = TRUE
B = ISPICKVAL(StageName, "Visited") = FALSE

AND(A, NOT(B)) = AND(TRUE, NOT(FALSE)) = TRUE


When you test this, are you ever able to set the StageName to "Won-Contract Signed"?

kfrankfran

Oh my goodness, you are correct!  I just tested and I am not able to set the Stage Name to "Won-Contract Signed."

Have any suggestions?  Is the formula you previously sent what I need to change my validation rule to?

JonPJonP
Try this:

AND (
     ISPICKVAL( StageName, "Won-Contract Signed") ,
     NOT(ISPICKVAL( PRIORVALUE(StageName) ,"Visited") ) )
kfrankfran

This worked!  Thanks so much.  I'm glad you spotted my original mistake.

 

Thank you!!

 

Reeses498Reeses498

unfortunately, this did not work for me.  We have several stages, but the stages I want to make sure do not get skipped are "Opportunity Identification" and "Opportunity Qualifiication"...so, you cannot move to "proposal stage" or "won-active" unless the opportunity has historically been at both of these stages.

 

Is there anything you recommend?

kfrankfran

I actually had to re-work  my validation rule to:

AND (
     ISPICKVAL( StageName, "Won-Contract Signed") ,
     NOT(ISPICKVAL( PRIORVALUE(StageName) ,"Visited") ) )

This makes it so my sales team cannot select the Stage Name "Won-Contract Signed" unless they select Stage Name "Visited" first. 

Post name JonP helped me re-work my formula.  Maybe you can try using the PRIORVALUE function?  I was missing this in my previous Validation rule.

JonPJonP
How about multiple validation rules, one for each stage in sequence?

Or if you need something less rigid, it might be time for an Apex Trigger.  If Opportunity Stage History is accessible from Apex (I'm not certain it is) then you could query to see what stages had been previously set, not just the immediate prior one.


kfrankfran

This is a good idea to look into.  I have a question about another issue.  Is it possible to create a relationship between an Opportunity Field and a Contact Field?  I have a custom text field in Opportunity, and I want that field to pre-populate in the Contact record  - kind of like field mapping, but i know you can only map lead fields.

I've received the suggestion that I need to create a formula to do this, but I'm not sure if it's even possible.

JonPJonP
Depends what you want to do.  If you want to show a value from opportunity on a contact, read-only, then the feature you're looking for is called "Cross-Object Formulas".

If you want the contact field to be copied from the opportunity initially, but editable on the contact, there are several strategies but none of them are as simple as a formula field.
kfrankfran

I want to show a read-only value from the Opportunity to the contact field, but just text.  I've looked up Cross Object Formulas, but will this work for text?

I have a field in Opportunities where my sales staff can type notes (open text), and I want those same text notes to pre-populate in the Contact Record attached to that opportunity.  Is this possible through Cross Object Formulas?

JonPJonP
I don't think cross-object formulas will work for what you want.

If I understand your requirement correctly, you have multiple opportunities, and each opportunity has a Text (Long) field "Note", and for a contact you want to show all "Note" fields on all opportunities related to the contact's account.  Is that roughly what you want?

An Opportunity is typically related to one Account, and a Contact is related to one Account.  But cross-object formulas only let you go "up" the hierarchy, e.g. from Contact you could show a field on Account, but you couldn't go Contact -> Account -> Opportunities (many).

If you have a custom field on Contact that is a lookup to one Opportunity, you could use that field in your cross-object formula, but I don't think that's really what you're looking for.
kfrankfran
Yes, this is exactly what I want to do.  Each opportunity has a Text (Long) field "Note", and I want that same field with the text notes to show on the contact record related to the opportunity.
 
I've been tod that cross-object formulas might work, but have had no success.  Any suggestions?  Maybe this just isn't possible?
JonPJonP
I'm still not clear--what is the relationship between the Contact and the Opportunity?  It is a custom lookup field on Contact, such that a Contact can be related to one and only one Opportunity via this relationship?

Or can a Contact be related to multiple Opportunities?

If the former, you may be able to use cross-object formulas.  If the latter, then cross-object formulas will not work.

Cross-object formulas only work when you have a path from one record to one other specific record.  They cannot be used to pull values from 1..N (multiple) records.  (There is a feature called Roll-Up Summary Fields that can aggregate values from multiple child records to a parent, but they only work with numeric values [e.g. SUM, AVERAGE, MIN, MAX] and still produce a single result, not a list of all results.)
kfrankfran

Currently there is no relationship, but I'm hoping I can create one.  We track our sales in Opportunities, so when my sales staff wants to add  long text notes, they can do it in the customized field in Opportunity.  However, i would also like those notes to pre-populate in the Contact record linked with that opportunity.  This will make it so if we search for a contact, the same notes from that Opportunity record will also be displayed in the contact record  Do you think this is possible?

JonPJonP
I still don't think a one-to-one relationship is what you want.  Is each contact always only associated with at most one opportunity?  That doesn't sound like the real world--but you may have a business model where the requirement is that simple, and if so that's great.

But I still think what you want is, from a contact, to find and display all the notes on all the opportunities that contact is related to (in some manner--which you need to define) on the contact detail page.  For that, you will have to use Visualforce or an S-Control so you can control the query and display behaviors.

kfrankfran

Yes, I was thinking an S-control might help.  I will research this and see if I can build the correct S-control to do this.

 

Thanks.