+ Start a Discussion
Leonard CadetLeonard Cadet 

append text with apex

In Apex, how do a append text to an existing field? 
Best Answer chosen by Leonard Cadet
SEKAR RAJ.SEKAR RAJ.
Hi Leonard,
Here is the solution for the appending text with existing values.
String toAppend = 'Append with existing value';
account a =[SELECT name FROM account LIMIT 1];
a.name += toAppend;
update a;

THANKS,
SEKAR RAJ

All Answers

SEKAR RAJ.SEKAR RAJ.
Hi Leonard,
Here is the solution for the appending text with existing values.
String toAppend = 'Append with existing value';
account a =[SELECT name FROM account LIMIT 1];
a.name += toAppend;
update a;

THANKS,
SEKAR RAJ
This was selected as the best answer
Leonard CadetLeonard Cadet
This shoudl work great. Thanks Sekar.

For the string Varible 'toAppend' this could also be equal to a salesforce field correct?

so:

String toAppend = b.name
Deepali KulshresthaDeepali Kulshrestha
Hi Leonard,

I have gone through your question. To append the text with the field value of any record.
Please try the code given below:-

Example:-

Account acc = [Select Name form Account Limit 1];
acc.name = acc.Name + 'Any Text';
update acc ;
 
Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com