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
tschlosstschloss 

[zkSforce] problems with "update" method

Hi, maybe I am using the methods not in the intended way - a very basic example app would be soooo great!!!!

 

I have a little learning app on a free developper instance of SFDC.

What I achieved:

- I send out a "queryAll" and got reading access to all of the fields in the result (select Id,Name From Opportunity)

 

What does not work:

- update

 

What did I do and how does it go wrong:

- I took one of the 31 objects of the query result and put it into a new NSArray

- I sent an "update" with this one element array

- The runtime says

INVALID_TYPE: sObject type '' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names.

What confuses me.
- the property "Id" of all the zkSObjects in the query result is (null). I would have expected that this is set to the SFDC-id of the respective record. Is this needed for update and do I have to care for setting it?
- the property "type": same with all 31 records in the result: all (null). Maybe I have to put in something too (but don't know appropriate values).
- maybe I have to clear the id from the collection because it can't be updated (related to first point above)
I am really looking forward to a little more help ;)
Simon, pls. consider to add a donate or Flattr button to your website!
Thanks
Thomas
EDIT: 
I found some answers by trying:
- for a successful update the "type" property of the object to update has to be set. After setting it to @"Opportunity"  it worked.
- the update methods with either the Id in the header property of the objects or in the fields collection (or both; did not try if one has a higher priority if they are different from each other)
I still get some compiler warnings because the compiler does not know the type of my objects. This probably are due to my lack of Objective-C experience. Here is the screenshot: (oppsA ist the records NSArray from the zkQueryResult).
EDIT2:  by using some typecasts for the object references I could remove all of the warnings!

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell

There's a bug in the reading of id and type from query & retreive calls, I need to publish the new version with that fix. Having said that, its actually bad practice to do query/update with the objects you got from query because you'll be sending back all the fields you queried, rather than just the subset you want to actually change.

 

As for your compiler warning, NSDictionary is a read-only dictionary, the setters are part of a subclass of NSDictionary called NSMutableDictionary (this is a common pattern in cocoa), you should be changing the feilds on the object via the methods on ZKSObject, not by manipulating the contained fields dictionary. 

 

 

// setting a fieldValue to nil will automatically put it in the fieldsToNull collection
// setting a fieldValue to non nil will automatically remove it from the fieldsToNull collection
- (void)setFieldValue:(NSObject *)value field:(NSString *)field;
- (void)setFieldDateTimeValue:(NSDate *)value field:(NSString *)field;
- (void)setFieldDateValue:(NSDate *)value field:(NSString *)field;
- (void)setFieldToNull:(NSString *)field;

 

// setting a fieldValue to nil will automatically put it in the fieldsToNull collection

// setting a fieldValue to non nil will automatically remove it from the fieldsToNull collection

- (void)setFieldValue:(NSObject *)value field:(NSString *)field;

- (void)setFieldDateTimeValue:(NSDate *)value field:(NSString *)field;

- (void)setFieldDateValue:(NSDate *)value field:(NSString *)field;

- (void)setFieldToNull:(NSString *)field;

All Answers

SuperfellSuperfell

There's a bug in the reading of id and type from query & retreive calls, I need to publish the new version with that fix. Having said that, its actually bad practice to do query/update with the objects you got from query because you'll be sending back all the fields you queried, rather than just the subset you want to actually change.

 

As for your compiler warning, NSDictionary is a read-only dictionary, the setters are part of a subclass of NSDictionary called NSMutableDictionary (this is a common pattern in cocoa), you should be changing the feilds on the object via the methods on ZKSObject, not by manipulating the contained fields dictionary. 

 

 

// setting a fieldValue to nil will automatically put it in the fieldsToNull collection
// setting a fieldValue to non nil will automatically remove it from the fieldsToNull collection
- (void)setFieldValue:(NSObject *)value field:(NSString *)field;
- (void)setFieldDateTimeValue:(NSDate *)value field:(NSString *)field;
- (void)setFieldDateValue:(NSDate *)value field:(NSString *)field;
- (void)setFieldToNull:(NSString *)field;

 

// setting a fieldValue to nil will automatically put it in the fieldsToNull collection

// setting a fieldValue to non nil will automatically remove it from the fieldsToNull collection

- (void)setFieldValue:(NSObject *)value field:(NSString *)field;

- (void)setFieldDateTimeValue:(NSDate *)value field:(NSString *)field;

- (void)setFieldDateValue:(NSDate *)value field:(NSString *)field;

- (void)setFieldToNull:(NSString *)field;

This was selected as the best answer
SuperfellSuperfell

I updated the zksforce page with the fixed version of the library, and an additional sample and links.

tschlosstschloss

Thanks, that very kind.

 

Great library, great service - sometimes I would feel better, when having paid something for s.o. work! 

 

Cheers

Thomas