This is my visualforce page which displays the selected contacts from the previous page and a list of contacts in a picklist.
<apex:form>
<apex:pageBlock title="Selected contacts" >
<apex:pageBlockSection>
<apex:pageBlockTable value="{!selectedContacts}" var="sc" >
<apex:column value="{!sc.firstName}" />
<apex:column value="{!sc.lastName}" />
<apex:column value="{!sc.phone}" />
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:pageBlockSection title="Choose account" >
<apex:selectList value="{!accountDetail}" size="1">
<apex:selectOptions value="{!options}"/>
</apex:selectList>
</apex:pageBlockSection>
<apex:pageBlockButtons>
<apex:commandButton value="Save" action="{!save}" />
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
This is a part my controller related to the save button in the above page.
public pageReference save(){
system.debug('account'+accountDetail.Id);
for(contact con : selectedContacts){
con.accountId = accountDetail.Id;
selectedContactWithAccount.add(con);
}
if(selectedContactWithAccount.size() > 0){
update selectedContactWithAccount;
}
pageReference page = new pageReference('/apex/finalStep31July');
return page;
}
When i click on the save button the above page just gets reloaded and neither of the contacts get saved in the account record selected from the picklist. Please tell me what am I doing wrong here.
accountDetail
variable is of typeAccount
. I suppose its type is String?