function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SabrentSabrent 

img SRC - correct syntax to append string

I have a text field called Test__c

public myCustomSettings__c myCustomSettings=myCustomSettings__c.getValues('PBA');
String imageid = myCustomSetting.Image_Id__c;

If i do hardcode the file ID , I see the image.

//obj.Test__c = '<img alt="comment" src="/servlet/servlet.FileDownload?file=01580000001YP3k" ></img>';

But ofcourse I don't want to hard code the id, so I did the following which doesn't display the image
pbaComment.Test__c = '<img alt="comment" src="/servlet/servlet.FileDownload?file="+commentimageid>

Can someone tell me what is the correct syntax?

Thanks.
Best Answer chosen by Sabrent
SabrentSabrent
Finally after several trail and erros resolved my issue


*****************   step1: Created a custom setting , added the id of the image to this custom setting ***********************

*****************   step2: Created an instance of the custom setting in my controller to fetch the custom setting data ***********************

*****************   step3: Created a string variable , appended the custom setting field (this field holds the image id) to the File URL **************

***************  step4: Populated the long text area with the image by appending the string created in step 3 above rather than hardcoding the id ***************

myCustomSettings__c myPBA =myCustomSettings__c.getValues('nameundermanage');

String emailimageid = '/servlet/servlet.FileDownload?file=' +myCustomSettings.Email_Image_Id__c;

customobject.Test__c = '<img alt="email" src="' + emailimageid + '"></img>';

All Answers

Raghavendra ARaghavendra A
Hi Rov,

You have to upload the image in Static resources. Then you need to add the following code in your code to <img src="{!$Resource.ImageName}"/> where image name is the Static resource name.

Please try and let me know if you need more help.

Thanks,
Raghu
SabrentSabrent
I tried this doesn't display the image . Note that

obj.Test__c is a text field
SabrentSabrent
Finally after several trail and erros resolved my issue


*****************   step1: Created a custom setting , added the id of the image to this custom setting ***********************

*****************   step2: Created an instance of the custom setting in my controller to fetch the custom setting data ***********************

*****************   step3: Created a string variable , appended the custom setting field (this field holds the image id) to the File URL **************

***************  step4: Populated the long text area with the image by appending the string created in step 3 above rather than hardcoding the id ***************

myCustomSettings__c myPBA =myCustomSettings__c.getValues('nameundermanage');

String emailimageid = '/servlet/servlet.FileDownload?file=' +myCustomSettings.Email_Image_Id__c;

customobject.Test__c = '<img alt="email" src="' + emailimageid + '"></img>';

This was selected as the best answer