You need to sign in to do that
Don't have an account?
Apex trigger help needed
Hi,
I need help on the following req
1) I am having a custom field called as "Dealer Principal__c" in my custom object called as "Account Exceptions__c"
2) There is a lookup on my custom object called as Account__c which is a lookup to the account object
My req is i want to populate my custom field "Dealer Principal__c" on Account exception__c custom object with the contact first name and last name of the contact related to the account that i select if the contact title is set as "Dealer Principal"
if the account record type is group account , the child accounts contact is set which is having
contact title as "Dealer Principal"
Help me with the requirement please
Thanks in Advance
All Answers
Error: Compile Error: unexpected token: '{' at line 19 column 47
trigger updateaccountexceptions on AccountExceptions__c (after insert, after update){
map<id,string> dealercontacts= new map<id,string>();
set<id> accids=new set<id>();
for(AccountExceptions__c acex:trigger.new){
accids.add(acex.Account__c);
}
List<contact> cons=new List<contact>([select accountid,firstname,lastname from contact where title='Dealer Principal' and accountid=:accids]);
for(Contact con:cons){
string conname=con.firstname+' '+con.lastname;
dealercontacts.put(con.accountid,conname);
}
list<AccountExceptions__c> acexlisttoupdate =new list<AccountExceptions__c>();
for(AccountExceptions__c acex:trigger.new){
if(dealdercontacts.containskey(acex.Account__c){
acex.Dealer_Principal_s__c=dealdercontacts.get(acex.Account__c);
acexlisttoupdate.add(acex);
}
}
update acexlisttoupdate;
}
when i enter the values on click on save i m getting the following error,
Apex trigger AF_updateaccountexceptions caused an unexpected exception, contact your administrator: AF_updateaccountexceptions: execution of AfterInsert caused by: System.FinalException: Record is read-only: Trigger.AF_updateaccountexceptions: line 20, column 1
acex.Dealer_Principal_s__c=dealercontacts.get(acex.Account__c);