You need to sign in to do that
Don't have an account?
apsullivan
Creating my first test class for a simple trigger
I've written a pretty simple trigger and I was hoping to get a hand with a test class.
All my trigger does is stamp the account with the same user lookup value from an opportunity (CF Manager -> Account CF Owner fields). I'm brand new to Apex so help is always appreciated. The trigger fires without issue.
Here's the trigger:
trigger OnAccountOpportunityCFManager on Opportunity (before insert, before update) { List<Id> AccountsToUpdate = new List<Id>{}; // Find account to update for(Opportunity o: Trigger.new){ if (o.CF_Manager__c != Null && o.AccountId != Null) { AccountsToUpdate.add(o.AccountId); } // Pull field data from account List<Account> accts = new List<Account>([SELECT Id, Account_CF_Owner__c FROM Account WHERE Id IN :AccountsToUpdate]); // Update account for(Account a: accts) { a.Account_CF_Owner__c = o.CF_Manager__c; update a; } } }
Thanks!
Hi Sullivan
Try below code :-
All Answers
Hi Sullivan
Try below code :-
Thanks so much! This is exactly the start I needed. With the required fields added, this gave my trigger 100% coverage. One small note for anyone else that may find this helpful: the field name for Stage is StageName.
Again, though, thanks!
Happy to help Sullivanand I forgot to put the API name of the field Stage.