0

Currently I am trying to block certain profiles from changing UnitPrice within Quote. I used validation rules under customize> QuoteLineItem and worked perfectly fine. However those validation rules only work when the product has been already added. The Issue I have right now; is when the user adds a product inside quote by clicking on "Add Line Item" they are prompted to a page where they can enter quantity. There is also a UnitPrice there as well. They are still allowed to change the price. I am not sure how i can access that page and how I can disable that field within the page. I thought the below trigger could do it, but I am not sure how to add certain profile or even where do i add that trigger to for this page.

changing the UnitPrice there

Check if the value of "UnitPrice" has changed like

if(trigger.new[0].UnitPrice != trigger.old[0]).UnitPrice)
{
trigger.new[0].addError('You can not change the value of SalesPrice');
}

currently this is what I have as validation rule that stops user from changing price after the lineItem has been added

OR(AND(ISCHANGED(UnitPrice),$UserRole.Id  = "00E..."),AND(ISCHANGED(UnitPrice),$UserRole.Id  = "00E..."))

Updated: the new validation rule using my own profile ID as a test case

OR(
    AND(ISNEW(), NOT(ISNULL(UnitPrice)),
    AND(NOT(ISNEW()), ISCHANGED(UnitPrice)),$UserRole.Id = "00EG00....")
)
7
  • Don't ever use hard-coded Ids except as a last resort. Here, you should use $UserRole.DeveloperName instead of $UserRole.Id. Are you testing as someone with a blacklisted role?
    – Adrian Larson
    Dec 23, 2016 at 17:12
  • No I have many users under a role and I dont want any of them to have the option to change the price at any time during of quote creation and adding line item. @AdrianLarson
    – Metawaa
    Dec 23, 2016 at 17:17
  • Yes, I understand what you are trying to do...that's what I mean by blacklist. Are you testing as a user who has a role that should be disallowed?
    – Adrian Larson
    Dec 23, 2016 at 17:24
  • @AdrianLarson yes I added my own role ID, admin and I am testing it under my own name
    – Metawaa
    Dec 23, 2016 at 17:25
  • @AdrianLarson this is the new validation rule I added with my own profileId OR( AND(ISNEW(), NOT(ISNULL(UnitPrice)), AND(NOT(ISNEW()), ISCHANGED(UnitPrice)),$UserRole.Id = "00EG00....") )
    – Metawaa
    Dec 23, 2016 at 17:29

1 Answer 1

1

Stick with your Validation Rule. You just need to add a clause for ISNEW.

OR(
    AND(ISNEW(), NOT(ISNULL(UnitPrice)),
    ISCHANGED(UnitPrice)
)

If you want to add a UserRole blacklist to the mix, I recommend the following:

AND(
    1 = CASE($UserRole.DeveloperName,
        "Admin", 1,
        "OtherBlacklistedRole, 1,
        "etc...", 1,
        0
    ),
    OR(
        AND(ISNEW(), NOT(ISNULL(UnitPrice)),
        ISCHANGED(UnitPrice)
    )
)

Note that both formulas should work equally well for the insert and update case. If you really insist on keeping the insert and update rules separate, they would be:

Insert Rule

AND(
    1 = CASE($UserRole.DeveloperName,
        "Admin", 1,
        "OtherBlacklistedRole, 1,
        "etc...", 1,
        0
    ),
    ISNEW(),
    NOT(ISNULL(UnitPrice))
)

Update Rule

AND(
    1 = CASE($UserRole.DeveloperName,
        "Admin", 1,
        "OtherBlacklistedRole, 1,
        "etc...", 1,
        0
    ),
    ISCHANGED(UnitPrice)
)
8
  • Thanks for the reply. If I write this as an individual validation rule, would it override the other one. I just added that as its own and it didnt work I was just wondering. I am adding this under quoteLineItem
    – Metawaa
    Dec 23, 2016 at 16:50
  • Can you be more specific about what didn't work?
    – Adrian Larson
    Dec 23, 2016 at 16:51
  • So I added what you have to validation rules (Under QuoteLineItem) and then I went and try to add a new product to a quote by clicking on"Add Line Item" change the sales price(UnitPrice) and saved it. it didnt stop me. I am going to update my question with what I have so far. I added your rule as a new rule besides what I already had
    – Metawaa
    Dec 23, 2016 at 17:09
  • @Metawaa Take a look at the updated formula...
    – Adrian Larson
    Dec 23, 2016 at 17:37
  • Do you mind to tell me what this does $UserRole.DeveloperName and 1,0
    – Metawaa
    Dec 23, 2016 at 17:39

You must log in to answer this question.

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