0
if(opp1.size()>0)
    {
        for(integer i=0;i<opp1.size();i++)
        { 

            //oppid=String.valueOf(opp1[i].get('Id'));
            stage=String.valueOf(opp1[i].get('StageName'));
            tmp1+='<th>'+stage+'</th>';
            counter++;

        }

    }
9
  • what is the type of opp1? is it a list?
    – highfive
    Jun 28, 2016 at 6:04
  • It looks fine. What is the issue??
    – Mr.Frodo
    Jun 28, 2016 at 6:08
  • 4
    What is your actual question - How to Ask
    – Dave Humm
    Jun 28, 2016 at 6:10
  • Mr.Frodo its look fine but i want to show all stages values its show only one value that is already in oppotunity object and stage is the opportunity object field that contain 7 to 8 stage name so i can select all stage value stage type is picklist Jun 28, 2016 at 9:19
  • This code will give you the value of stage field of the opportunity record you have fetched.If that you want to find out then this code is correct. or you need the values in the stage picklist??
    – Mr.Frodo
    Jun 28, 2016 at 9:22

2 Answers 2

3

To retrieve the values of picklist you need to use Schema.DescribeFieldResult.

here is sample code to retrieve values of StageName picklist of Opportunity object.

Schema.DescribeFieldResult fieldResult = Opportunity.StageName.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
for(Schema.PicklistEntry s:ple){

    System.debug('value: '+s.getLabel());
} 

See this thread for more information.

7
  • this code show error Jun 28, 2016 at 10:09
  • Description Resource Path Location Type Save error: Method does not exist or incorrect signature: Opportunity.StageName.getDescribe() opportunity.cls /basit/src/classes line 33 Force.com save problem Jun 28, 2016 at 10:09
  • This code works fine.I have tested it.Can you update your code what are you doing?
    – Mr.Frodo
    Jun 28, 2016 at 10:14
  • public with sharing class opportunity{ public list<AggregateResult> opp{get;set;} public opportunity() { opp=[select StageName from Opportunity group by StageName ]; public String getOpportunity_Plan() { string stage=''; Schema.DescribeFieldResult fieldResult = Opportunity.StageName.getDescribe(); List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues(); for(Schema.PicklistEntry s:ple) { stage=s.getLabel(); } } } Jun 28, 2016 at 10:20
  • change name of your class from Opportunity to something else.It is conflicting.
    – Mr.Frodo
    Jun 28, 2016 at 10:31
-1

Just replace

stage=String.valueOf(opp1[i].get('StageName'));

by this :

stage=String.valueOf(opp1[i].StageName);

Regards,

Ajay

2
  • Both are correct. There is no need to replace.
    – Mr.Frodo
    Jun 28, 2016 at 6:25
  • Yes, of course Mr.Frodo you are right. Both are working. Jun 28, 2016 at 6:39

Not the answer you're looking for? Browse other questions tagged .