function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RacerRex9727RacerRex9727 

Can't deserialize date fields?

I am working on an iOS app procedure that queries a SQLite database and attempts to upload the records onto SalesForce. However, I seem to be having issues with the date fields. I keep getting an error message that it cannot be serialized. My JSON-savvy coworker suggested I try using the ASCII notation to represent the "/" in the dates, but it still keeps giving me the same error. How do I format the StartDate field so SalesForce will accept it?

 

 if (sqlite3_prepare_v2(database, [query UTF8String],-1,&statement, nil) ==SQLITE_OK)
    {
        while (sqlite3_step(statement) == SQLITE_ROW)
        {
           

NSDate* MyDate = [formatter dateFromString: [NSString stringWithCString (char*)sqlite3_column_text(statement, 2) encoding:NSUTF8StringEncoding]];

NSMutableString * StartDate = [NSMutableString stringWithFormat:@"%@",[formatter stringFromDate:MyDate]];

 [StartDate replaceCharactersInRange: [StartDate rangeOfString:@"/"] withString:@"&#48" ];

 [StartDate replaceCharactersInRange: [StartDate rangeOfString:@"/"] withString:@"&#48" ]; //Other fields, irrelevant code to problem
NSDictionary * fields = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects: [NSNumber numberWithInt:FormID],AuditID,StartDate,StartTime,StationID,UserID,Gate,FlightNumber,RegNoseNumber,Completed,Year,AirCraft, nil] forKeys:[NSArray arrayWithObjects: @"FormID__c",@"AuditID__c",@"StartedDate__c",@"StartedTime__c",@"StationID__c",@"UserID__c",@"Gate__c",@"FlightNumber__c",@"RegistryNoseNumber__c",@"Completed__c",@"Year__c",@"Aircraft__c", nil] ]; SFRestRequest *request = [[SFRestAPI sharedInstance] requestForCreateWithObjectType:@"Form__c" fields:fields]; [[SFRestAPI sharedInstance] send:request delegate:self]; } sqlite3_finalize(statement); sqlite3_close(database);

 

SuperfellSuperfell

date / datetimes should be in iso 8601 format, e.g. 2012-05-14T20:21:00Z

RacerRex9727RacerRex9727

I still keep getting the failure : (

 

5/17/12 8:18:15.487 AM SOSApp SF: error: Error Domain=com.salesforce.RestAPI.ErrorDomain Code=999 "The operation couldn’t be completed. (com.salesforce.RestAPI.ErrorDomain error 999.)" UserInfo=0x6ea6870 {message=Cannot deserialize instance of date from VALUE_STRING value 2012-05-17T07:47-0500 at [line:9, column:45], errorCode=JSON_PARSER_ERROR}


J2theCJ2theC

what is the date format you've applied to your NSDateFormatter?

 

on an unrelated note: why are you using Sqlite directly instead of core data?

RacerRex9727RacerRex9727

It's my intention to learn Core Data after this project. I've only been programming on iOS for a few months but had to meet pressing development deadlines for the app while I learned.

 

 

Anyway...

 

 

    NSDateFormatter *formatter;
    formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-ddTHH:mmZ"];

 

 

J2theCJ2theC

Your date formatter format is missing parameters for seconds and miliseconds. Are you sure the ISO 8601 standard will accept that format? 

RacerRex9727RacerRex9727

Well until now I haven't really given much thought to the ISO 8601 format. What format syntax would you suggest I put in the formatter? I'm just trying to get SalesForce to accept the silly thing.

SoleesSolees

Try this man,

 

    //set Date formatter

    NSTimeInterval startDateSeconds = [[NSDate yourDaaaaaaaaaaaaaaate] timeIntervalSince1970];

    NSDate *startDate = [NSDate dateWithTimeIntervalSince1970:startDateSeconds];

    

    NSDateFormatter* df_utc = [[[NSDateFormatteralloc] init] autorelease];

    [df_utc setTimeZone:[NSTimeZonetimeZoneWithName:@"UTC"]];

    [df_utc setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.000'Z'"];

    

    NSString *startDateString = [df_utc stringFromDate:startDate];