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
manoj6492manoj6492 

bulk trigger for updating

trigger AccountReplicate on Account (after delete, after insert, after update) {

if(trigger.isInsert)
{
for (Account acc:trigger.new)
{
    AccountOne__c ac = new AccountOne__c();
    ac.Fax__c = acc.Fax;
    ac.Phone__c = acc.Phone;
    ac.Name =acc.Name;
    insert ac;
}
	
}

if(trigger.isUpdate)

{
	
		
		integer i=0;
	list<AccountOne__c> a2 = new list<AccountOne__c>([Select Id from AccountOne__c where Name =: trigger.old[i].Name ]);
	
	for(AccountOne__c c1 : a2)
	{	
	
		
		c1.Name=trigger.new[i].name;
		c1.Fax__C =trigger.new[i].Fax;
		c1.Phone__C=trigger.new[i].Phone;
		i++;
		
		
	}
		update a2;
		
}
if(trigger.isDelete)
{
	AccountOne__c a3 = [Select Id from AccountOne__c where Name =: trigger.old[0].Name ];		
	
	
		delete a3;
}
}

 the above trigger handles only single record but i need to handle it for bulk records...can anyone help me

Avidev9Avidev9
The data models doesnt seems good.
Since you are creating one AccountOne__c per account, why arent making AccountOne__c child of standard account ?

This way it will be really easy to handle the sync. Infact you can create formula fields in chaild for Fax,Phone etc that will automatically reflect values from Account
manoj6492manoj6492

I have been given task to do by this way

Avidev9Avidev9
I dont think this the best way and you are unnecessarily increasing the complexity of the system.