visualforce

Requirement : Select image from document and then shows this image or insert this image on richtext area field on sobject.

here in this post we will learn  how you can insert an image into saleforce object fields .

but before going to code lets know the scenarios in which we need to insert image into sobject fields .

sometimes user want to show some images on record details page like:

profile image , product qr code or flags .

so to fullfill this requirement we need to follow the below steps:

  1.  create a rich text area field in your sobject
  2.  fetch the image from document using soql and insert it into your richtext area field

Here is the code snippet : 


// fetching image from document here image name is GreenFlag

List< document > documentList=[select Name,id from document where Name=’GreenFlag’ ];

// fetching account in which we want to insert image 

account acc = [select id,StatusFlag__c  from account limit 1];

// assigning image tag to account rich text area field (StatusFlag__c)

acc .StatusFlag__c ='<img src=”/servlet/servlet.FileDownload?file=’+documentList[1].id+'” width=”20″ height=”20″>’;


NOTE : You can also use formula fields in some scenarios.Its totally depends on your requirement.

Hits: 789

Share Post

By Himanshu Rana

My Name is Himanshu Rana, 23 Years young, born and grow up in Ghaziabad, India. A High Spirited Salesforce Admin, Developer and a Blogger. I currently work at Wakencode Technologies,

Leave a Reply

Your email address will not be published. Required fields are marked *