You need to sign in to do that
Don't have an account?
Kunal Purohit 4
How to apply validation rule in junction object?
I have junction object "Author-Research Paper". This object has two master detail relationship with objects "Authors" and "Research Paper".
Now,there must not be more than 5 Authors for single research paper. How to write validtion rule for it?
Now,there must not be more than 5 Authors for single research paper. How to write validtion rule for it?
1. Create an Apex Trigger on before insert of your junction object
2. In your trigger, iterate through the records inserted and for SELECT back the id's you're checking
3. If you find a match for the Case and Issue Id it won't be the current record (as it hasn't been written yet in a before insert trigger), all you need to then do is call the .addError method on the record
Depending on your objects it should look something like this:
trigger trg_bi_caseissue on CaseIssue__c (before insert) {<br> <br> <br> // Iterate through the list of new records<br> for (CaseIssue__c ci : trigger.new) {<br> <br> // We only care if there is one record<br> List<CaseIssue__c> resultList = [SELECT id, Name FROM CaseIssue__c <br> WHERE Case__c = :ci.Case__c<br> AND Issue__c = :ci.Issue__c];<br> <br> // Raise the error back if any records found <br> if (!resultList.isEmpty()) {<br> System.debug('Found another copy ' + resultList[0].id + ' name is ' + resultList[0].Name);<br> ci.addError('Duplicate record, a Case Issue already exists for that combination');<br> }<br> }<br><br>}<br>
For further reference, you can check this blog (https://developer.salesforce.com/forums/?id=906F000000091mrIAA)too.
I hope you find the above information is helpful. If it does, please mark as Best Answer to help others too.
Thanks.
They must check it thoroughly for compliance with the requirements and accept or send it back for additional review.
Source: research paper writers (https://researchpaperwriter.org/)