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
MisbahMisbah 

Multiple Rest Request Objects with Attachments

Hi 

 

I have a view controller on which i am taking input from customer with images. after that i loop throgh rows and what ever row is slected and has image data i save it .

 

Now i noticed there is no TAG Property for SFRestRequest , and it uses the same response object for handeling the result. 

 

What i am doing is once new record is created, i received its ID in Resoonse then i upload attachment to sales force using that ID . 

 

Of one record this is fine, 1 record with 1 attachment, how to handel it when i hve 5 records with 5 attachments. how to distingish between requests.

Best Answer chosen by Admin (Salesforce Developers) 
jhersh1jhersh1

Hiya, I wrote an extension to the iOS SDK that allows you to make REST requests using block methods, which are then called on complete. It's very easy this way to keep track of which request returns which data. Make sure you're running the latest SDK, then check out Blocks.h

 

For example:

 

 

for( this; is; myloop ) {

[[SFRestAPI sharedInstance] performSOQLQuery:@"select id from account limit 10"

                                   failBlock:^(NSError *e) {

                                           NSLog(@"FAILWHALE with error: %@", [e description] );

                                       }

                               completeBlock:^(NSDictionary *results) {

                                        NSLog(@"success with %@", results );

                                   }];

All Answers

jhersh1jhersh1

Hiya, I wrote an extension to the iOS SDK that allows you to make REST requests using block methods, which are then called on complete. It's very easy this way to keep track of which request returns which data. Make sure you're running the latest SDK, then check out Blocks.h

 

For example:

 

 

for( this; is; myloop ) {

[[SFRestAPI sharedInstance] performSOQLQuery:@"select id from account limit 10"

                                   failBlock:^(NSError *e) {

                                           NSLog(@"FAILWHALE with error: %@", [e description] );

                                       }

                               completeBlock:^(NSDictionary *results) {

                                        NSLog(@"success with %@", results );

                                   }];

This was selected as the best answer
MisbahMisbah

Hi

 

Thank you very much for your kind support. I will test this solution, Hopefully it will work.

 

for the time being i was saving data like this

 

First I am inserting all records and maintain a sequce based on received response Insert RecordID of newly created records in a Dictionary then based on RecordID i am inserting all attachments with ParentID.

 

Using blocks it will be more easier to maintain a sequence and upload respective attachments together.

MisbahMisbah

Dear Johanthon

 

Thank you very much for your kind support.

 

The specified solution worked for me.

 


NSArray *fields = [[NSArray alloc] initWithObjects:@"Inspections__c" , @"Violation_Type__c",@"Number_of_Violations__c",@"Inspector_Remarks__c", nil];
NSArray *values = [[NSArray alloc] initWithObjects:self.InspectionID,ViolationType,theNOC ,inspectorRemakrs,nil];
NSDictionary *dict = [[NSDictionary alloc] initWithObjects:values forKeys:fields];

[[SFRestAPI sharedInstance] performCreateWithObjectType:@"Feedback__c" fields:dict
failBlock:^(NSError *e)
{
NSLog(@"Inspection Feedback FAILED with error: %@", [e description] );
}
completeBlock:^(NSDictionary *resDic)
{
NSString *recordID = [resDic objectForKey:@"id"];
NSString* cpiString = [NSString stringWithFormat:@"%d",currentImageButtonIndex];
UIImage *image = [UIImage imageWithData:[self.images objectForKey:cpiString]];
NSString *imageString = [UIImagePNGRepresentation(image) base64Encoding];

NSArray *attfields = [[NSArray alloc] initWithObjects:@"ParentId" , @"Name",@"Body", nil];
NSArray *attvalues = [[NSArray alloc] initWithObjects:recordID,@"Evidence.jpg",imageString,nil];
NSDictionary *attachmentInfo = [[NSDictionary alloc] initWithObjects:attvalues forKeys:attfields];

 

[[SFRestAPI sharedInstance] performCreateWithObjectType:@"Attachment" fields:attachmentInfo failBlock:^(NSError *e)
{
NSLog(@"Inspection Attachment : %@ FAILED with error: %@",recordID ,[e description] );
}
completeBlock:^(NSDictionary *resDic)
{

}];

[attvalues release];
[attfields release];
[attachmentInfo release];
}];