+ Start a Discussion
Chris MarzellaChris Marzella 

Scale A Formula Using Apex

I am looking for a way to get a contact image into the detail page, but I need something that can scale to thousands of contacts. The below formual works for a small amount of records, but this will quickly become unmanageable. Would Apex be the best route and how would I accomplish this?
 
IMAGE(
    CASE(
        Name,

        'Jeff May',       '/servlet/servlet.ImageServer?id=01590000000rZ17',
        'Steve Molis',    '/servlet/servlet.ImageServer?id=01590000000rZ18',
        'Geoffrey Flynn', '/servlet/servlet.ImageServer?id=01590000000rZ19',

        '/img/s.gif'
    ),
    'Contact Logo'
)

 
William TranWilliam Tran
Are you planning to put this is a formula field?  Formula field can't call Apex if I recall correctly

If it's regular apex/VF page, it depends on where the data reside, if it is in the DB you can create function to return the ID given name using SQOL select id from .... where name ='Jeff May';

if it's something you need to manual entered, you can consider manually creating a map object or something similar to store the data.

thx
Chris MarzellaChris Marzella
It doesn't need to populate a formula field. I just want to be able to say If name="Jeff May" get from documents JeffMay.jpg
William TranWilliam Tran
Yes, you can create a get method taking in a string parameter of name and returning a string type of Picture name.

thx.
Chris MarzellaChris Marzella
Sorry I am new to apex. What would the get method look like?
SKolakanSKolakan
Here is an alternative -
have an image ID field (Say Image_Id__c) on contact which will contain image ID for that contact and use image formula field like IMAGE('/servlet/servlet.ImageServer?id=' & Image_Id__c)