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

Can't get userId in latest version of iOS Mobile SDK - please help

I've spent way too many long nights on this.  My app is 95% done except I need this last little bit to work.


What I think I've learned:


- latest version doesn't use SFNativeRestAppDelegate.*m* - which means all of the answers I found via Google (like this: ) on how to get the current userId in a separate class/View doesn't work.


I've tried declaring a new instance of SFOAuthCredentials and of SFIdentityData (which I think is the correct one of the two):


    SFOAuthCredentials *class7Instance = [[SFOAuthCredentials alloc] init];
    NSString *stringValue7 = class7Instance.userId;




I'm not an iOS developer by trade but I've got my app all working except I need to extract the userId to take some additional logic (code already written).


Can someone help?  I'm interested in using the latest version, not ZKSForce or an older version of the SFDC Mobile SDK unless I really really have to.


I think it's something pretty simple.


When I've tried declaring an instance or setting NSUserDefaults, in debugger the string values are always 00000.

Craig IsaksonCraig Isakson

#import "SFAccountManager.h"




    SFOAuthCredentials *creds = [SFAccountManager sharedInstance].coordinator.credentials;

    NSLog(@"creds.userId:  %@", creds.userId);


Should work.


Gaurav KheterpalGaurav Kheterpal

The best way to keep up with the differences in the mobile sdk code is to actually look at what changed.


You'd see this snippet which explains how to retrieve all params


+    SFOAuthCredentials *creds = [SFRestAPI sharedInstance].coordinator.credentials;
+    NSString *accessToken = creds.accessToken;
+    NSString *refreshToken = creds.refreshToken;
+    NSString *clientId = creds.clientId;
+    NSString *userId = creds.userId;
+    NSString *orgId = creds.organizationId;
+    NSString *instanceUrl = creds.instanceUrl.absoluteString;
+    NSString *loginUrl = [NSString stringWithFormat:@"%@://%@", creds.protocol, creds.domain];
     NSString *apiVersion = [SFRestAPI sharedInstance].apiVersion;
     NSString* jsString = [NSString stringWithFormat:@""

 @@ - (void)sendJavascriptLoginEvent:(UIWebView *)webView {

                           "    refreshToken: \"%@\","

                           "    clientId: \"%@\","

                           "    loginUrl: \"%@\","
+                          "    userId: \"%@\","
+                          "    orgId: \"%@\","
                           "    instanceUrl: \"%@\","
                           "    apiVersion: \"%@\""
                           "  };"

 I hope this helps.