I'm looking for a trigger to prevent duplicate quote at opportunity, if there is alaredy a quote at opportunity user will not be able to generate new quote in system i.e. only 1 quote per opprotunity.
I try below code but it's not working
trigger DuplicateStudentCheck on Quote(before insert) {
Quote[] studentsList = Trigger.new;
Set oppSet = new Set();
for (Quote s: quoteList) {
oppSet.add(s.Opportunity);
}
List duplicateQuoteList = [Select s.Name, s.Opportunity.Name From Quote where s.Opportunity IN: oppSet];
Set duplicateOpplIds = new Set();
for (Quote s: duplicateQuoteList) {
duplicateOpplIds.add(s.Opportunity.Name);
}
for (Quote s: quoteList) {
if (duplicateOpplIds.contains(s.Opportunity.Name)) {
s.Opportunity.addError('Record already exist');
}
}
}