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
Hari N 20Hari N 20 

Apex trigger after update

Hi All,
I have written a trigger on Account.
I am storing mutiple phone number values in phone number field and I am splitting those values into three different fields.
It is working fine. If I update any phone number in phone field, I want to see the same change in those fields. This updation is not working.

Please suggest me the changes

This is the code I have written.

trigger AccountPhoneTrigger on Account (before insert) {
 List<String> descriptionValues;
 List<Id> accountIds = new List<Id>(); 
        for(Account acc: Trigger.New){
        if(!String.isBlank(acc.Phone)){
           descriptionValues = acc.Phone.split(',');
            
           for(Integer count = 0; count < descriptionValues.size(); count ++){
                    acc.Pho1__c = descriptionValues[0].trim();
                       acc.Pho2__c = descriptionValues[1].trim();
                       acc.Pho3__c = descriptionValues[2].trim();
                        
           }
        }
            
   
    }
}
Best Answer chosen by Hari N 20
Dilip_VDilip_V
Hari,

Your code looks perfect but you havn't add after update event in your trigger.

Thats y its not working.
Try this code
trigger AccountPhoneTrigger on Account (before insert,before update) {
 List<String> descriptionValues;
 List<Id> accountIds = new List<Id>(); 
        for(Account acc: Trigger.New){
        if(!String.isBlank(acc.Phone)){
           descriptionValues = acc.Phone.split(',');
            
           for(Integer count = 0; count < descriptionValues.size(); count ++){
                    acc.Pho1__c = descriptionValues[0].trim();
                       acc.Pho2__c = descriptionValues[1].trim();
                       acc.Pho3__c = descriptionValues[2].trim();
                        
           }
        }
            
   
    }
}

Let me know if you have any issues.

Mark it as best answer if it works.
Thanks.

All Answers

sfdcMonkey.comsfdcMonkey.com
try this onces
trigger AccountPhoneTrigger on Account (before insert,before update) {
 List<String> descriptionValues;
 List<Id> accountIds = new List<Id>(); 
        for(Account acc: Trigger.New){
        if(!String.isBlank(acc.Phone)){
           descriptionValues = acc.Phone.split(',');
            
           for(Integer count = 0; count < descriptionValues.size(); count ++){
                    acc.Pho1__c = descriptionValues[0].trim();
                       acc.Pho2__c = descriptionValues[1].trim();
                       acc.Pho3__c = descriptionValues[2].trim();
                        
           }
        }
thanks
mark it best answer if it helps you

 
Dilip_VDilip_V
Hari,

Your code looks perfect but you havn't add after update event in your trigger.

Thats y its not working.
Try this code
trigger AccountPhoneTrigger on Account (before insert,before update) {
 List<String> descriptionValues;
 List<Id> accountIds = new List<Id>(); 
        for(Account acc: Trigger.New){
        if(!String.isBlank(acc.Phone)){
           descriptionValues = acc.Phone.split(',');
            
           for(Integer count = 0; count < descriptionValues.size(); count ++){
                    acc.Pho1__c = descriptionValues[0].trim();
                       acc.Pho2__c = descriptionValues[1].trim();
                       acc.Pho3__c = descriptionValues[2].trim();
                        
           }
        }
            
   
    }
}

Let me know if you have any issues.

Mark it as best answer if it works.
Thanks.
This was selected as the best answer