[SalesForce] Display Attachment image in formula field

I have a trigger which updates attachment id into a custom field of object X__c. I have creatted a formula field with below formula to display the attached pic

IMAGE('/servlet/servlet.FileDownload?file=customfield__c', customfield__c ,20,20).

But the image is not getting displayed.But if i replace the customfield__c with attachment id like below , the image is getting displayed. Please help where i am going wrong.

IMAGE('/servlet/servlet.FileDownload?file=00P28000000Ezg4', customfield__c ,20,20).

Best Answer

Because you've enclosed customfield__c inside single quotes it is being treated as a string literal in your formula.

You need to remove it from the single quotes and instead append it to your string to get the result you want.

IMAGE('/servlet/servlet.FileDownload?file=' + customfield__c, customfield__c, 20, 20)