Variable doesn’t exist :Date

i write a small apex code snippet.

if(v.dataType == 'Date')
    {  System.debug('date is'+mapField.get(field1.name));
        System.debug('field is'+field1);
        String str = mapField.get(field1.name).fieldValue;
        Date x;
        if(str ==null)
        x= Date.newInstance(str.split('\\')[2],str.split('\\')[0],str.split('\\')[1]);

        if(Date.valueOf(dataType1) == x)
         conditionsResult.add(true);
         else conditionsResult.add(false);
    }

on line x= Date.newInstance(str.split('\\')[2],str.split('\\')[0],str.split('\\')[1]);
its giving me error

Variable does not exist: Date

but date is a global object i think.please help how to remove this error ??

Answer

Date.newInstance does not accept strings, it accepts integers according to the documentation. You are passing in Strings.

You could possibly try the Date.parse method.

Attribution
Source : Link , Question Author : user133421 , Answer Author : Phil Hawthorn

Leave a Comment