+ Start a Discussion
Internal PartnerInternal Partner 

Use of custom setting and custom fields type textarea with 255 characters is limited: How to concatenate two fields in APEX Code?

Hi all,

as some of you might know, custom fields for custom settings, with type Textarea, are limited to only 255 characters. I had read there is a workaround and this you can create a second field with the same length and create a record concatenating both, ok.
Our problem is, how can we change our code so the second field is taken in account and when sending the email, the value in the second field also will be displayed:

This is the code:
global class implements Schedulable {  
    
   global void execute(SchedulableContext SC) {
      sendEmail();
   }
    
    
    global void sendEmail(){

        Messaging.reserveSingleEmailCapacity(2);
        
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        
        // Strings to hold the email addresses to which you are sending the email.
        Email_Reminder__c er = Email_Reminder__c.getInstance('Reminder');
        String [] toEmailAddress = new String [] {er.ToEmailAddress__c};
        String Subject= er.Subject__c;
        String Body= er.Body__c ;
        String Body2= er.Body2__c; // I added the custom field Body2 in the Custom Setting
        String Owa_Label= er.OWA_Label__c;
       
        
     
        
        mail.setToAddresses(toEmailAddress);
        
        // Use Organization Wide Address  
        for(OrgWideEmailAddress owa : [select id, Address, Displayname from OrgWideEmailAddress]) {
            if(owa.DisplayName.contains(Owa_Label)) {
                 mail.setOrgWideEmailAddressId(owa.id); 
            }
              
        } 
           
        // Specify the subject line for your email address.
        mail.setSubject(Subject);
        
        // Set to True if you want to BCC yourself on the email.
        mail.setBccSender(false);
        
        // Optionally append the salesforce.com email signature to the email.
        // The email address of the user executing the Apex Code will be used.
        mail.setUseSignature(false);
        
        // Specify the text content of the email.
        //mail.setPlainTextBody('Please configure this');
        
        mail.setHtmlBody(Body);
        
        // Send the email you have created.
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }
}

Custom Setting with fields:

Body__c --> Textarea (255)
Body2__c --> Textarea(255)
OWA Label --> Text(100)
Subject__c --> Text(250)
ToEmailAddress__c --> Email

Value in Body__c:
 
This is a first test. This should work with two fields. The idea is first to display the value in Body__c and Body2__c as the content were the content in only one field.
Value in Body2__c:
 
This is an example of content in Body2__c. Questions is how can I concatenate Body__c and Body2__c?

If I get an Email, I would like to get the following content in this form:

This is a first test. This should work with two fields. The idea is first to display the value in Body__c and Body2__c as the content were the content in only one field.
This is an example of content in Body2__c. Questions is how can I concatenate Body__c and Body2__c?


How can I change my code so I get this result in the email. We are not yet using an email template.

Second question is, if we use an email template instead, how can we change the code above?



 
NagendraNagendra (Salesforce Developers) 
Hi,

Sorry for this issue you are facing.

May I suggest you please refer to below link from the stack exchange community with a similar discussion which might help you further. Please let us know if this helps.

Kindly mark this as solved if the reply was helpful.

Thanks,
Nagendra
Internal PartnerInternal Partner
Hi Nagendra, thanks for responding. Do ypu mean "Text Area (long) is supported in Custom metadata types", so using custom metadata types?. Do custom metadata types can be used in apex code?