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

Updating an Account from within trigger
I am trying to merge accounts that are being upserted from a dataload. However, when the account is matched, and I subsequently try to update the parent record, the parent is not actually being updated in salesforce. No unexpected errors are occuring.
(The Trigger is in fact also being triggered for the record in the mergedAccounts list...yet it does not appear to save). What am I missing?
(The Trigger is in fact also being triggered for the record in the mergedAccounts list...yet it does not appear to save). What am I missing?
//Parents are any accounts that exist in Salesforce that were not imported from UFOS List<Account> parents = [SELECT Id,Name,Sales_Rep__c,Active__c,BillingCity,BillingCountry,BillingPostalCode,BillingState,BillingStreet,Comments__c,Email__c, Fax,InternalNotes__c,Phone,RecordTypeId,Sales_Rep_Initials__c,ShippingCity,ShippingCountry,ShippingPostalCode,ShippingState,ShippingStreet, Sols_Planner__c,Toll_Free__c,UFOS_Account_Type__c,UFOS_Contact1_Ext__c,UFOS_Contact1_Phone__c,UFOS_Contact2_Ext__c,UFOS_Contact2_Phone__c, UFOS_ID__c, Type FROM Account WHERE UFOS_ID__c = '']; List<Account> mergedAccounts = new List<Account>(); for (Account a : Trigger.new) { //see if this account has a match in the parents list. for(Account p : parents) { if(p.Name.getLevenshteinDistance(a.Name) <= 2) { System.Debug('Parent---->' + p.Name + ' | ' + p.Id + ' | ' + p.Type); System.Debug('Account--->' + a.Name + ' | ' + a.Id + ' | ' + a.Type); if(a.Type == 'UFOS Customer') { //Join this account to the parent.... p.Sales_Rep__c = a.Sales_Rep__c; p.Active__c = a.Active__c; p.BillingCity = a.BillingCity; p.BillingCountry = a.BillingCountry; p.BillingPostalCode = a.BillingPostalCode; p.BillingState = a.BillingState; p.BillingStreet = a.BillingStreet; p.Comments__c = a.Comments__c; p.Email__c = a.Email__c; p.Fax = a.Fax; p.InternalNotes__c = a.InternalNotes__c; p.Name = a.Name; p.Phone = a.Phone; p.RecordTypeId = a.RecordTypeId; p.Sales_Rep_Initials__c = a.Sales_Rep_Initials__c; p.ShippingCity = a.ShippingCity; p.ShippingCountry = a.ShippingCountry; p.ShippingPostalCode = a.ShippingPostalCode; p.ShippingState = a.ShippingState; p.ShippingStreet = a.ShippingStreet; p.Sols_Planner__c = a.Sols_Planner__c; p.Solution_Planner__c = a.Solution_Planner__c; p.Toll_Free__c = a.Toll_Free__c; p.UFOS_Account_Type__c = a.UFOS_Account_Type__c; p.UFOS_Contact1_Ext__c = a.UFOS_Contact1_Ext__c; p.UFOS_Contact1_Phone__c = a.UFOS_Contact1_Phone__c; p.UFOS_Contact2_Ext__c = a.UFOS_Contact2_Ext__c; p.UFOS_Contact2_Phone__c = a.UFOS_Contact2_Phone__c; p.UFOS_ID__c = a.UFOS_ID__c; mergedAccounts.add(p); System.debug('mergedAccounts.size = ' + mergedAccounts.size()); a.addError('Customer merged with Salesforce account: ' + p.Id); } else //match all Accounts that are not a UFOs Customer to { //Do not want to create a circular dependency if(a.Id != p.Id) { a.ParentId = p.Id; } } } } } System.debug('final mergedAccounts.size = ' + mergedAccounts.size()); if(!mergedAccounts.isEmpty()) { System.debug('Merging accounts: ' + mergedAccounts); update mergedAccounts; }
Also, please post the entire trigger.