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
Hüsna ÇuhadaroğluHüsna Çuhadaroğlu 

VisualForce Pages return problem

After Lightning release, our visualforce pages ,in Salesforce1, which is connected to Opportunity, are not closing safely.
The code block is;

       pr = new PageReference('/' + oppId);
            pr.getParameters().put('nooverride', '1');
            pr.getParameters().put('id', oppId);
            return pr.setRedirect(true);   

In this block  return pr.setRedirect(true);    is not useful for returning to opportunity anymore.
We're getting this problem on production environment.

Is there anyone have the same problem? How can we handle with this bug?
 
Atul GuptaAtul Gupta
Husna, what do you mean by safely ? Are they not redirecting you to the right page ?
Hüsna ÇuhadaroğluHüsna Çuhadaroğlu
Yes Atul, the vfpage is not redirecting the right page (opportunity page)
Abhishek BansalAbhishek Bansal
Hi Husna,

You should change your code as below :
pr = new PageReference('/' + oppId);
return pr.setRedirect(true);
It will work in the same manner as you are trying to do with your method.
Please try with this and let me know if you have any issue.

Thanks,
Abhishek
Hüsna ÇuhadaroğluHüsna Çuhadaroğlu
Hi Abhishek, we have changed our code with yours but it didn't work again, we can not return the opp page. 
Abhishek BansalAbhishek Bansal
Hi Husna,

Can you tell us the error that you are getting in using the above code.
If there is no error than what is the actually happening here.
Can you please let us know the behaviour of this code ?

It would be easy to help you out if you can contact me on my gmail or skype.
Gmail : abhibansal2790@gmail.com
Skype : abhishek.bansal2790

Thanks,
Abhishek
Hüsna ÇuhadaroğluHüsna Çuhadaroğlu
Hi Abhishek,

This code block is a kind of redirecting the visualforce page to the right page. But with our code and the other one which is sent by you, didn't work for returning. This happened after winter release.
 
Atul GuptaAtul Gupta
Husna, you have got to use something like this to get it working in LEX(Lightning Experience) as well as in SF1
 
<apex:page controller="DC_redirect_to_oppty_controller">
<script>
function setupMarker(){ 

    var aId = '00637000005NYbK';
    
    // Go back to the Account detail page
    if( (typeof sforce != 'undefined') && sforce && (!!sforce.one) ) {
        // Salesforce1 navigation
        sforce.one.navigateToSObject(aId);
    }
    else {
		console.log('@@else : ')
        var url = location.href;  // entire url including querystring - also: window.location.href;
        var baseURL = url.substring(0, url.indexOf('/', 14));
        console.log('@@baseURL : '+ baseURL);
        // Set the window's URL using a Visualforce expression
        window.location = baseURL + '/' + aId;
    }
}
</script>
<apex:form >
    <apex:commandButton value="redirect" onclick="setupMarker(); return false;"/>
    </apex:form>
</apex:page>

 
sandeep unnikrishnansandeep unnikrishnan
For salesforce one you should use sforce.one.navigateToURL() javascript script methods to navigate.
sandeep unnikrishnansandeep unnikrishnan

if( (typeof sforce != 'undefined') && (sforce != null) ) { // Salesforce1 Remote Action method built in controller } else { //Action Function of normal App }
Atul GuptaAtul Gupta
Husna, did you sort this out.
Let me know if you need any further help on this.

Please mark a Best Answer to close this thread.
Hüsna ÇuhadaroğluHüsna Çuhadaroğlu
Hi Atıl,

Your code didn't work on our vf pages. We're trying to find another ways but really thanks for helps.
Atul GuptaAtul Gupta
Husna, I just tried this code in my DEV org and its working fine. This code is redirecting me to the right page even in SF1.

I think you are also invoking a action method on commandbutton, that case try this variation of the code
 
<apex:page controller="DC_redirect_to_oppty_controller">
<script>
function setupMarker(){ 

    var aId = '00637000005NYbK';
    
    // Go back to the Account detail page
    if( (typeof sforce != 'undefined') && sforce && (!!sforce.one) ) {
        // Salesforce1 navigation
        sforce.one.navigateToSObject(aId);
    }
    else {
        var url = location.href;  // entire url including querystring - also: window.location.href;
        var baseURL = url.substring(0, url.indexOf('/', 14));
        // Set the window's URL using a Visualforce expression
        window.location = baseURL + '/' + aId;
    }
}
</script>
<apex:form >
    <apex:commandButton value="redirect" action="{!methodInController}" oncomplete="setupMarker(); return false;"/>
    </apex:form>
</apex:page>

I've also removed the console.log statements from the javascript a they do not work in IE.

Let me know if you need any further help on this.
 
Atul GuptaAtul Gupta
Just for the example's sake I've hardcoded the opportunity ID in the above code, you need to pass in the right Id to get it working.
TabrezTabrez
Hi Husna,

Please try this code in your apex code which will return a Standard Visualforce Page.
 
public Opportunity getOpportunity() {
if(opportunity == null) opportunity = new Opportunity();
return opportunity;
}

//for redirecting to opportunity detail page.

PageReference optyPage = new ApexPages.StandardController(opportunity).view();
optyPage.setRedirect(true);
return optyPage;
Hope this answer your question.

Regards,
TabreZ
 
Ulas KutukUlas Kutuk
Husna, you shuold be using code  snippted below, try to use on oncomplete
sforce.one.navigateToURL('/001');

 
Atul GuptaAtul Gupta
Husna, did you sort this out ?

Please mark a Best Answer to close this thread.
Abhilash Mishra 13Abhilash Mishra 13
please look into this. really need help for this.
https://developer.salesforce.com/forums/ForumsMain?id=906F00000005I83IAE