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
Sanchi9Sanchi9 

Validation Rule on Quote

Hi!

Given: Quote has a lookup with Pricebook.
I want to write a validation rule on Quote object, to not change the pricebook if Quote line items already exists. 
 
Best Answer chosen by Sanchi9
Sanchi9Sanchi9
Hi Veer!

Thank you for your reply!
Yes you are correct, Quote line item is a child object. So for that I have made a Roll-up summary on Quote object for storing the count of the line items and I am using that field in my validation rule. 
I've modified the rule ANUTEJ suggested and it works fine for me:

AND(
NOT(ISNEW()),
ISCHANGED ( Pricebook2Id ),
 LineItemCount >0
)
 

All Answers

ANUTEJANUTEJ (Salesforce Developers) 
Hi Priya,

Can you try the below rule once:
 
AND(
NOT(ISNEW()),
ISCHANGED (Pricebook2Id)
)

then if the above validation rule that checks if the record is not new and if the pricebook2Id field value is changed then you can throw an error.

Let me know if it helps you and close your query by marking it as the best answer so that it can help others in the future.  

Thanks.
ravi soniravi soni
hi Priya.
I think you want if quote line item(lookup of quote) has any record and pricebook is change then validation will be fire.
am I right?
if I'm right then you can't write validation. instead of it you will have to write trigger because quote line item is the child object and you can't get reference any child object into validtion or formula.
let me know did I get you right, then I will be write a trigger for this requirment.
Thank you
 
Sanchi9Sanchi9
Hi Veer!

Thank you for your reply!
Yes you are correct, Quote line item is a child object. So for that I have made a Roll-up summary on Quote object for storing the count of the line items and I am using that field in my validation rule. 
I've modified the rule ANUTEJ suggested and it works fine for me:

AND(
NOT(ISNEW()),
ISCHANGED ( Pricebook2Id ),
 LineItemCount >0
)
 
This was selected as the best answer
Suraj Tripathi 47Suraj Tripathi 47
Hi Priya,

You can go through this link..

https://developer.salesforce.com/forums/?id=9060G000000Xfl4QAC
If you find your Solution then mark this as the best answer. 

Thank you!

Regards 
Suraj Tripathi
fsaf asfsaf as
I want to use this script for my blog. Can you help for address lookup (https://kiwisearches.com/reverse-address-lookup).