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
ajay ambatiajay ambati 

problm with after trigger

iam account and contact in account object iam having phonenumber=9999999999 and i need to update all contact mobilephone feild which are accosiated particular account i done with follwing code no error bt trigger not firing pls hlp....
trigger accountupdatetrigger on account (after update) {



    if(trigger.isafter)
    {
        if(trigger.isupdate)
        {
   list<contact> lst = new list<contact>();
            
    
  list <Account> a = [Select id,Name,phone, (Select id, Contact.FirstName,contact.LastName,contact.MobilePhone from Account.Contacts) From Account where phone ='99999999999'];
       
            
            for(Account acc1:a)
               {
                   
                 for(schema.Contact cn:acc1.Contacts)
                     
                       {
                         //  lst.add(cn);
                      // }
                           
                          // if(cn.MobilePhone!=null && cn.MobilePhone==null)
                          // {
                           cn.MobilePhone ='99999999999';
                          update cn;
                           
                           }            
                           
       }
    }
              
}
       

    }
Amit Chaudhary 8Amit Chaudhary 8
Note your trigger will execute only once you will edit your record.

I see you are trying to update fixed set of Account if yes then please create Apex Batch job for same
1) http://amitsalesforce.blogspot.in/2016/02/batch-apex-in-salesforce-test-class-for.html

If found below issue in your Trigger
1) You are try to update fixed set of acoount record i will recomend you to try Batch job.
2) DML inside For loop
trigger accountupdatetrigger on account (after update) 
{
    if(trigger.isafter)
    {
        if(trigger.isupdate)
        {
			list<contact> lst = new list<contact>();
			list <Account> a = [Select id,Name,phone, (Select id, Contact.FirstName,contact.LastName,contact.MobilePhone from Account.Contacts) From Account where phone ='99999999999'];
            
            for(Account acc1:a)
            {
				for(schema.Contact cn:acc1.Contacts)
				{
				   cn.MobilePhone ='99999999999';
				   lst.add(cn);
				}            
			}
			if(lst.size() > 0)
			{
				update lst;
			}
        }
    }
}
Let us know if this will help you
 
ajay ambatiajay ambati
when you updating we must pass id but above code not passing id how it is possible?