Create field set :
Apex controller :
* Developer Name : Pratiksha Narvekar
* Created Date : 31-10-2017
**/
public class FieldsetAccount {
public String queryString{get;set;}
public list<Account> listAcc{get;set;}
public FieldsetAccount(){
queryString = 'Select ID';
for(Schema.FieldSetMember fsm : SObjectType.Account.FieldSets.FirstFieldsetAccount.getFields()){
queryString +=', '+fsm.getFieldPath();
}
queryString +=' from Account Limit 4';
listAcc = Database.query(queryString);
System.debug('...listAcc...'+listAcc);
}
}
Visualforce page:
* Developer Name : Pratiksha Narvekar
* Created Date : 31-10-2017
-->
<apex:page controller="FieldsetAccount" tabStyle="Account" sidebar="false"
ID="FieldSetAPID">
<apex:form ID="FieldSetAPFormID">
<apex:pageBlock ID="FieldSetAPBlockID">
<apex:pageBlockSection ID="FieldSetAPBlocksectionID" title="Account table" collapsible="true">
<apex:pageBlockTable value="{!listAcc}" var="listAccount">
<apex:repeat
value="{!$ObjectType.Account.fieldsets.FirstFieldsetAccount}"
var="varAcc">
<apex:column value="{!listAccount[varAcc]}">
</apex:column>
</apex:repeat>
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:pageBlockSection title="Account query is:" collapsible="true">
<apex:outputText value="{!queryString}"></apex:outputText>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Test class:
/**
* Developer Name : Pratiksha Narvekar
* Created Date : 31-10-2017
**/
@isTest
private class FieldsetAccountTest {
static testMethod void FieldsetAccountUnitTest() {
test.StartTest();
FieldsetAccount objFieldsetAccount = new FieldsetAccount();
Account objAcc = new Account();
//if u have required fields in account object then add those fields
objAcc.Name='test pratiksha';
insert objAcc;
test.StopTest();
}
}



Great!! Work Pratiksha
ReplyDeleteThanks:)
Delete