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
Craig CoulterCraig Coulter 

Validation rules for new records

Hi all,

I have a custom object under opportunity and I want to prevent new records from being created if 1 already exists, this is what I have so far:

AND(ISNEW(), Opportunity__r.Of_Campaign_Reviews__c >= 1,
OR(Opportunity__r.Performance_Status__c <> "Amber",Opportunity__r.Performance_Status__c <> "Under"), OR(Opportunity__r.Days_Since_Last_Campaign_Review__c = NULL, Opportunity__r.Days_Since_Last_Campaign_Review__c <= 7), OR(Performance_percentage_on_creation__c >= 0.80, Opportunity__r.Performance_Percentage__c >= 0.80))

The first rule works fine if the record is not marked as completed, but the others don't seem to work as new records can be created within 7 days of the last one, or the performance status is notunder or amber etc.

What do I need to do to fix it?

Thanks

Craig
SubratSubrat (Salesforce Developers) 
Hello Craig ,

Can you try with below validation rule and let me know further :
 
AND(
    ISNEW(),
    Opportunity_r.Of_Campaign_Reviews_c >= 1,
    NOT(
        OR(
            Opportunity_r.Performance_Status_c = "Amber",
            Opportunity_r.Performance_Status_c = "Under"
        )
    ),
    NOT(
        AND(
            NOT(ISBLANK(Opportunity_r.Days_Since_Last_Campaign_Review_c)),
            Opportunity_r.Days_Since_Last_Campaign_Review_c <= 7
        )
    ),
    Performance_percentage_on_creation__c >= 0.80,
    Opportunity_r.Performance_Percentage_c >= 0.80
)

If it helps , please mark this as Best Answer.
Thank you.
Abdul KhatriAbdul Khatri
Hi Craig,

Please correct me if I am wrong, but here what is your requirement is, you want the validation execute
  • For New Record and
  • Performance Status equal to either Amber or Under or Days since last campaign review > 7
Can you tell me what is with the percentages
Arun Kumar 1141Arun Kumar 1141

Hi Craig,

Please try the following updated rule:-
 

AND(
ISNEW(),
Opportunity__r.Of_Campaign_Reviews__c >= 1,
OR(
Opportunity__r.Performance_Status__c <> "Amber",
Opportunity__r.Performance_Status__c <> "Under"
),
OR(
ISBLANK(Opportunity__r.Days_Since_Last_Campaign_Review__c),
Opportunity__r.Days_Since_Last_Campaign_Review__c > 7
),
OR(
Performance_percentage_on_creation__c >= 0.80,
Opportunity__r.Performance_Percentage__c >= 0.80
)
)

If you find this helpful, please mark it as best answer.

Thanks.
Craig CoulterCraig Coulter
Thanks for the replies.

Unfortunately, both examples allow a new record to still be created when there is already an active record within 7 days and has not got a performance status of either Amber or Under.

@Abdul, yes, the validation should show the error if a new record is created when there is already one active with the last 7 days, has not got the performance status or either Amber or Under. The percentages were added as an experiment as they are what determines the Performance Status, so anything over 80% will be on target and not require looking at.