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
SapanaSapana 

Fields access

Can  we access fields from the custom objects which are not directly related to each other  in a visual force page ?How?

Best Answer chosen by Admin (Salesforce Developers) 
goabhigogoabhigo

Yes through SOQL query in Apex controller. But did not understand the use case for this !!

All Answers

goabhigogoabhigo

Yes through SOQL query in Apex controller. But did not understand the use case for this !!

This was selected as the best answer
RepsGRepsG

Yes you have to declare the Sobject variable in your apex controller like in the example below

 

public class mycontroller{

 

public Opportunity v_opp {get; set;}

 

public mycontroller() {

v_opp = new Opportunity();

Id id = ApexPages.currentPage().getParameters().get('id');

v_opp = [select Id, Name ....... from Opportunity where Id =: id];

 

}



}

 

Then make reference to the field from the Visualforce page For example

 

<apex:PageBlocksectionitem>

  <apex:outputLabelvalue="Loan Term(In Months)"/>

    <apex:panelgridcolumns="1">

       <apex:outputTextvalue="{!v_opp.Loan_Term__c}" rendered=""true" />

    </apex:panelgrid>

</apex:PageBlocksectionitem>

 

 











SapanaSapana

thanks for the code too