1

I have a requirement where I have to get Default Task Status and Closed Status.

     String defaultTaskStatus; // variable which contains Default Status
     Set<String> taskClosedStatusSet; // Set of Closed Status

I checked In Task object there is no field call isDefault or isClosed.

However, there is a Standard Object called TaskStatus, which contains above 2 variable.

So, how we will get all required data by using 2 standard objects Task and TaskStatus ?

3

Try this

String defaultTaskStatus = (String)[select MasterLabel from TaskStatus WHERE
                                   IsDefault=TRUE][0].get('MasterLabel');

Set<String> taskClosedStatusSet = new Set<String>();

for(TaskStatus ts: [select MasterLabel from TaskStatus WHERE IsClosed=TRUE]){
    taskClosedStatusSet.add(ts.MasterLabel);
}
  • That's correct if you are going to show the value, but if you want to compare that value to Task.Status, you should be using TaskStatus.ApiName, not TaskStatus.MasterLabel, since it's possible for them to be different, and TaskStatus.ApiName is the value that is used for Task.Status. – paulie4 May 11 '18 at 19:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.