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
Pete RuddPete Rudd 

Change from dropdown default value to other value

I have a button on the standard Leads page that opens a VF page.

 

If (and only if) the Lead Status field is still on the option "Pending" (the default) I would like this value to change to "Working On"

 

How do I do this?

 

Also when I click the save button on my VF page is it possible to get the actions behind a different button on the Leads page to perform it's action? (It opens up a report.)

 

Thanks in advance.

Peter

JHayes SDJHayes SD

Hi Peter,

 

Not sure if I understand you're first question.  If you're simply looking to change the default value, this can be done in the UI (Customize -> Leads -> Fields).  For the VF page, can you post your controller code?

 

Regards, jh

Pete RuddPete Rudd

Hi JH

 

Thanks for replying. Let me explain more clearly.

 

We have a field on Leads called Status. This is a picklist with the following options: Pending, Working On, Not Interested & No Further Action. Pending is the default value.

 

What I would like is that when a user clicks on the button that takes them to the VF page if the Status field has the value as Pending then it is automatically changed to Working On.

 

I hope this makes more sense.

 

(I appreciate I could probably do away with a VF page and do what I'm trying to achieve within the Leads page using workflow but I'm a newbie to VF and this looks better and is good practice.)

 

I appreciate your help.

 

Kind regards

Peter

JHayes SDJHayes SD

Hi Pete,

 

Here's how I got this working.  This is assuming the button that takes you to the VF page is on a page layout for the Lead object.

 

1. Create a custom button; Type should be Detail Button and Content Source should be URL.  The value will redirect to a VF page called TestPage.  You need to pass the record id to your VF page.  Here's what I used:

 

/apex/TestPage?id={!Lead.Id}

 

2. Create a controller for your VF page.  This page should contain an action method that will update the field value if it is Pending.

 

public class TestController {    
    public void updateTestStatus() {
    	Lead l = [SELECT Id, Test_Status__c FROM Lead
                WHERE Id = :ApexPages.currentPage().getParameters().get('Id')];
        if (l.Test_Status__c == 'Pending') {
        	l.Test_Status__c = 'Working On';
        	update l;
        }
    }
}

 

 

3.  Use the action attribute on your <apex:page> element on your VF page to call your action method.

 

<apex:page action="{!updateTestStatus}" controller="TestController" id="thePage">

....

 

This worked for me.  

 

Regards, jh

Pete RuddPete Rudd

Thanks again JH.

 

Yes the button is on the Lead page. When clicked the user goes to the VF page. It is a very basic page that displays a few fields from the Lead page and has an additional dropdown box so the user can select how precise they want a search to be.

 

My current code is below. As you can see the Lead Status field is changed to "Working On" no matter what it's current value. What I would like is a simple script(??) that says IF Lead Status = "Pending" change it to "Working On". Is that possible. (The contoller solution you have suggested is a bit beyond me at the moment.)

 

<apex:page standardController="Lead" sidebar="false" >

  
 
<apex:form >
      


        <apex:pageBlock title="Nace Code Search">
        <apex:pageBlockSection title="Lead Industry Details" columns="1">
          
          
           <apex:outputField value=" {!Lead.Company}" />
           <apex:outputField value=" {!Lead.Nace_Code__c}" />
           <apex:outputField value=" {!Lead.Nace_Code_Description__c}" />
                            
                         
           <apex:selectList value="{!Lead.Status}" >
               <apex:selectOption itemValue="Working On" />
           </apex:selectList>
          
       
    
        </apex:pageBlockSection>
       
    <apex:pageBlockButtons >        
        <apex:commandButton value="Save" action="{!save}" />

    </apex:pageBlockButtons>
    
     
        <apex:pageBlockSection title="Search Type" columns="1">
             <apex:inputField value="{!Lead.Nace_Search_Type__c}"/>   
            
             <apex:outputField value="{!Lead.Nace_Search__c}"/>   
        </apex:pageBlockSection>

    </apex:pageBlock>
</apex:form>


</apex:page>

 


Regards

Peter