1

I am trying to have user select only specific account as parent account. So here is what the situation is . a custom drop down in visual force page that contains specific account. The user picks one of those accounts and submits the rest of the stuff. that page will be attached to account. so some how I need to get that name and the Account Id of it and put attach it to that ID . any ideas

<td class="data2Col" style="border-bottom:0px;">
                    <select id="BillingUnitType" class="AddressUnitType">
            <option value=""></option>
            <option value='APT'>Apartment</option>
            <option value='BLDG'>Building</option>
        </td>
        </select>

How do I pass the value of Apartment or building to salesforce controller. its a single choice, i am not passing a list

1

An org could contain many thousands of Accounts so a lookup field may be better. To display that in a Visualforce page your controller exposes an SObject instance that has an Account field (such as Contact) and your page just has this:

<apex:inputField value="{!contact.AccountId}"/>

The UI will present the name but the ID value will be populated correctly.

If you are sure there will never be more than a few tens or hundreds of Accounts you can instead present a select list of all the Accounts:

<apex:selectList value="{!contact.accountId}"
    <apex:selectOptions value="{!accountOptions}"/>
</apex:selectList>

where your controller creates a list of SelectOption objects for all Accounts where the value is the ID and the label the name.

PS

On the changed question, use an apex:selectList with apex:selectOption elements for the options and add a string property to your controller for the value to be automatically stored into.

|improve this answer|||||
  • Yes I understand what you are saying . so here is the situation Under a Hierarchy they may be 100 of account available that could be selected as parent account. The user may have access and see all those accounts however I only want to limit them to specific accounts as the parents. so the user can only use 4 region out of 12 regions we have , if i do a look up they will see 12 but if I make a custom selection in salesforce apex. (I dont wanna make an actual field in native salesforce) so the only see 4 instead of 12... is that clear? – Metawaa Jun 28 '16 at 22:08
  • @bez Sounds like building the SelectOption list is the way to go then; you can use SOQL/Apex to narrow down to exactly the relevant Accounts. – Keith C Jun 28 '16 at 22:11
  • I changed the question, I added something to it. so I want to create bunch of fields in that selection and pass that using variable in controller – Metawaa Jun 28 '16 at 22:13
  • @bez Ive added a PS but best of you Google and read up more on Visualforce as the binding of values to and from a controller is core stuff you'll need to know. – Keith C Jun 28 '16 at 22:18
  • Yes I was just writing that code – Metawaa Jun 28 '16 at 22:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.