You need to sign in to do that
Don't have an account?

Apex Account Trigger Error need help!
We set up a new account trigger in salesforce today for our parature integration and received this error on the opportunity record changing a record type and then pressing save this error appeared.
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger UpdateContact caused an unexpected exception, contact your administrator: UpdateContact: execution of AfterUpdate caused by: System.Exception: Too many DML rows: 112: Trigger.UpdateContact: line 11, column 13".
Click here to return to the previous page.
Account apex trigger
Body | Download Apextrigger UpdateContact on Account (after insert, after update) { for (Account account : Trigger.new) { List<Contact> contacts = new List<Contact>(); contacts = [SELECT Id FROM Contact WHERE AccountId = :account.ID]; for(Contact c: contacts) { update contacts; } } } |
How can we fix this? Also strange happening on changing opportunity record type and saving.
This Parature/SFDC integration we were working on only picked up records that have been modified, so changing the Account record won’t trigger the integration to update the related Contacts by default (since nothing was changed on the Contact record) which we wanted to occur. So this trigger will do a “save” operation on all related Contacts making it look like the record was “modified” but not actually change any data.
This creates a trigger that occurs when an account is saved that will “update” all associated customers without actually making any changes.
For example changing one role to another in a contact record.
What is strange this seems to happen on one particular account on the opportunity record adding any products as well that's why we cant change the record type? I set up another opportunity with same product and record type and was fine, but for this account in particular we noticed some contacts were being updated during the integration not sure if that triggered it. We turned off the integration around 2:30pm, but still cannot change this particular opportunity record type due to the product for some reason?
I see a couple of problems with the trigger. 1) Within the second For Loop, you are updating contacts instead of c. 2) When you have a DML statement within a For Loop, the best practice within Salesforce is to use a List Variable. you are probably hitting a governor limit. Try this code below:
trigger UpdateContact on Account (after insert, after update) { for (Account account : Trigger.new) { for(List<Contact> contacts:[SELECT Id FROM Contact WHERE AccountId = :account.ID]) { update contacts; } } }
Here's another version that might be even better:
trigger UpdateContact on Account (after insert, after update) { List<Account> accounts = Trigger.new; for(List<Contact> contacts:[SELECT Id FROM Contact WHERE AccountId in :accounts]) { update contacts; } }
We are receiving messages from our SF users saying that no one can add products? Can you please tell us how this trigger would be affect products?
THanks!
Hi John, I am very new to triggers and am trying to modify the code you provided below. I need to change the "Contact Status" to "Inactive" (custom field on the Contact record) for all Accounts that have an "Account Status" of "Inactive" (custom field on the Account record).
Is this easily done? Any help would be appreciated! Thank you!!!