+ Start a Discussion
Shubham SengarShubham Sengar 

prefix by tigger

mr prefix by tigger when new account name inserted ..??
 
Best Answer chosen by Shubham Sengar
ManojjenaManojjena
Hi Subham ,

Try with below code it will help !!
trigger PrefixBeforeName on Account (before insert) {
    for(Account acc :Trigger.new){
      acc.Name='Mr.'+acc.Name;
    }
}


 

All Answers

Keyur  ModiKeyur Modi
Hi,
You can achieve this functionality through workflow
where you can set Rule Criteria:Account: Account Name not equal to null
Evaluation CriteriaEvaluate the rule when a record is created
// as you want this at time of insertion only

then  you can add imediate action Field update
where you can update Account name with this formula
'Mr.'+ Name

it will work while you create new record.

please let me know if this will help,

Thanks,
Keyur Modi


 
Shubham SengarShubham Sengar
ya m tring that code ...but gives some error ...can u plz send me complite code
 
Keyur  ModiKeyur Modi
Hi ,
can you mention , in which step you are getting error and what error it is ??

Thanks,
Keyur Modi
Shubham SengarShubham Sengar
my code is ==> trigger Mr on Account  (before insert)  { list prefixName = new list();  List a1=[Select Name from Account where Account.name=:trigger.new[0].name];  }
Shubham SengarShubham Sengar
can u send me code ...because m facing to much error ...Question >> write a trigger to prefix account name with Mr whenever record is inserted ..?? 
ManojjenaManojjena
Hi Subham ,

Try with below code it will help !!
trigger PrefixBeforeName on Account (before insert) {
    for(Account acc :Trigger.new){
      acc.Name='Mr.'+acc.Name;
    }
}


 
This was selected as the best answer
Shubham SengarShubham Sengar
thanks Manoj bro its working ...
Dheeraj P 7Dheeraj P 7
Hi Manoj can you write the code update prefix.