You need to sign in to do that
Don't have an account?
noobfn
Visualforce popultng contacts from Account using fieldset
Hello, I'm a noob still to all of these. And I'm confused with my code, it doesn't work. Initially I used a list, I was populating contacts from an Account by entering accountId & click submit button, now I want to do the same but using a FieldSet. I created my fieldset called "properNames" and I'm stuck and confused with my code. Can someone help?
VP:
<apex:page standardController="Account" extensions="fieldSetExtension"> <apex:form > <apex:pageBlock > Enter Account Id: <apex:pageBlockSection > <apex:pageBlockSectionItem > <apex:inputText value="{!ContactForAcc.AccountId}" /> <apex:commandbutton value="Submit" action="{!redirectUser}"/> </apex:pageBlockSectionItem> </apex:pageBlockSection> <apex:pageBlockSection columns="1" id="contactTable" title="Contats Details"> <apex:pageBlockTable value="{!lstCon}" var="con"> <apex:repeat value="{!$ObjectType.Contact.FieldSets.properNames}" var="f"> <apex:column value="{!con[f]}"/> </apex:repeat> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
Extension Controller:
public with sharing class fieldSetExtension { public Contact ContactForAcc {get;set;} public fieldSetExtension(ApexPages.StandardController controller) { ContactForAcc = new Contact(); lstCon = new List<Contact>(); fields = new List<Schema.FieldSetMember>(); } public String AccountId {get;set;} Public List<Contact> lstCon {get;set;} Public List<Schema.FieldSetMember> fields = Schema.SObjectType.Contact.fieldSets.properNames.getFields(); public PageReference redirectUser(){ AccountId = ContactForAcc.AccountId; if(AccountId != null) { string query = 'select'; for(Schema.fieldSetMember f : fields){ query += f.getFieldPath() + ', '; } query += 'id, Name from Contact where Accountid =: AccountId'; lstCon = Database.query(query); } return null; } }
Thank you so much!
rubber duck effect, here is the solution:
VP:
Controller:
Regards,
NoobFN