Skip to content

Instantly share code, notes, and snippets.

@vetriselvanSF
Created October 29, 2017 14:46
Show Gist options
  • Save vetriselvanSF/018ad5307b00713714bdee941ff8229e to your computer and use it in GitHub Desktop.
Save vetriselvanSF/018ad5307b00713714bdee941ff8229e to your computer and use it in GitHub Desktop.
Fieldsets - APEX & Visualforce
<apex:page standardController="Account" extensions="OpportunityRelatedListClass" sidebar="false" showHeader="false">
<apex:pageblock id="pb">
<apex:pageBlockSection collapsible="false" columns="1">
<apex:pageBlockTable value="{!Opportunities}" var="opp" styleClass="dataTable">
<apex:column title="Edit">
<apex:outputLink style="color:#015ba7" value="{!URLFOR($Action.Opportunity.Edit, opp.Id, ['retURL'='/%2F'+ opp.AccountId])}" target="_top">Edit</apex:outputLink>
</apex:column>
<apex:column >
<apex:facet name="header">Opportunity Name</apex:facet>
<apex:outputLink value="/{!opp.Id}" target="_top">{!opp.Name}</apex:outputLink>
</apex:column>
<apex:repeat value="{!$ObjectType.Opportunity.fieldsets.Opportunity_RelatedList}" var="fieldValue">
<apex:column value="{!opp[fieldValue]}">
</apex:column>
</apex:repeat>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageblock>
</apex:page>
public class OpportunityRelatedListClass {
public List<Opportunity> oppList{get;set;}
public Account accObj = new Account();
public String accId;
Public Integer noOfRecords{get; set;}
Public Integer size{get;set;}
public Boolean hasDeleteAccess {get;set;}
public OpportunityRelatedListClass(ApexPages.StandardController OppController) {
}
// Method to query the list of Opportunities
public List<Opportunity> getOpportunities(){
accId = ApexPages.CurrentPage().getparameters().get('Id');
oppList = new List<Opportunity>();
String query = 'SELECT ';
for(Schema.FieldSetMember f : this.getFields())
{
query += f.getFieldPath() + ', ';
}
query += ' Id FROM Opportunity WHERE AccountId = :accId';
oppList = Database.Query(query);
return oppList;
}
// Method to get the list of fields in the fieldsets
public List<Schema.FieldSetMember> getFields()
{
List<Schema.FieldSetMember> fm = new List<Schema.FieldSetMember>();
return SObjectType.Opportunity.FieldSets.Opportunity_RelatedList.getFields();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment