You need to sign in to do that
Don't have an account?

hi , i am writng a trigger to make the letter in every word in account name to be upper case. here is the trigger and apex class i have used. its working but the code is adding parenthesis every time i insert or update
trigger accountnameuppercase on account (before insert,before Update) {
List<account> acclist = trigger.new;
nameupper.makeuppercase(acclist);
}
apex class:::
public class accnameuppercase{
public static void makeuppercase(List<account> acclist){
for(account a : acclist){
String rep_name =a.name;
List<String> elems = rep_name.split('');
rep_name = '';
for (String x : elems)
{
rep_name += x.substring(0,1).toUpperCase()+x.substring(1,x.length() ) + ' ';
}
a.name=rep_name;
}
}
}
List<account> acclist = trigger.new;
nameupper.makeuppercase(acclist);
}
apex class:::
public class accnameuppercase{
public static void makeuppercase(List<account> acclist){
for(account a : acclist){
String rep_name =a.name;
List<String> elems = rep_name.split('');
rep_name = '';
for (String x : elems)
{
rep_name += x.substring(0,1).toUpperCase()+x.substring(1,x.length() ) + ' ';
}
a.name=rep_name;
}
}
}
I copied your code and tried it but caused an error,
so I'm not sure the exact reason why it adds parenthesis.
(You are missing a blank space in "rep_name.split('');" ?)
Anyway, this code works, does it make sense?
Use following code to solve your problem. For some reason your code is not working. I am not able to debug it .
Regards,
Santosh
just add a if statement
apex class:::
public class accnameuppercase{
public static void makeuppercase(List<account> acclist,Map<Id,Account> oldMap){
for(account a : acclist){
//if a. name is not capitalize, then dosomething, else do nothing
}
You can use the following code.
Thanks,
Devendra
What worked for you? I need to know if any of the above suggested answers worked for you... please do let me know!!
Shingo Yamazaki / Santosh Chitalkar : Do your codes work when you tested them in your Org?
Im trying to use one of them :p
Thanks
#RaggyRao