• madhu sannapa
  • NEWBIE
  • 30 Points
  • Member since 2016

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
When I am execute this Trigger I am getting an error at line Query Illegal assignment from LIST<Account> to LIST<Account> at line in Salesforce Trigger


trigger ContactsOnAccount on Contact (after insert, after delete) {
    Set<Id> aId = new Set<Id>();
   
    if(Trigger.isInsert){
        for(Contact opp : Trigger.New){
            aId.add(opp.AccountId);
        }
        List<Account> acc = [select id,Count_id__c from Account where Id in:aId];
        List<Contact> con = [select id from contact where AccountId in :aId];
       
        for(Account a : acc){
            a.Count_id__c=con.size();
           
        }update acc;
    }
   
    if(Trigger.isDelete){
        for(Contact opp : Trigger.old){
            aId.add(opp.AccountId);
        }
        List<Account> acc = [select id,Count_id__c from Account where Id in:aId];
        List<Contact> con = [select id from contact where AccountId in :aId];
       
        for(Account a : acc){
            a.Count_id__c=con.size();
           
        }update acc;
    }
 
}
  
   
       
trigger C1 on Contact (after insert,after delete) {
    decimal x;
  If (trigger.IsInsert==true){
   
for(contact c:trigger.new){
    If(c.Account!=null){
         Account a =new account();
         a=[select   Number_of_contact__c from account where account.name=:c.account.name];
         if(a.Number_of_contact__c==null){
         a.Number_of_contact__c=0;}
         x=a.Number_of_contact__c ; 
         x=x+1;
         a.Number_of_contact__c=x;
         update a;
         
           }
        }
     }   
   }
When I am execute this Trigger I am getting an error at line Query Illegal assignment from LIST<Account> to LIST<Account> at line in Salesforce Trigger


trigger ContactsOnAccount on Contact (after insert, after delete) {
    Set<Id> aId = new Set<Id>();
   
    if(Trigger.isInsert){
        for(Contact opp : Trigger.New){
            aId.add(opp.AccountId);
        }
        List<Account> acc = [select id,Count_id__c from Account where Id in:aId];
        List<Contact> con = [select id from contact where AccountId in :aId];
       
        for(Account a : acc){
            a.Count_id__c=con.size();
           
        }update acc;
    }
   
    if(Trigger.isDelete){
        for(Contact opp : Trigger.old){
            aId.add(opp.AccountId);
        }
        List<Account> acc = [select id,Count_id__c from Account where Id in:aId];
        List<Contact> con = [select id from contact where AccountId in :aId];
       
        for(Account a : acc){
            a.Count_id__c=con.size();
           
        }update acc;
    }
 
}