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
hitzhitz 

FIeld Set Image FIeld Issue

Hi, Experts

 

I have Created one Formula (Text) field which display images  according to risk [red, green, yellow]. it works good in page layout means display image according to value but problem with field set.

 

i have created field set which contains that Formula (Text) field and some other fields set.

now i have created one VF page  which display value in field set using below code

 

<apex:pageBlockSection columns="2">
                       <apex:repeat value="{!$ObjectType.myObj__c.FieldSets.General_Detail}" var="mo">
                            <apex:outputField value="{!mobjId[mo]}"/>       
                       </apex:repeat>
                  </apex:pageBlockSection>

it displays other fields records good but it will not display image [it diaplays image path like <img src="green.gif" alt="abc"/>]

 

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Hmm.  Maybe contains throws an error when it doesn't like the type - I've also tried with number, text and currency and while the output isn't what I'm looking for I don't get an error.

 

However, its worth checking the type of field.  I've revised my code below to check the type of field before looking for the value <img.  Depending on how the boolean logic is implemented in Visualforce, this may need to be split out into seperate conditions, but try this to begin with:

 

 

<apex:repeat value="{!$ObjectType.Account.FieldSets.AccountsAndContactsEdit}" var="field">
     <apex:outputPanel rendered="{!AND($ObjectType.Account.Fields[field].type=='string', CONTAINS(Account[field], '<img'))}">
       <apex:outputLabel value="{!$ObjectType.Account.Fields[field].label}"/>
       <apex:outputText value="{!Account[field]}" escape="false"/>
     </apex:outputPanel>
     <apex:inputField value="{!Account[field]}" rendered="{!NOT(AND($ObjectType.Account.Fields[field].type=='string', CONTAINS(Account[field], '<img')))}"/>
</apex:repeat>

 

 

All Answers

bob_buzzardbob_buzzard

Yeah, unfortunately as the type of your field is a String, Salesforce renders it as-is.

 

I've used the following technique to work around this - its not elegant but does the trick.  If the field containts the text '<img', I render it out as a label plus the unescaped HTML, otherwise I render it as a regular field:

 

 

<apex:repeat value="{!$ObjectType.Account.FieldSets.AccountsAndContactsEdit}" var="field">
   <apex:outputPanel rendered="{!CONTAINS(Account[field], '<img')}">
      <apex:outputLabel value="{!$ObjectType.Account.Fields[field].label}"/>
      <apex:outputText value="{!Account[field]}" escape="false"/>
   </apex:outputPanel>
   <apex:inputField value="{!Account[field]}" rendered="{!NOT(CONTAINS(Account[field], '<img'))}"/>
</apex:repeat>

 

 

hitzhitz

Hi, bob

 

Thanks  for quick reply,

but i have still problem it will show me an internal server error

bob_buzzardbob_buzzard

How odd - mine displays the field as expected.

 

Can you post your revised code?

hitzhitz

Hi, bob

 

my field set contains number,text, currency and image [formula [text] to..........

 

<apex:repeat value="{!$ObjectType.myObj__c.FieldSets.General_Detail}" var="mo">
   <apex:outputPanel rendered="{!CONTAINS(mobjId[mo], '<img')}">
      <apex:outputLabel value="{!$ObjectType.myObj__c.Fields[mo].label}"/>
      <apex:outputText value="{!mobjId[mo]}" escape="false"/>
   </apex:outputPanel>
   <apex:outputField value="{!mobjId[mo]}" rendered="{!NOT(CONTAINS(mobjId[mo], '<img'))}"/>
</apex:repeat>

bob_buzzardbob_buzzard

Hmm.  Maybe contains throws an error when it doesn't like the type - I've also tried with number, text and currency and while the output isn't what I'm looking for I don't get an error.

 

However, its worth checking the type of field.  I've revised my code below to check the type of field before looking for the value <img.  Depending on how the boolean logic is implemented in Visualforce, this may need to be split out into seperate conditions, but try this to begin with:

 

 

<apex:repeat value="{!$ObjectType.Account.FieldSets.AccountsAndContactsEdit}" var="field">
     <apex:outputPanel rendered="{!AND($ObjectType.Account.Fields[field].type=='string', CONTAINS(Account[field], '<img'))}">
       <apex:outputLabel value="{!$ObjectType.Account.Fields[field].label}"/>
       <apex:outputText value="{!Account[field]}" escape="false"/>
     </apex:outputPanel>
     <apex:inputField value="{!Account[field]}" rendered="{!NOT(AND($ObjectType.Account.Fields[field].type=='string', CONTAINS(Account[field], '<img')))}"/>
</apex:repeat>

 

 

This was selected as the best answer
hitzhitz

Hi, bob

 

Thank you

 

i have also solved using below code

 

<apex:repeat value="{!$ObjectType.Account.FieldSets.Risk_Set}" var="ac">
            <apex:outputPanel rendered="{!CONTAINS( $ObjectType.Account.Fields[ac].label, 'Risk')}">
                <apex:outputLabel value="{!$ObjectType.Account.Fields[ac].label}"/>
                <apex:outputText value="{!accId[ac]}" escape="false"/>
            </apex:outputPanel>
            <apex:outputField value="{!accId[ac]}" rendered="{!NOT(CONTAINS( $ObjectType.Account.Fields[ac].label, 'Risk'))}"/>
        </apex:repeat>

 

it works but not formated display