You need to sign in to do that
Don't have an account?
sforce.one is being called on desktop
We have a VF page that has the code from this articale (https://developer.salesforce.com/docs/atlas.en-us.salesforce1.meta/salesforce1/vf_dev_best_practices_pages_multipurpose.htm) to manage if the code runs on SF1 or desktop.
Since we do create sforce instace for JS work the if as apper in the articale generates an error
Wouldn't it be more currect to have it :
Thanks
if( (typeof sforce != 'undefined') && (sforce != null) ) { // Salesforce1 navigation }Does anyone knows why Salesforce whould think that sforce is only found in SF1?
Wouldn't it be more currect to have it :
if( (typeof sforce != 'undefined') && (sforce != null) && (sforce.one) ) { // Salesforce1 navigation }To make sure there is a sforce.one instance?
Thanks
There's a variety of ways to attempt to verify that you're executing in a Salesforce1 context, or not. We'll be updating the doc topic highlighted to use the following if condition for the test: You do need to test that sforce exists before you test for sforce.one. But, depending on your coding style, you might want to write it differently, test a few additional things, etc.
I'd recommend extracting the if condition out into a utility function, so that if the assumptions that underlie it ever change, you can update the function once, instead of doing a lot of search-and-replacing. (hint hint, safe harbor, etc.)
All Answers
There's a variety of ways to attempt to verify that you're executing in a Salesforce1 context, or not. We'll be updating the doc topic highlighted to use the following if condition for the test: You do need to test that sforce exists before you test for sforce.one. But, depending on your coding style, you might want to write it differently, test a few additional things, etc.
I'd recommend extracting the if condition out into a utility function, so that if the assumptions that underlie it ever change, you can update the function once, instead of doing a lot of search-and-replacing. (hint hint, safe harbor, etc.)
Hi Alderere_SFDC ,
From version 33 sforce is always present whether we are opening it from web or salesforce1.
@SF-Roy Thanks. If you ind my solution fruitful please select it a best answer :P
It's a behavior that has changed in the past, and will likely change again. Or we might provide a much better, more reliable way to check. That's why I recommend abstracting out the check for Salesforce1 into a utility function. That way, when it changes again, you'll be able to update your code quickly.
Gruber observed that this feature got the most mixed reaction from the crowd. You could see that half of the audience had adopted Auto Layout already, because they cheered. You could also see the laggards in the audience, who had not adopted this feature, because they groaned as they realized that they now had no choice, and it was going to be more work because they'd waited.
The question, when it finally came, came in the form of a statement. Roughly, "it seems like when Apple gives you the hint that you want to adopt a particular technology, it's often a very good idea to take the hint". Schiller's response was a deadpan "we have a pretty good track record of that".
Put your Salesforce1 check in a utility function. Check for sforce before you check for sforce.one. Safe harbor.
See "Detecting the User Experience Context" here: https://developer.salesforce.com/trailhead/lex_dev/lex_dev_visualforce/lex_dev_visualforce_multipurpose_pages
If this is going to pose a significant problem, please log a case and explain your use case.