+ Start a Discussion
shan razshan raz 

how to retrieve picklist value of each selected record

Hi everyone,
Hope everyone is safe and healthy...
I have a scenario where clients from community portal will go in and approve or reject there quotes. 
I got the page up and everything but updating the selected record i am having an issue with, especially the picklist value of the selected record.
Record 1 Status selected is Approved
Record 2 Status selected is Declined
They hit Save button
Both Records 1 & 2 will be saved with Declined.
Please Help
VisualForce Page
<apex:page controller="ZAttachmentViewer" showHeader="false" docType="html-5.0" lightningStylesheets="true">
<!--Outputpanel rendered in "acct" not equal to null-->
<!--<apex:outputPanel rendered="{!IF(account != null, true, false)}"> -->
<apex:form >
<apex:pageblock id="acct">

    <apex:pageblockTable value="{!acct}" var="ac">

        <apex:column value="{!ac.Quote_Status__c}" headerValue="Quote Status"/>
        
        <apex:column value="{!ac.Quote_Number__c}" headerValue="Quote Number"/>
        <apex:column value="{!ac.Id}" headerValue="Id"/>
        <apex:column value="{!ac.Status__c}" headerValue="Id"/>
        
        <apex:column headerValue="Approve or Reject here">
            <apex:selectList value="{!details}" size="1">
                <apex:selectOptions value="{!Items}" />
            </apex:selectList>        
        </apex:column>
        
        <apex:column headerValue="Comments">
            <apex:inputTextarea value="{!comments}" id="txtusername"/>     
        </apex:column>
        

        
        <apex:column headerValue="Approve/Reject Here">
            <apex:commandButton value="Approve/Reject " action="{!Submit}"/>  
        </apex:column>        

</apex:pageblockTable>
<apex:pageblockSection >
<apex:commandButton value="Approve/Reject " action="{!Submit}"/> 
</apex:pageblockSection>
                       
</apex:pageblock>

<apex:pageblock id="attachment" title="Attachments" >

    <apex:pageblockTable value="{!att}" var="a">
    
        <apex:column headerValue="Download">
            <apex:outputLink value="{!URLFOR($Action.Attachment.Download, a.Id)}" target="_blank">View</apex:outputLink>
        </apex:column>
        <apex:column value="{!a.Parent.Name}" headerValue="Quote Number"/>
        <apex:column value="{!a.Name}" headerValue="File Name"/>
        <apex:column value="{!a.LastModifiedDate}"/>  
   
   </apex:pageblockTable>
   
   
</apex:pageblock>   

</apex:form>
<!-- </apex:outputPanel>-->
</apex:page>
Apex Code:
public with sharing class ZAttachmentViewer{


    //private ApexPages.StandardController controller {get; set;}
    public List<Attachment> att{get;set;}
    public List<Community_Quote__c> acct{get;set;}  
    public List<Community_Quote__c> qqq = new List<Community_Quote__c>();
    public String StatusInput {get;set;}
    public String errorMessage { get; set; }
    public String details{get; set;}
    public String comments{get;set;}

    // standard controller - could also just use custom controller
    public ZAttachmentViewer(ApexPages.StandardController controller) {}

    public ZAttachmentViewer() {

        //Get UserId of the current user
        String usrid = UserInfo.getUserId();
        System.Debug('+++++++++UserID++++' + usrid);    
        
        //Run the Userid that we recieved and get the Account Id associated with it         
        User recordId = [SELECT AccountId__c FROM User Where ID=:usrid];
        System.Debug('+++++++++recordId++++' + recordId);
        
        account = recordId.AccountId__c;
        
        //Check to see if we get the Account ID
        System.Debug('+++++++++AccountId++++' + recordId.AccountId__c);
        
            
        //Use the AccountId into query to get results
        acct = [Select Id, Name,Account__c,Case__c,Quote_Status__c,
                Quote_Number__c,Comment__c, Status__c 
                from Community_Quote__c 
                where 
                Account__c=:recordId.AccountId__c 
                and 
                Quote_Status__c='Proposed to Client'];
        
        att = [select Id,ContentType,ParentId,Parent.Type,Parent.Name,OwnerId,Owner.Name, Name, LastModifiedDate, BodyLength from Attachment where ParentId = :acct];
        
        
    }
  
    public String options { get; set; }

     public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new selectOption('None', ' None '));
        options.add(new SelectOption('Accepted by Client','Accepted by Client'));
        options.add(new SelectOption('Rejected','Rejected'));
        return options;

    }
    

    public PageReference Submit() {
    
    List<Community_Quote__c> cpqlist = [select Id,Status__c,Comment__c,Quote__c from Community_Quote__c where Id=:acct];
        
        if(!cpqlist.isEmpty()) {
            for(Community_Quote__c ccc: accountIds){
                ccc.Status__c = details;
                ccc.Comment__c = comments;
                qqq.add(ccc);   

            }

        update qqq;
        }

    return null;
    }
}


 
Best Answer chosen by shan raz
Nikhil_KhetanNikhil_Khetan
@Zishan

Is Community_Quote__c.Status__c a picklist field? If so, rather than using bring it from server side, can't you bind it directly as a inputField on the VF page?

If not, then you have to use wrapper classes. This will solve you problem

Regards,
Nikhil
Please mark this as best answer, if my answer helped!

All Answers

Nikhil_KhetanNikhil_Khetan
@Zishan

Is Community_Quote__c.Status__c a picklist field? If so, rather than using bring it from server side, can't you bind it directly as a inputField on the VF page?

If not, then you have to use wrapper classes. This will solve you problem

Regards,
Nikhil
Please mark this as best answer, if my answer helped!
This was selected as the best answer
shan razshan raz
Thank you I wrote wrapperclass to have it work. thank you