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
Pranathi AnukuriPranathi Anukuri 

in account of all records when the description field is empty,the empty field should filled with given data using trigger

In account List of all records, when the description field is empty, the empty field should filled with given data(This is my new Description)using trigger
Khan AnasKhan Anas (Salesforce Developers) 
Hi Pranathi,

Greetings to you!

Please try the below code, I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
 
trigger UpdateDescriptionAcc on Account (before insert, before update) {
    
    for(Account a : trigger.new){
        if(a.Description==null || a.Description==''){
            a.Description = 'This is my new Description';
        }
    }
}

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Pranathi AnukuriPranathi Anukuri
i am asking the question that in my account object list of old records where the description is null the given data should place there
Khan AnasKhan Anas (Salesforce Developers) 
Hi Pranathi,

You don't need a trigger for that. Because a trigger is Apex code that executes before or after the following types of operations:
insert, update, delete, merge, upsert, undelete

You can mass update records by executing below code in anonymous window. 
Developer Console -> Debug -> Open Execute Anonymous Window
List<Account> AllRecords = new List<Account>();
for(Account acc: [select id, Name, Description from Account]){
    if(acc.Description==null || acc.Description==''){
        acc.Description='This is my new Description';
        AllRecords.add(acc);
    }
}
update AllRecords;

I hope it helps you.

Kindly mark this as solved if the information was helpful. It will help to keep this community clean.

Thanks and Regards,
Khan Anas