Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PaymentProcessor_PreventMultipleDefaults.trigger not functional #9

Open
njjc opened this issue Jul 23, 2012 · 1 comment
Open

PaymentProcessor_PreventMultipleDefaults.trigger not functional #9

njjc opened this issue Jul 23, 2012 · 1 comment

Comments

@njjc
Copy link

njjc commented Jul 23, 2012

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."

@njjc
Copy link
Author

njjc commented Jul 23, 2012

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.');
            }
        }
    }

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant