[SalesForce] Convert date in JSON to Date from String

While parsing JSON response from webservices, I'm getting date field as '03/21/2012' in a string format. My JSON2Apex parser class is converting this value in String and I'm facing hard time converting this value in Date format.

Illegal assignment from String to Date

    for(accountParser.cls_account caa : classlist){
    Account A = New Account ();
    A.Name = caa.Name;
    A.Start_Date__C = caa.Start_date; // Error: Illegal assignment from String to Date
}

Best Answer

You can always convert the value again after you have parsed your JSON. Try using the Date.parse(...) method on the string.

A.Start_Date__C = Date.parse(caa.Start_date);
Related Topic