You need to sign in to do that
Don't have an account?
SFAdmin5
Account lookup field not populating from Trigger
I've got a trigger that inserts a new sObject record on a custom object when another custom object is created. It works but the only thing that does not work is populating the Account lookup field. Here's the code. The problem has got to be around the line "newAN.Account__c = insertedCSBI.Account__c;"
I know this is an Id field. Not sure if I need to be dealing with apex map or set or both here. All I know is that this trigger creates a new record successfully, but that new record is not associating the new record to an Account.
Any ideas?
trigger CustomServicesBillingInvoice on Custom_Services_Billing_Invoice__c (after insert, before update, after update) { ///Account Note Insert for new Billing Records if (Trigger.isInsert && Trigger.isAfter) { //Declare a new List of type Account_Note__c. Name of List is newANlist List<Account_Note__c> newANlist = new List<Account_Note__c>(); //Loop over all of the Custom_Services_Billing_Invoice__c values in Trigger.new for(Custom_Services_Billing_Invoice__c insertedCSBI:Trigger.new){ //Declare a new Account_Note__c and name it newAN Account_Note__c newAN = new Account_Note__c(); //Assign the Custom_Services_Billing_Invoice__c record's values to the fields on the newAN record newAN.Account__c = insertedCSBI.Account__c; newAN.Note__c = insertedCSBI.Billing_Notes__c; newAN.Note_Function__c = 'Finance'; newAN.Note_Status__c = 'Resolved'; //Add newAN to newANlist for any insertedCSBI records that have some text in the Billing_Notes__c field. //Exclude CSBI records that are null for this field if(insertedCSBI.Billing_Notes__c !=null){ newANlist.add(newAN); } } //Insert newANlist Database.insert(newANlist); } }
I would put some System.Debug statements in there to see what the values are coming across as through the Trigger. Weird things can sometimes happen.
Thanks. That is a good idea. Unfortunately I couldn't figure that out.
However I did get this trigger working perfectly on my own. It passes 100% test coverage.
Thought I'd post the final working code so others can benefit
FYI solution is to create a cross object formula field called "Accountlookup__c" that is simply this
Opportunity__r.Account.Id
In my case this field is on the custom object called "Custom_Services_Billing_Invoice__c"