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
Kunal Purohit 4Kunal Purohit 4 

How to remove prefix 'Mr.' from Account object?

I want to remove prefix 'Mr.' from my Account object. I have tried through the BatchApex class. But still its not working.
public class BatchApex1 implements database.Batchable<Sobject> {
    public database.QueryLocator start(database.BatchableContext Bc)
    {
        string query='select id,name from Account';
        return database.getQueryLocator(query);
    }
    
    public void execute(database.BatchableContext Bc, list<Account> alist)
    {
        for(account a:alist)
        {
           a.name= a.Name.removeStart('Mr.');
        }
        
        update alist;
        system.debug(alist);
    }
     public void finish(database.BatchableContext Bc)
    {
        
    }

}
 
SwethaSwetha (Salesforce Developers) 
HI Kunal,
This is a product limitation. Please consider upvoting below Idea on salesforce Idea exchange so the product team can consider in upcoming releases
https://trailblazer.salesforce.com/ideaView?id=087300000007EwRAAU

Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you
Karan KeharKaran Kehar
Hi Kunal,

Are you referring to person accounts?
If yes then you can do the following in your execute method
a.suffix = '';

 
Kunal Purohit 4Kunal Purohit 4
It's not working.  Moreover, thre is one required field ISSN_Number__c in Account Object. Here is the code again.
public class BatchApex1 implements database.Batchable<Sobject> {
    public database.QueryLocator start(database.BatchableContext Bc)
    {
        string query='select id,name,ISSN_Number__c from Account';
        return database.getQueryLocator(query);
    }
    public void execute(database.BatchableContext Bc, list<Account> alist)
    {
        for(Account a:alist)
        {
            if(a.Name.startsWith('Mr.'))
            {
                
          a.name= a.name.removeStart('Mr.');
              a.ISSN_Number__c= 2;
            }
        }
        update alist;
       
    }
     public void finish(database.BatchableContext Bc)
    {
        
    }

}