4
You can create a Unique field (Unique_Course_Student_Relationship__c) on the junction object and populate it with a concatenation of StudentId and CourseId through a workflow on create.
CASESAFEID(StudentId) + CASESAFEID(CourseId)
This will ensure that there's never two junction records with the same Student and Course as the value of that field needs to be ...
2
You can write a before trigger on the junction object and check if the combination already exists. If yes then use addError to throw an error.
Only top voted, non community-wiki answers of a minimum length are eligible
Related Tags
lookup × 908apex × 164
visualforce × 131
trigger × 81
marketing-cloud × 69
ampscript × 67
custom-object × 65
relationships × 63
lookup-filter × 63
master-detail × 59
soql × 56
lightning × 34
custom-field × 33
lightning-aura-components × 32
account × 26
process-builder × 25
formula × 23
contact × 23
dataextensions × 21
related-list × 21
search × 21
email × 18
filters × 17
javascript × 16
workflow × 16