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
Nec 123zxcNec 123zxc 

About Apex class

Hello newbie here. I am not able to show the error from my Custom Label. Can anyone help me? Thank you so much!

 

//here is my Code

public class MyClassHandler {
  
    public static void caseValidation(List<Case> caseList){
        
        caseList = [SELECT Id, AccountId, Account.Client_Type__c from Case];
        Set<Id> caseId = new Set<Id>();
        
        for(Case caseStorage : caseList){
            caseId.add(caseStorage.AccountId);
            //system.debug('Result' + caseStorage.Id);
            
                if(caseStorage.Account.Client_Type__c == 'Silver' && caseId.size() <= 3){
                caseStorage.addError(System.Label.SilverError); //error message
            
        }
        } 
    }
}

 

//Here on the image is the main error I want to remove

User-added image

 

Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

I don't see any issue with the syntax of accessing the custom label.
Can you please let me know what exactly you are trying to achieve in the above scenerio.

Thanks,
Nec 123zxcNec 123zxc

Hi Sai,

 

I want to show the error message from my Custom Label on New Case form.

 

Thanks,
Nec

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Nec,

I did not understood the logic above. In which scenerio you want the error message to be shown .  I hope  this is a trigger handler.  Can you please elobrate the requirement .

Thanks,
Suraj Tripathi 47Suraj Tripathi 47

Hi,

Please find the solution. You can take references from the below code.

public class CustomLabelApexDemoController {
    public string customLabelValue{get;set;}
    public CustomLabelApexDemoController(){
        customLabelValue = System.Label.DemoLabel;
    }
}
 
String customLabelValue = System.Label.myName.DemoLabel;

Please mark it as the Best Answer so that other people would take references from it.

Thank You

Nec 123zxcNec 123zxc

Hi Sai,

 

This is the scenario, I have 2 clients the Silver and Gold, the Silver takes 1 case only then the Gold takes 3 cases only.
Now if my selected client is Silver, I am allowed to create 1 case only, then if I try to create another 1 or more than 1 case for Silver, 
the error message from my custom label will appear, and yes I am using trigger. 

 

Thanks,
Nec

Nec 123zxcNec 123zxc

Hi Suraj,

 

Sure, no worries.

 

Thanks,
Nec

Nec 123zxcNec 123zxc

Hello,

 

Additional, the Clients are from Account object.

 

Thanks,
Nec