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
cdolcdol 

Native iOS having trouble upserting to SFDC

Hello - Not quite sure if the title is most applicable, but here is the issue my team is having.

 

Our iOS app uses Core Location to identify a street address. It then searches for that street address in Salesforce, under both the Leads and the Accounts. Data can be input on the device, and then the information is uploaded back to Salesforce.

 

We normally don't get issues with the app, however, and this is the real kicker - it refuses to work in our main office.

 

Does anyone have any pointers as to what may be causing the error? I've included the Console output below. Sorry if it is more than what is required. 

 

Mar  5 15:19:27 Redacted-Name-iPad Sequoia[9181] <Warning>: (
	    "<SFAccount: 0x1e034c10> (entity: SFAccount; id: 0x1e07f900 <x-coredata&colon;//B05E5782-65F4-4EBB-9E68-F4E8D2C173FA/SFAccount/p5> ; data&colon; <fault>)"
	)
Mar  5 15:19:29 Redacted-Name-iPad Sequoia[9181] <Warning>: is connected: 1
Mar  5 15:19:29 Redacted-Name-iPad Sequoia[9181] <Warning>: SFRestAPI::send: <SFRestRequest 0x1e0506d0 
	endpoint: /services/data 
	method: GET 
	path: /v23.0/query 
	queryParams: {
	  "q" : "SELECT ID, Company, Name, Street, City, State, PostalCode, Phone FROM Lead WHERE PostalCode = '15238' AND Street LIKE '90 Beta_%' AND City = 'O'Hara Township' AND State = 'PA'"
	} 
	>
Mar  5 15:19:29 Redacted-Name-iPad Sequoia[9181] <Warning>: error: Error Domain=com.salesforce.RestAPI.ErrorDomain Code=999 "The operation couldn’t be completed. (com.salesforce.RestAPI.ErrorDomain error 999.)" UserInfo=0x1e0ac010 {message=
	'O'Hara Township' AND State = 'PA'
	                                 ^
	ERROR at Row:1:Column:175
	line 1:175 mismatched character '<EOF>' expecting ''', errorCode=MALFORMED_QUERY}
Mar  5 15:19:29 Redacted-Name-iPad Sequoia[9181] <Warning>: request:didFailLoadWithError: Error Domain=com.salesforce.RestAPI.ErrorDomain Code=999 "The operation couldn’t be completed. (com.salesforce.RestAPI.ErrorDomain error 999.)" UserInfo=0x1e0ac010 {message=
	'O'Hara Township' AND State = 'PA'
	                                 ^
	ERROR at Row:1:Column:175
	line 1:175 mismatched character '<EOF>' expecting ''', errorCode=MALFORMED_QUERY}
Sequoia[9181] <Warning>: (
	)
Mar  5 15:26:47 Redacted-Name-iPad locationd[46] <Notice>: received EBUSY, try kScanTypeChannel, channel, 153, rssi -60, delayed 0.000s
Mar  5 15:26:51 Redacted-Name-iPad Sequoia[9181] <Warning>: (
	    "<SFAccount: 0x1e034c10> (entity: SFAccount; id: 0x1e07f900 <x-coredata&colon;//B05E5782-65F4-4EBB-9E68-F4E8D2C173FA/SFAccount/p5> ; data&colon; {\n    accountType = Prospect;\n    autoRenewTerm = nil;\n    billingCity = nil;\n    billingState = nil;\n    billingStreetAddress = nil;\n    billingZIP = nil;\n    businessName = \"Brock's Account\";\n    contact = \"0x1cde1c30 <x-coredata&colon;//B05E5782-65F4-4EBB-9E68-F4E8D2C173FA/Contact/p5>\";\n    contractDate = \"2013-01-18 05:00:00 +0000\";\n    contractSignatureImageURL = nil;\n    contractTerm = nil;\n    createdContactID = nil;\n    createdContractURL = nil;\n    currentHauler = nil;\n    dateCreated = \"2013-03-05 19:40:22 +0000\";\n    dateModified = nil;\n    latitude = 0;\n    longitude = 0;\n    opportunity = \"0x1cd99420 <x-coredata&colon;//B05E5782-65F4-4EBB-9E68-F4E8D2C173FA/Opportunity/p5>\";\n    sfID = 001U000000Vm4LAIAZ;\n    shippingCity = \"O'Hara Township\";\n    shippingState = PA;\n    shippingStreetAddress = \"90 Beta Dr\";\n    shippingZIP = 15238;\n})"
	)

 

 

SuperfellSuperfell

When you build your SOSL string, you need to escape the ' in strings, from the log, it shows

 

endpoint: /services/data 
	method: GET 
	path: /v23.0/query 
	queryParams: {
	  "q" : "SELECT ID, Company, Name, Street, City, State, PostalCode, Phone FROM Lead WHERE PostalCode = '15238' AND Street LIKE '90 Beta_%' AND City = 'O'Hara Township' AND State = 'PA'"
	} 

Take a close look at the city clause its City = 'O'hara Township' the ' in the city name needs to be escaped with \ when you build the string.

 

 

cdolcdol

Understood, just had this problem turn up when doing a literal string in a different service. 

 

Any idea how to programatically escape the apostrophe when I dont really know what the City value will be?

SuperfellSuperfell

sure see escapeSosl in this class for an example, you'd call this passing each value as you build your sosl string.

cdolcdol

Is it the API that limits that apostrophe? Or Obj-C? 

 

I know for a fact they are able to be entered into text fields in Salesforce.

 

Either way, thanks for the link. I'm trying to learn how that works to patch my app. 

SuperfellSuperfell

Its from the sosl language, as quote is a delimitor in the sosl language, you can't have one directly within a value as then it thinks its the end of the value, same sort of thing as when building SQL queries.

cdolcdol

So this is a bit embarassing, but I've been going at this for over an hour now and cannot seem to get this to work properly.

 

I'm trying to start just by using escapeSosl for the 'city' in my address fields. However, my setup is a bit different than what was in the Maildrop example.

 

Any further advice on how to properly implement this to cut out any apostrophes in 'city' ?

 

- (NSString *)escapeSosl:(NSString *)src {
    // from docs, these are all reserved
    NSArray *reserved = [NSArray arrayWithObjects:@"\\", @"&", @"|", @"!", @"{", @"}", @"[", @"]", @"^", @"~", @"*:", @":", @"'" ,@"\"", @"+", @"-", nil];
    NSMutableString *s = [NSMutableString stringWithString:src];
    NSString *r;
    NSEnumerator *e = [reserved objectEnumerator];
    while (r = [e nextObject])
        [s replaceOccurrencesOfString:r withString:[NSString stringWithFormat:@"\\%@", r] options:NSLiteralSearch range:NSMakeRange(0, [s length])];
    return s;
}

-(void)syncServerDataWithAccount:(SFAccount *)account
{
    
    //Confirm the action
    //Parse the account location data, removing the last word in the `street` object, and removing illegal characters
    NSString *street = account.shippingStreetAddress;
    NSMutableArray *streetArray = [[street componentsSeparatedByString:@" "] mutableCopy];
    [streetArray removeLastObject];
    street = [streetArray componentsJoinedByString:@" "];
    street = [street stringByAppendingString:@"_%"];
    
    //Parse the City, making sure that there are no illegal characters!
    NSString *city = account.shippingCity;
    NSString *state = account.shippingState;
    NSString *zip = account.shippingZIP;

 

SuperfellSuperfell

Where are you building the sosl string and calling search ? that's the place to do the escaping.

samantha.logicsamantha.logic

With the location string, I guess you are getting it right ! But with SOSL you need to check certain other parameters of IOS that can be helpful in building the rest query for your DB.  Doc reference for each string of IOS upsertion can be found here