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
TilluTillu 

How to display object records on button click ?

I want to display all opportunities  records in  new window on button click on contact page. it is like all related to contact opportunities should need to be visible. Can any one help pls
Vijay NagarathinamVijay Nagarathinam
Hi,

Use the code,

visualforce:

<apex:page standardController="Contact" extensions="test"> 
  <apex:form >
    <apex:pageblock >
        <apex:pageblockTable value="{!olist}" var="a">
            <apex:column value="{!a.name}"/>
            <apex:column value="{!a.stagename}"/>
        </apex:pageblockTable>
    </apex:pageblock>
  </apex:form>  
</apex:page>

controller:

public class test 
{
public opportunity opp{get;set;}
public list<Opportunity> olist {get;set;}
public string ids;
public account acc;
    public test(ApexPages.StandardController controller) 
    {
      Contact con = (Contact)controller.getRecord();
      contact c1 = [select id , accountId from Contact where id =: con.id];
      ids = c1.accountId;
      olist = new list<opportunity>([select id, name, stagename from opportunity where AccountId =: ids]);
    }
}
TilluTillu
Not  getting expected result with this code...getting vf error  list has no rows to display
Vijay NagarathinamVijay Nagarathinam
In mydeveloper org its working fine. I add one custom button in contct detail page.

 
TilluTillu
is that all opportunities under that contact is displayed ??
TilluTillu
Did we need to pass contact id  in the butoon URL ?