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
Sanjana RajasekarSanjana Rajasekar 

Validation Rule Support

Hi , I have a usecase where If Sales Agreement record is edited, Its related Opportunity is Closed Won and Sales agreement  type is 'New Business' . Should prevent users to add products.

I tried this, But this Validation throws message If it Creating Sales agreement record.
AND(

ISPICKVAL( SalesAgreement.Sales_Agreement_Type__c , 'New Business'),
ISPICKVAL( SalesAgreement.Opportunity__r.StageName ,'Won' ),
NOT(ISNEW()),
NOT(ISBLANK( PricebookEntry.Product2.Name ))
)
SubratSubrat (Salesforce Developers) 
Hello Sanjana ,

To fix this issue, you can remove the condition that checks if the record is not new, and instead, add a condition to check if the record is being edited. Here's an updated validation rule that should work:
 
AND(
  ISPICKVAL(SalesAgreement.Sales_Agreement_Type__c, 'New Business'),
  ISPICKVAL(SalesAgreement.Opportunity__r.StageName, 'Closed Won'),
  NOT(ISNEW()),
  ISCHANGED(SalesAgreement.Opportunity__c),
  NOT(ISBLANK(PricebookEntry.Product2.Name))
)


This validation rule will only trigger when a Sales Agreement record is being edited, its related Opportunity is "Closed Won", the Sales Agreement type is "New Business", and a product is being added to the Sales Agreement.

If this helps , please mark this as Best Answer.
Thank you.