Open njjc opened 12 years ago
I believe this should work:
trigger PaymentProcessor_PreventMultipleDefaults on gwop__Payment_Processor__c (before insert, before update) {
//first query to see if there is a default processor
Payment_Processor__c[] processors = [SELECT id FROM Payment_Processor__c WHERE Default_Connection__c = true];
if (!processors.isEmpty()) {
for (Payment_Processor__c p : trigger.new) {
if (p.Default_Connection__c && (trigger.isInsert || p.id!=processors[0].id)) {
p.addError('You have already selected a Payment Processor as the Default Processor. Please uncheck this option to save this record.');
}
}
}
}
PaymentProcessor_PreventMultipleDefaults.trigger doesn't allow editing the current default record; trying to save after an edit throws "Error:You have already selected a Payment Processor as the Default Processor. Please uncheck this option to save this record."