You need to sign in to do that
Don't have an account?
Gdickens3
Display Account Owner on Case
I have modified a code for inserting the account owner on an opportunity record to show the same on a case object, but getting error: Compile Error: Incompatible element type Schema.SObjectField for collection of Id at line 4 column 36
I am new to apex and have only successfully modified current triggers when fields change, any help is appreciated.
trigger trgAccOwner on Case (before insert,before update) { Set<Id> acctIDs = new Set<Id>(); for(Case tl:Trigger.new) { if(case.AccountId != null) acctIDs.add(case.AccountId); } Map<Id, Account> acctMap = new Map<Id, Account>([select Owner.Name from Account where Id in :acctIDs]); for(Case tl: Trigger.new) { if(case.AccountId != null) case.Account_Owner__c = acctMap.get(Case.AccountId).Owner.Name; } }
I've made the appropriate changes on your trigger. You can see the difference in what is marked in red. On your loop, you are calling each record within your Trigger.new collection as 'tl'. Due to this, you must refer to your record instance as 'tl' while inside your loop.
All Answers
I've made the appropriate changes on your trigger. You can see the difference in what is marked in red. On your loop, you are calling each record within your Trigger.new collection as 'tl'. Due to this, you must refer to your record instance as 'tl' while inside your loop.
Thank you!