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
PawelWozniakPawelWozniak 

Ho to display record id instead of name in DataTable?

 

I want to diplay a table of products prices with product ID, have found that visualforce is making autoconversion which I want to avoid. 

 

The Apex SOQL query:

SELECT Id, Product2Id, Pricebook2Id, UnitPrice, CurrencyIsoCode, IsActive, UseStandardPrice FROM PricebookEntry WHERE // some coditions

 

Visualforce:
<apex:pageBlockTable id="pricesList" value="{!allPricesList}" var="price">
<!-- Id, Product2Id, Pricebook2Id, UnitPrice, CurrencyIsoCode, IsActive, UseStandardPrice -->
<apex:column headerValue="Product Id" value="{!price.Product2Id}" />
<apex:column headerValue="Pricebook Id" value="{!price.Pricebook2Id}"/>
<apex:column headerValue="CurrencyIsoCode" value="{!price.CurrencyIsoCode}"/>
<apex:column headerValue="UnitPrice" value="{!price.UnitPrice}"/>
<apex:column headerValue="UseStandardPrice" value="{!price.UseStandardPrice}"/>
<apex:column headerValue="IsActive" value="{!price.IsActive}"/>
</apex:pageBlockTable>

 

After page is rendered {!price.Product2Id} and {!price.Pricebook2Id} is changed to link to product/pricebook with its name. I want to have just salesforce ID here.

I tried:

{!price.Product2Id__r.Id} gives error: Invalid field Product2Id__r for SObject PricebookEntry

{!price.Product2Id.Id} error: Unknown property 'String.Id'

 

When I am diplaying content of List whoch hold values from SOQL which are given to VF page I see:

 

CurrencyIsoCode=EUR, IsActive=true, UseStandardPrice=false, Id=01uD000000B7LpVIAV, UnitPrice=1.00, Pricebook2Id=01sD0000000FE0sIAG, Product2Id=01tD0000001OvXoIAK
 

So conversion is made on VF page. How to stop it?

 

Best Answer chosen by Admin (Salesforce Developers) 
Shailesh DeshpandeShailesh Deshpande

Try to change your column tag to below:

 

<apex:column headerValue="Product Id" >

<apex:outPutText value="{!price.Product2Id}"/>

</apex:column>

All Answers

Shailesh DeshpandeShailesh Deshpande

Try to change your column tag to below:

 

<apex:column headerValue="Product Id" >

<apex:outPutText value="{!price.Product2Id}"/>

</apex:column>

This was selected as the best answer
PawelWozniakPawelWozniak

Thank you it works perfectly.