function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Abhishek_NewAbhishek_New 

Initial term of field expression must be a concrete SObject: LIST<Account> at line 20 column 8

 
trigger UpdateContactNo on Contact (after insert) { list<Account> acc = new list<Account>();        
for(Contact c:trigger.new)
{ 
  list<Account> ac =[select id,No_of_Contacts__c from Account where id =: c.AccountId]; 
    for(Account a : ac)
           {
               if (a.No_of_Contacts__c != null){   
             a.No_of_Contacts__c = a.No_of_Contacts__c+1;
                    acc.add(a); 
              }
             else{
                a.No_of_Contacts__c = 1;
                    acc.add(a); 
              }
       } 
}
try
{
   if(!acc.isEmpty)
    update acc;
}
catch(Exception e)
{
e.getMessage();
}

}
Error is coming in if (a.No_of_Contacts__c != null)line...
Best Answer chosen by Admin (Salesforce Developers) 
Gunners_23Gunners_23

At line 3 where you're doing query change it to

 

List<Account> ac = new List<Account>();

 

ac = [QUERY];

 

and in try block you're not calling empty function. Change it to as mentioned below

 

try
{
         if(!acc.isEmpty())
           update acc;
}

 

All Answers

Gunners_23Gunners_23

At line 3 where you're doing query change it to

 

List<Account> ac = new List<Account>();

 

ac = [QUERY];

 

and in try block you're not calling empty function. Change it to as mentioned below

 

try
{
         if(!acc.isEmpty())
           update acc;
}

 

This was selected as the best answer
Abhishek_NewAbhishek_New

It Worked..Thanks...