You need to sign in to do that
Don't have an account?

Retrieve All Contacts from same Account into picklist
I'm looking for some help, either code samples or documentation to point me towards that can help me achieve this. On an existing VF page, we are currently dislpaying Proposal__c record data and we are exposing and collecting data already.
What I need now is to be able to select a Contact, whose Account is associated to that record - in a picklist form or list form (most of our accounts for this purpose are <50 contacts).
On each Proposal__c is a Vendor__c (Contacts lookup). So basically, i need some help constructing the SOQL query to return the list of other Vendors (Contact lookup) associated to that Account. The user will basically be able to save to the record, one other contact. I'm not sure if a picklist or lookup is going to be easier in this scenario.
Relevant code below:
<apex:page standardController="Proposal__c" extensions="ProposalExtension" tabStyle="Proposal__c" cache="false"> <apex:pageMessages id="pageErrors"></apex:pageMessages> <apex:sectionHeader title="New Award"/> <apex:form id="awardForm"> <apex:pageBlock title="Bid Detail" id="awardBlock" mode="edit"> <apex:pageBlockButtons > <apex:commandButton value="Send LOE" action="{!sendLOE}"/> <apex:commandButton value="Cancel" action="{!cancel}"/> </apex:pageBlockButtons> <apex:pageBlockSection title="Bid Information" columns="2" collapsible="false" showHeader="false"> <apex:outputField value="{!bid.Vendor__r.Name}"/> <apex:outputField value="{!bid.Bid_Date__c}"/> <apex:outputField value="{!bid.Bid_Amount__c}"/> <apex:outputField value="{!bid.Bid_Deliver_By__c}"/> </apex:pageBlockSection> <apex:pageBlockSection title="Award Information" id="results" columns="2" collapsible="false"> <apex:inputField value="{!bid.Award_Amount__c}" required="true"/> <apex:inputField value="{!bid.Awarded_Date__c}" required="true"/> <apex:inputField value="{!bid.Award_Deliver_By__c}" required="true"/> <apex:inputField value="{!bid.Award_Comments__c}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
I couldn't figure out how to use those queries...but i did figure it out in a different way (probably not best practice). Here's how I did it - but if anyone could look over my controller / VF page and use the method described above i would appreciate it
My relevant VF page codeblock:
All Answers
In Controller you can use subquery on Account Query
Ex.
Account a=[Select id,name,(select id,name from contacts) from account];
list<Contact> lstcon=a.Contacts;
From this list you can make pick list whichh one you want?
Hi,
Try below sample code
List<Contact> s =[Select Contact.Account.Name,Contact.Account.id from Contact where Contact.Name='asha aas' ];
set<string> stids= new set<string>();
for(Contact d : s)
{
stids.add(d.Account.id);
}
List<Contact> c =[SELECT Contact.FirstName,Contact.LastName,Contact.Id, Contact.Account.Name from Contact where Contact.Account.Id in :stids];
system.debug(c);
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
I couldn't figure out how to use those queries...but i did figure it out in a different way (probably not best practice). Here's how I did it - but if anyone could look over my controller / VF page and use the method described above i would appreciate it
My relevant VF page codeblock:
Extra Question - If i wanted to output this as a searchable lookup - how would i do that?
Right now i'm using apex:selectList - but i'd rather use the component that gives me the standard lookup dialogue like when i hit the magnifying glass on standard layout pages.
Can anyone tell me why this code might work for me while in development but not in production?
In particular, the code for the contact picklist: