You need to sign in to do that
Don't have an account?
Kunal 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)
{
}
}
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)
{
}
}
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
Are you referring to person accounts?
If yes then you can do the following in your execute method
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)
{
}
}