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
SabrentSabrent 

Dynamically changing value of custom picklist field

I have a picklist field with values 'Yes', 'No'

On the web portal if a user uploads a document, I want the picklist value to change from 'No' to 'yes'.

If the value is already 'Yes', keep it as 'Yes'.

Can someone please shed light on how I can achieve this?

Thanks in advance.

Best Answer chosen by Admin (Salesforce Developers) 
CodeFinderCodeFinder

I suppose you have a controller to the vf page. In the upload button action method in controller  rite this condition

public Blob fileContent{get; set;}

SObject sc = new SObject();

//in the uploadbutton action method

 public void uploadAction(){
	
     if(fileContent != null && sc.picklist = 'No'){
        sc.picklist = 'Yes';
     }
}

 This is as per my understanding of the issue. if there is more info you want specifically can you give more detailed description of the case and please put the controller code and VF code.

 

 

All Answers

CodeFinderCodeFinder

I suppose you have a controller to the vf page. In the upload button action method in controller  rite this condition

public Blob fileContent{get; set;}

SObject sc = new SObject();

//in the uploadbutton action method

 public void uploadAction(){
	
     if(fileContent != null && sc.picklist = 'No'){
        sc.picklist = 'Yes';
     }
}

 This is as per my understanding of the issue. if there is more info you want specifically can you give more detailed description of the case and please put the controller code and VF code.

 

 

This was selected as the best answer
Kirtesh_JainKirtesh_Jain

Yeah,

 

You would have to check the Blob value is null or not null . On the basis of that you can change the picklist value to Yes in your apex code . 

 

Thanks,

Kirtesh

Kirtesh_JainKirtesh_Jain

If you are not using the VF page then you would have to write trigger and need to check the documents uploaded and then can take decesion..

 

Please provide more detailsif  you are not ok with solns.

 

Thanks.

Kirtesh

SabrentSabrent

CodeFinder, Thank you very much ! Yes you are right I have a controller to the vf page. I shall try this and let you know.

 

SabrentSabrent

Thanks for your reply Kirtesh. I will try a solution posted by CodeFinder which is similar to your solution. I will try it and let you know. Much appreciated!!

CodeFinderCodeFinder


I am sure the value must be changing but the problem is its not getting updated to the database. You have to update the Sobject after the change in the picklist. 

 

public PageReference divSubmit(){
        this.diversityPanelSwitch = false;
        this.cntrDiversityList = new List<DiversityWrapper>();     
        supplierRecordsInitialization();
        resetDivPageFlags();
        if (this.Supplier.Is_your_company_certified_as_Diverse__c != 'Yes')this.Supplier.Is_your_company_certified_as_Diverse__c = 'Yes';
        return null;
    }

 

 

For this code

I see that you are not updating the object after you have changed the field to Yes. Please put a System.debug(this.Supplier.Is_your_company_certified_as_Diverse__c) statement after the if code. put the if code in braces and then put a debug statement. and check in the debug logs.
if (this.Supplier.Is_your_company_certified_as_Diverse__c != 'Yes'){

          this.Supplier.Is_your_company_certified_as_Diverse__c = 'Yes';
          System.debug(this.Supplier.Is_your_company_certified_as_Diverse__c);
}

 I am sure the value must be changing but the problem is its not getting updated to the database. You have to update the Sobject after the change in the picklist. 


SabrentSabrent

CodeFinder, thanks heaps!!! You are right I was't updating the Supplier object.  I added update Supplier and that  solved my problem. 

 

if (this.Supplier.Is_your_company_certified_as_Divers​e__c != 'Yes'){

          this.Supplier.Is_your_company_certified_as_Diverse​__c = 'Yes';
          update Supplier;
}

 

Thanks, once again.