You need to sign in to do that
Don't have an account?
Steve Thurston
Convert Long Text Area to String
I am trying to convert the contents of a Long Text Area into a String to include in an HTML Email. The line of code I am using is:
emailHTML = emailHTML.replace('%%Opportunity.Dispatch_Notes__c%%', Opportunity.Dispatch_Notes__c);
emailHTML is the full HTML content of the email. '%%Opportunity.Dispatch_Notes__c%%' is the tag in the HTML that I am trying to replace with the Opportunity's 'Dispatch_Notes__c' field. That field's data type is Long Text Area.
When I try to save the Apex class in IDE, I get the error message on that line:
"Save error: Method does not exist or incorrect signature: [String].replace(String, Schema.SObjectField)"
I have any number of calls to .replace() on that 'emailHTML' string, so the method presumably isn't the problem, which means the signature is. Apparently, it doesn't like replacing contents in a String ('emailHTML') with the contents of a Long Text Area field.
How do you include Long Text Area field content in HTML? Is there some way to cast the Long Text Area type into a String type?
emailHTML = emailHTML.replace('%%Opportunity.Dispatch_Notes__c%%', Opportunity.Dispatch_Notes__c);
emailHTML is the full HTML content of the email. '%%Opportunity.Dispatch_Notes__c%%' is the tag in the HTML that I am trying to replace with the Opportunity's 'Dispatch_Notes__c' field. That field's data type is Long Text Area.
When I try to save the Apex class in IDE, I get the error message on that line:
"Save error: Method does not exist or incorrect signature: [String].replace(String, Schema.SObjectField)"
I have any number of calls to .replace() on that 'emailHTML' string, so the method presumably isn't the problem, which means the signature is. Apparently, it doesn't like replacing contents in a String ('emailHTML') with the contents of a Long Text Area field.
How do you include Long Text Area field content in HTML? Is there some way to cast the Long Text Area type into a String type?
Opportunity oppty = [Select Id,Dispatch_Notes__c from Opportunity where Id='YourOptyId' Limit 1];
emailHTML = emailHTML.replace('%%Opportunity.Dispatch_Notes__c%%', oppty.Dispatch_Notes__c);
Regards,
Pawan Kumar
All Answers
Please try below.
emailHTML = emailHTML.replace('%%Opportunity.Dispatch_Notes__c%%', (String)Opportunity.Dispatch_Notes__c);
Regards,
Pawan Kumar
Now I get the error:
"Save error: Incompatible types since an instance of Schema.SObjectField is never an instance of String"
Please share your full code.
Regards,
Pawan Kumar
Opportunity oppty = [Select Id,Dispatch_Notes__c from Opportunity where Id='YourOptyId' Limit 1];
emailHTML = emailHTML.replace('%%Opportunity.Dispatch_Notes__c%%', oppty.Dispatch_Notes__c);
Regards,
Pawan Kumar
It works fine now. Thanks for your help!