function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mavsmavs 

Saving selected select List option

some one plese help me to find what is wrong with the below code.

 

upon selecting the value in the dropdown list and after clicking on save button, Account.status__c field should be updated with the dropdown list selected value.

 

When i try to save the below code i am receiving this error. Please help

 

Illegal assignment from LIST:String to String

 

 

VF Page

<apex:page tabStyle="Account" controller="Account_Update"> <apex:form > <apex:pageblock mode="edit"> <apex:outputLabel value="Status"></apex:outputLabel> <apex:selectList value="{!status}" multiselect="false" size="1"> <apex:selectOptions value="{!items}"/> </apex:selectList> <br /><br /> <apex:pageBlockButtons location="bottom"> <apex:commandButton value="Save" action="{!save}"/> </apex:pageBlockButtons> </apex:pageblock> </apex:form> </apex:page>

 

Controller

 

 

public class SBS_Account_Update { String[] Status =new String[]{}; Id AcctId = ApexPages.currentPage().getparameters().get('id'); Account recTypeid=[Select RecordTypeId from Account where id=:AcctId]; public List<SelectOption> getItems() { List<SelectOption> options = new List<SelectOption>(); if(recTypeid.RecordTypeId=='0123000000004ZZ') { options.add(new SelectOption('--Select--','--Select--')); options.add(new SelectOption('Fully Paid','Fully Paid')); options.add(new SelectOption('Partially Paid','Partially Paid')); } else { options.add(new SelectOption('--Select--','--Select--')); options.add(new SelectOption('Paid','Paid')); options.add(new SelectOption('Not Paid','Not Paid')); } return options; } public String[] getStatus() { return status; } public void setStatus(String[] status) { this.status= status; }

Account act=new Account(Id=AcctId);

public PageReference save() { acct.Status__c=this.Status; Illegal assignment from LIST:String to String update acct; return null; } }

In the above save method, i tried putting, acct.status__c=Status[2];

When clicked on save, just the VFpage is getting refreshed. Nothing is getting saved in the Account.Status__c field.

 

Also,please advise!!!!

Message Edited by mavs on 06-25-2009 12:41 PM
Best Answer chosen by Admin (Salesforce Developers) 
ShamSham

Since <apex:selectList> mulitple is set to false it will always select a single value.

 

So instead of having string[] as Status value use a string.

 

i.e.

 

public String getStatus()
        {
            return status;
        }
           
       public  void setStatus(String status)
        {
            this.status= status;
        }
 

 

All Answers

ShamSham

Since <apex:selectList> mulitple is set to false it will always select a single value.

 

So instead of having string[] as Status value use a string.

 

i.e.

 

public String getStatus()
        {
            return status;
        }
           
       public  void setStatus(String status)
        {
            this.status= status;
        }
 

 

This was selected as the best answer
mavsmavs

Thanks Sham. It worked!!

 

I did not notice that....:smileywink: