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
Thomas PanniThomas Panni 

Retrieve document's name to use it in a formula

Hi guys,
I am quite a newby to apex and vf. I have to following problem to solve:

Using SFDC's standard state and country picklists the user enters an address on accounts. Depending on the selected country selection the belonging country flag should appear in a separate field on the newly created or changed account. I found the SFDC graphics pack on the appexchange and installed it. You can find all flags somewhere under documents. So far fine. If I create a formula using the billing country code field from the account object I get the ID, let's say DE for Germany. If I use the Image function in a formula I can set a hyperlink to a flag using the SFDC unique ID, i.e. something like 906F000000098ZCIAY. The image will show up.
But this requires that you know the ID's of every image and create a real giant formula to get the countries and flags assigned. Instead I wanted to use the file's name, i.e. de.png. From that I wanted to extract the first 2 characters, in this case DE and compare that with the preselected billing country code to automatically get the right flag assigned to the right country. My feeling is that this cannot be solved using a formula. I guess I might need some apex to do it. Can anyone help me out please? Any suggestion would be really appreciated. Thanks so much in advance...

best Thomas
ShashankShashank (Salesforce Developers) 
You can use an apex trigger to query the document Id and store the document Id in a custom field, and use the custom field in the formula.

You can also use headless flows in workflow rules or process builder to achieve the same.

Please try them and let me know if you are stuck somewhere specifically, or if you want me to provide sample code for a simple trigger.