0

I need in my wrapper class the activity date from the task object as string to display at a visual force page. My two version below does n't work.

If I use this version I get an error (Attempt to de-reference a null object).

public class Wrapper implements Comparable {
    
    private final Id id;
    private final DateTime createDateSort;
    private final String createDate;
       
    public wrapper(Task t) { 
        id                    = t.Id;
        DateTime activitydate = t.ActivityDate;
        createDate            = activitydate.format('dd.MM.yy', UserInfo.getTimeZone().toString());
        createDateSort        = t.ActivityDate;           
    }

And if I use this version I get the error (Method does not exist or incorrect signature: void format(String) from the type Date

public class Wrapper implements Comparable {
    
    private final Id id;
    private final DateTime createDateSort;
    private final String createDate;
       
    public wrapper(Task t) { 
        id                  = t.Id;
        createDate          = t.activitydate.format('dd.MM.yy');
        createDateSort      = t.ActivityDate;           
    }
1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Oct 12, 2021 at 9:56

2 Answers 2

0

Try this

createDate = string.valueOfGmt(createDateSort);
0

I found the problem. It was because there were tasks with no activitydate. I add an If-Clause to solve the problem.

    If (t.ActivityDate == Null) { 
        createDateSort  = t.CreatedDate;
        createDate      = t.CreatedDate.format('dd.MM.yy', UserInfo.getTimeZone().toString());
    } ELSE {
        DateTime ActivityDate = t.ActivityDate;
        createDateSort        = t.ActivityDate;
        createDate            = ActivityDate.format('dd.MM.yy', UserInfo.getTimeZone().toString());
    }

You must log in to answer this question.

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