I am having a hard time to run my test class for my trigger WHERE my trigger updates the Contacts Mailing to Accounts Biliing Address whenever the Accounts Billing Address is updated. This is my Trigger
trigger UpdateContactBillingAddress on Account (after update) {
Set accountId = new Set();
List contactsToUpdate = new List();
for(Account acc: Trigger.new){
// Please perform a check to see if address was updated
accountId.add(acc.Id); //accounts that were updated.
}
for(Contact c : [Select Id, MailingCity, MailingStreet, MailingCountry,
Account.BillingCity, Account.BillingStreet, Account.BillingCountry
from Contact where Account.Id in: accountId]){
c.MailingCity = c.Account.BillingCity;
///same for rest of the fields
contactsToUpdate.add(c);
}
update contactsToUpdate;
}
It works fine.But my test class is giving me errors: Compile Error: Initial term of field expression must be a concrete SObject: List at line 24 column 41
My Test Class
@isTest
public class UpdateContactBillingAddress_Test{
static testMethod void testupdates() {
// Let’s create our records from scratch!
Account a= new Account();
a.Name=’TestAccount';
a.BillingStreet=’hjasadhj';
insert a;
//update Account
a.billingState=’My City';
update a;
// Verify that the billingState field was updated in the database.
Account updatedAccount = [SELECT billingState FROM Account WHERE Id = :a.Id];
System.assertEquals(‘My City’, updatedAccount.billingState);
//Create record for new contact
Contact c=new Contact();
c.FirstName=’hina';
c.LastName=’meena';
List contact = [SELECT Id, MailingStreet,MailingCity FROM Contact WHERE AccountId = :a.Id];
System.assertEquals(‘hjasadhj’, contact.MailingCity);
}
}
Can anyone help me find the error/debug it. Thanks