You need to sign in to do that
Don't have an account?
Avoid Duplicates in Master-Detail Relationship
Hi,
I have two object School and Student.
They are having master detail relationship where School(Master) --> Student(Child)
Each school must contain student name with unique values.
For e.g. School Name : DOn Bosco
Student Name: Ajay
Student Name : Kunal
It should not allow another record with student name as 'Ajay', because it is already available under DOn Bosco.
But student Name "Ajay" can allow to add under different school name (say under St. Xaviers), simply because "Ajay" belongs to different school.
How to resolve this problem?
Cheers,
Devendra S
This trigger avoids Insertion of Account with duplicate name.
You have to develop something similar.
You would have to avoid combination of Student and School Id's or Names respectively depending upon the requirement.
Hope it helps :)
All Answers
I beleive you are using a vf page here to add multiple students to a School.
this can be handled in your save method, where you are inserting the Students record.
Before inserting a record, just check whether it exists in database or not, if not then create it, else display an appropriate page message
and the other way of avoiding it is using triggers,
I'm still in confusion about - you want to avoid it using trigger or you want to handle in vf page.
This trigger avoids Insertion of Account with duplicate name.
You have to develop something similar.
You would have to avoid combination of Student and School Id's or Names respectively depending upon the requirement.
Hope it helps :)
hi i am solve this problem using trigger. my master object is StudentName__c and my child object is CollegeName__C. When the user select the one student name morethan once from CllogeName__C Object it will throws an error.
Trigger Deduplicate on CollegeName__c (before insert,before update)
{
list<CollegeName__c>list1=new list<CollegeName__c>();
set<id>set1=new set<id>();
for(CollegeName__c c:trigger.new)
{
list1.add(c);
set1.add(c.Student_Name__c);
}
List<CollegeName__c> cc = [select Student_Name__c from CollegeName__c where Student_Name__c=:set1];
for(CollegeName__c c1:trigger.new)
{
if(cc.size()>0)
{
c1.addError('already exsits');
}
}