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
mat_tone_84mat_tone_84 

syntax of query to get field in other object

Hi,

I need to create a vf page into contact for get a field of a custom object, is it be possible ?

 

the query is like: "select customobject_customfield from customobject where customobject_customfield = :contact_city"

 

I will create a new visualforcepage , put it into the layout of contact and get a custom message to the user.

 

I'm able to create the trigger with query by eclipse, but it is the first time that I have to create a query into visualforcepage

 

Someone can give me some help with the syntax ?

 

thanks

Best Answer chosen by Admin (Salesforce Developers) 
Navatar_DbSupNavatar_DbSup

Hi,

Try the below code snippet as reference:

 

<apex:page standardController="Contact" extensions="dispalyObjectA" >

  <apex:dataTable value="{!listobj}" var="m" columnswidth="100px,100px" cellpadding="4" border="1">

 

                <apex:column headervalue="ID" value="{!m.id}" />

                <apex:column headervalue="Nmae" value="{!m.name}" />

                <apex:column headervalue="Number" value="{!m.Number1__c}" />

                <apex:column headervalue="Price" value="{!m.objB_price__c}" />

              

               

                </apex:dataTable>

</apex:page>

 

=========Apex Controller===========

 

public class dispalyObjectA {

public List<ObjectA__c> listobj{get;set;}

    public dispalyObjectA(ApexPages.StandardController controller)

   

    {

        listobj=new List<ObjectA__c>();

        listobj=[select id,name,Number1__c, objB_price__c from ObjectA__c where Number1__c=70  Limit 10];

    }

  

}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

 

All Answers

Navatar_DbSupNavatar_DbSup

Hi,

Try the below code snippet as reference:

 

<apex:page standardController="Contact" extensions="dispalyObjectA" >

  <apex:dataTable value="{!listobj}" var="m" columnswidth="100px,100px" cellpadding="4" border="1">

 

                <apex:column headervalue="ID" value="{!m.id}" />

                <apex:column headervalue="Nmae" value="{!m.name}" />

                <apex:column headervalue="Number" value="{!m.Number1__c}" />

                <apex:column headervalue="Price" value="{!m.objB_price__c}" />

              

               

                </apex:dataTable>

</apex:page>

 

=========Apex Controller===========

 

public class dispalyObjectA {

public List<ObjectA__c> listobj{get;set;}

    public dispalyObjectA(ApexPages.StandardController controller)

   

    {

        listobj=new List<ObjectA__c>();

        listobj=[select id,name,Number1__c, objB_price__c from ObjectA__c where Number1__c=70  Limit 10];

    }

  

}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

 

This was selected as the best answer
mat_tone_84mat_tone_84

Hi,

the code works properly, but I need the last answer for filtering the query

 

 

 

  listobj=[select id,name,Number1__c, objB_price__c from ObjectA__c where Number1__c =  CONTACT.CUSTOMFIELD__C ];

 


 

which is the right syntax for filtering with contact's field?

I try to declare above "Contact C" and then filtering with number1__c = :c.customfield__c but doesn't work, I get "attemp to referenc a null object"

 

thanks!!

mat_tone_84mat_tone_84

I'm looking for another way for filtering but doesn't work....

 

<apex:column headervalue="ID" value="{!if( m.Number1__c = c.customfield__c ,m.number1__c,'not show')}" />

 I get syntax error Error: Syntax error. Missing ')'

mat_tone_84mat_tone_84

I solved the problem in this way, adding "rendered" into the apex:column

<apex:column rendered="{!m.number1__c=contact.customfield__c}"  headervalue="Number" value="{!m.Number1__c}" />