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
Mina Zaklama 9Mina Zaklama 9 

Native/Hybrid App: Navigate from a native page to a VF page passing values

Is it possible to create a native mobile app that can open a VF page in its view passing some values to it. Then navigating back to the native page.
Like if I have an iOS app that view a list of All Contacts, but I want the Contact details page to be a VF page because I might be showing and hiding fields frequently and I don't want to issue an update for the app every time I change the fields being viewed in the details page.
I want to pass the Contact.Id to the VF page to view the details and maybe edit then I can navigate back to the native page viewing the list of contacts, and maybe passing values from the VF page to another native page.
Ashish_SFDCAshish_SFDC

Hi Mina, 


That is possible using a Visualforce Component, See the links below for complete documentation, 

https://wiki.developerforce.com/page/Creating_a_Mobile_Component_for_Visualforce

https://wiki.developerforce.com/page/User_Interface

http://www.salesforce.com/us/developer/docs/salesforce1/salesforce1_guide.pdf


Regards,
Ashish

akhilesh_sfdcakhilesh_sfdc
There are multiple ways to solve this.
1) Using Native SDK: You can use frontDoorUrlWithReturnUrl method on SFAuthenticationManager, to obtain a salesforce URL with a valid user session. You can then launch a UIWebView with that URL to navigate to appropriate resource. In this case, you will have to define your own techniques to communicate back to native app from your VF page, which is not really straight forward depending on type of communication.

2) Using Hybrid SDK: Hybrid SDK comes packaged with cordova, which provides better hooks to communicate between your native app and the UIWebViews
Mina Zaklama 9Mina Zaklama 9
akhilesh_sfdc,

trying this code redirected me to salesforce login page
"You have attempted to access a page the requires salesforce.com login. If you are already a user of the system, please login below."

NSURL *url = [SFAuthenticationManager frontDoorUrlWithReturnUrl:@"{COMMUNITIES_URL}/apex/{VF_PAGE_NAME}" returnUrlIsEncoded:NO];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url  cachePolicy: NSURLRequestUseProtocolCachePolicy timeoutInterval:10];
[webview loadRequest:request];

Ashish_SFDCAshish_SFDC
Hi Mina, 


frontDoorUrlWithReturnUrl:returnUrlIsEncoded:

Creates an absolute URL to frontdoor with the given destination URL.

+ (NSURL *)frontDoorUrlWithReturnUrl:(NSString *)returnUrl returnUrlIsEncoded:(BOOL)isEncoded
Parameters
returnUrl
The destination URL to hit after going through frontdoor.

isEncoded
Whether or not the returnUrl value is URL-encoded.

Return Value
An NSURL object representing the configured frontdoor URL.

Declared In
SFAuthenticationManager.h

http://forcedotcom.github.io/SalesforceMobileSDK-iOS/Documentation/SalesforceSDKCore/html/Classes/SFAuthenticationManager.html


But it would basically look like this:

SFOAuthCredentials *creds = [SFAccountManager sharedInstance].credentials;
NSString *frontDoorUrl = [NSString stringWithFormat:@"%@/secur/frontdoor.jsp?sid=%@&retURL=%@&display=touch", [creds.instanceUrl absoluteString], creds.accessToken, @"/your/page/relative/url"];
UIWebView *webView = [[UIWebView alloc] initWithFrame:view frame];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:frontDoorUrl]]];

https://developer.salesforce.com/forums/ForumsMain?id=906F00000009FH5IAM


Regards,
Ashish