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

Help with error "Variable does not exist: Id" when trying to default an Account on Contact
I'm writing a trigger to default the Account of a Contact each time a Contact is created. The trigger is relatively simple. I'm receiving an error that reads: Variable does not exist: Id. Can anyone point me in the direction of what I'm doing wrong?
trigger setDefaultAcc on Contact (before insert){ List<Contact> lstCon = new List<Contact>(); // Find out and prepare list of Contacts for(Contact var : Trigger.new){ if(var.AccountId == null){ lstCon.add(var); } } // Fetch the Default account if(lstCon.size()>0){ List<Account> acc = new List<Account>(); acc = [SELECT Id, Name FROM Account WHERE Name = 'Strategic Market Advisors' LIMIT 1]; if(acc != null){ for(Contact var : lstCon){ // Assign the id of the default account to the selected contacts var.AccountId = acc.Id; } } } }
When you try to access the record which is in list, you need to identify the Index for it though..
Hope this helps & Mark it Solved if it solves the query!
All Answers
When you try to access the record which is in list, you need to identify the Index for it though..
Hope this helps & Mark it Solved if it solves the query!
if(acc != null){
for(Contact var : lstCon){
var.AccountId = acc[0].Id;
}
}