So I have a formula field to check number of due days and I am checking that in my apex controller in 'if condition', if it is less than 7 or not. However, I have a requirement to make changes so -- "The number 7 should be a setting that we need to be able to update without code change. Can we add this in Global settings?"

My guess is -

  1. Either we can add it as static global integer variable?
  2. a constant?
  3. custom label, but that can't be used in apex.

Please provide your suggestion.

Note- The (starred)** lined is for which the changes are required


    public static List<PartnerTaskWrapper> getCountTask(){
    List<PartnerTaskWrapper> taskWrapper = new List<PartnerTaskWrapper>();
    User userData= UserUtils.getCurrentUser();
    String accountId = userData.Contact.Account.Id;
    Integer countedOpenTasks = 0;
    Integer countedUnassignedTasks =0 ;
    Integer countedOverdueTasks = 0;
    Integer counted7DaysDueTasks =0;
    List<Partner_Task__c> ptask= PartnerTaskSelector.getAllCountTask(accountId, System.AccessLevel.SYSTEM_MODE);
    for(Partner_Task__c allTask: ptask){
        if(allTask.Status__c == PartnerTaskConstants.STRING_ASSIGNED ||
          allTask.Status__c == PartnerTaskConstants.STRING_INPROGRESS || 
           allTask.Status__c == PartnerTaskConstants.STRING_UNASSIGNED){
            countedOpenTasks ++;
        if(allTask.Status__c == PartnerTaskConstants.STRING_UNASSIGNED){
            countedUnassignedTasks ++;
        if(allTask.Task_due_in_days__c <0){
            countedOverdueTasks ++;
        **if(allTask.Task_due_in_days__c <= 7 && allTask.Task_due_in_days__c >= 0){**
            counted7DaysDueTasks ++;
    taskWrapper.add(new PartnerTaskWrapper(countedOpenTasks,countedUnassignedTasks, countedOverdueTasks, counted7DaysDueTasks ));
    system.debug('days7dueCount '+counted7DaysDueTasks);
    system.debug('overdue '+countedOverdueTasks);
    system.debug('unassigned '+countedUnassignedTasks);
    system.debug('openCount '+countedOpenTasks);
    system.debug('wrapper '+ taskWrapper);
      return taskWrapper;

1 Answer 1


You can use Custom Label in Apex.


The value will be stored as String. So you will need to convert it to Integer.

Integer dueDate = Integer.valueOf(System.Label.CustomLabelName);

This can also be done using Custom Settings.

Create a List Custom Setting and add the Value__c custom text field. Create a Custom Setting record and set the Name as 'DueInDays' and Value__c as '7'. Follow Steps here.

Read the Custom Setting field value as String, convert it to Integer and use in Apex.

CustomSettingName__c mc = CustomSettingName__c.getValues('DueInDays');
Integer dueDate = Integer.valueOf(mc.Value__c);

Note: Instead of creating a text field you can also create a Number field for the Value. Text field is generic and can be used to store other settings as well.

  • Hey! @Sneh I don't think it will be lying with the requirement though. I have proper statement as - 'The number 7 should be a setting that we need to be able to update without code change. Can we add this in Global settings?'
    – SF Learner
    Jul 14, 2023 at 4:40
  • Added steps by using Custom Setting. Please note that even updating Custom Labels does not require any code change
    – Sneh
    Jul 14, 2023 at 4:59

You must log in to answer this question.

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