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
kiwitrotterkiwitrotter 

Trying to get a list of Lead Status values to display based on a certain Record Type.

Hi all,

 

I am new to this discussion board and I realise that this may have been posted a few times before but I have been unable to find a definitive resolution to this problem whereby it doesn't seem to be possible to get a list of picklist values relative to the record type.

 

My scenario is that we have a lead status picklist field that displays certain statuses if the record type is a Sales Record Type and displays a different set of statuses if the record type is a Marketing Record type. The following code that I use to try and pull out the lead statuses relavent to a particular record type doesn't work and instead the complete list of lead status values for both Sales and Marketing leads is displayed instead:

 

public List<SelectOption> getLeadStatusValue(){
    if(leadStatusValue == null){
        
        Schema.DescribeFieldResult fieldResult = Lead.Status.getDescribe();
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('', ''));
                     
        for( Schema.PicklistEntry f : ple)
        {
            options.add(new SelectOption(f.getLabel(), f.getValue()));
        }       
        leadStatusValue = options;
    }
    return leadStatusValue;
}

 

Does anybody know of any solution to this problem? Any help is greatly appreciated.

 

Thanks a million!

AlagarAlagar

Hi Kiwitrotter,

 

Yours code will return complete list of lead status values. Reason is u havent check the recordtypeid of the object while pulling the Leadstatus value.

 

 First get the recordtypeid as below:

Id salesRecTypeId = [select id from RecordType where DeveloperName = 'Sales_recordtype'].id; 

Id marketingRecTypeId = [select id from RecordType where DeveloperName = 'marketing_recordtype'].id;

 //developer name is record type name.  

 

 then check the condition

if(Recordtypeid=salesRecTypeId && LeadStatus!= null)

{ //place the code to pull the picklist field value  }

 

Now this will return Picklist value for Sales Record type