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
HayaHaya 

SAme field showing different values in 2 different visualforce pages

I have 2 extensions pulling data for 2 visualforce pages.

 

I am having a problem with one the fields showing different values.

 

1.

Extension code:

case1=[Select Priority,CaseNumber,Accountid,Subject,Contactid,CreatedDate,Ownerid from case];   
 return case1; 

 

vp code:

<apex:column value="{! s.Ownerid}" headerValue="Request Owner" />

 

Results: the Ownerid shows up as expected: General Queue

 

 

2. 

Extension code: 

case1=[Select Priority,CaseNumber,Accountid,Subject,Description,Contactid,Ownerid,CreatedDate from case where CaseNumber='00222854'];   
return case1;

 

vp code:

<p>{!s.Ownerid}</p>

 

Results: the Ownerid shows up as: 00G00000006pE82EAE

 

All the rest of the fields are displayed with the right values.

 

What am I doing wrong?

 

Thanks,

Haya

 

Best Answer chosen by Admin (Salesforce Developers) 
swatKatswatKat

A look up field always stores the id of the parent record in the database. Just using the notation : <p>{!s.Ownerid}</p> will display the actual value. But like this :

 

<apex:column value="{! s.Ownerid}" headerValue="Request Owner" />

 the value of the field is displayed as a link, with the name of the look up record( like the owner name in your case).

 

  Replace the <p>{!s.Ownerid}</p> with the following and that should work.

 

<apex:outputField value="{!s.Ownerid}"/>

 

All Answers

swatKatswatKat

A look up field always stores the id of the parent record in the database. Just using the notation : <p>{!s.Ownerid}</p> will display the actual value. But like this :

 

<apex:column value="{! s.Ownerid}" headerValue="Request Owner" />

 the value of the field is displayed as a link, with the name of the look up record( like the owner name in your case).

 

  Replace the <p>{!s.Ownerid}</p> with the following and that should work.

 

<apex:outputField value="{!s.Ownerid}"/>

 

This was selected as the best answer
HayaHaya

That did it.

Thank you so much,

MellowRenMellowRen

I hate to ask the obvious but I assume the reason your second SOQL statement grabs a specific case ( where CaseNumber='00222854'  ) is for testing purposes and that this is the same case being viewed in your first VF page?

 

Second question. In your org is 00G00000006pE82EAE the ID of the General Queue? I am trying to assertain that when you say different values you are concerned about "General Queue" vs "00G00000006pE82EAE" not that it has go the wrong owner record.

 

Assuming the above, then your problem is that fact that pure HTML and Apex tags treat record IDs differently. The SOQL statement will get the ID (that is the 18 digit code you see). When you display that value in HTML (such as withing paragraph tags) this is exactly what yiou will get. When you assign that ID as the value attribute of an Apex tag, Salesforce knows that it is more than just a series of letters and numbers and specifically displays the Name field of the record it represents.

 

To get your first example to look like the second:

 

<apex:column headerValue="Request Owner">
   {!s.Ownerid}
</apex:column>

 To get your second example to look like the first, the easiest way would be to use an Outputfield:

 

<p><apex:outputField value="{!s.Ownerid}"/></p>

 And possibly remove the <p></p> tags depending on why they are there.

 

Hope this helps.

 

Regards

MellowRen

 

 

 

MellowRenMellowRen

Man I need to type faster :-)

swatKatswatKat

:)

Avidev9Avidev9
Man!