-3

In following trigger.I need to get the labels for field labels in Opportunity Level:

For example:

 Api name                                        Field Label

Client_Stability_Risk_Mitigation__c --->Client Stability Risk & Mitigation
Contract_Terms_Risk_Mitigation__c --->Contract Terms Risk & Mitigation         

etc.

   for(Opportunity op:opList){
 if(op.Client_Stability_Risk_Mitigation__c!=null &&  op.Top_Risk_Client_Stability__c){
       //I need field label of Client_Stability_Risk_Mitigation__c
        i++;
            op.Top_2_Risks__c=i+'.'+op.Client_Stability_Risk_Mitigation__c;

        }
        if(op.Contract_Terms_Risk_Mitigation__c!=null && 
  op.Top_Risk_Contract_Terms__c){
  //I need field label for Contract_Terms_Risk_Mitigation__c
               if(op.Top_2_Risks__c!=null){
               i++;
                   op.Top_2_Risks__c=op.Top_2_Risks__c+'\n'+i+'.'+op.Contract_Terms_Risk_Mitigation__c;
               }
           }}
1
  • -1 for not demonstrating any research efforts, please make sure you do so prior to posting, you have been a member for quite some time now and your post history does not do you much favor.
    – glls
    Commented Jul 17, 2018 at 3:36

3 Answers 3

1

Get it from apex describe calls - DescribeSObjectResult:

To get Account Name:

Schema.SObjectType.Account.fields.Name.getLabel()

In your example:

Schema.SObjectType.Opportunity.fields. Client_Stability_Risk_Mitigation__c.getLabel()
0
4

You can get this information with the Describe API. For example,

String fieldLabel = Opportunity.Client_Stability_Risk_Mitigation__c.getDescribe().getLabel();

There are many ways to invoke the Describe API; see DescribeFieldResult and DescribeSobjectResult for more details and examples.

0
2

you can try this using describe cls.

 for(Opportunity op:opList){
if(op.Client_Stability_Risk_Mitigation__c!=null &&  op.Top_Risk_Client_Stability__c){
    //I need field label of Client_Stability_Risk_Mitigation__c
    i++;
    op.Top_2_Risks__c=i+'.'+Opportunity.Client_Stability_Risk_Mitigation__c.getDescribe().getLabel();

}
if(op.Contract_Terms_Risk_Mitigation__c!=null && 
   op.Top_Risk_Contract_Terms__c){
       //I need field label for Contract_Terms_Risk_Mitigation__c
       if(op.Top_2_Risks__c!=null){
           i++;
           op.Top_2_Risks__c=Opportunity.Top_2_Risks__c.getDescribe().getLabel();+'\n'+i+'.'+Opportunity.Contract_Terms_Risk_Mitigation__c.getDescribe().getLabel();
       }
   }}
0

You must log in to answer this question.

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