+ Start a Discussion
sathishkumar periyasamysathishkumar periyasamy 

PageReference not working in community

We have custom button "Close Opportunity/Create Order" on the opportunity layout. When user click that button we will redirecting to Visualforce page to create a Order Line Item and Fulfillment record. Once the transaction is completed system will be redirecting to Order Line Item. This is working for Internal user but community user are getting wired look and feel.

User-added image

look like it redirected inside iframe. using below code to redirect.
 
PageReference pageRef;
pageRef = new PageReference('/'+orderGroup.Id);
pageRef.setRedirect(true);
return pageRef;
Any help?
Best Answer chosen by sathishkumar periyasamy
sathishkumar periyasamysathishkumar periyasamy
Thanks for your response Amit.

Finally found root cause of this issue

Custom button "Behavior" should be "Display in existing window without sidebar or header"

User-added image

All Answers

Amit Singh 1Amit Singh 1
Hi Satish,

Use below code
PageReference pageRef;
String baseUrl = System.URL.getSalesforceBaseUrl().toExternalForm();
pageRef = new PageReference(baseUrl+'/'+orderGroup.Id);
pageRef.setRedirect(true);
return pageRef;

Looks like that it is not using Site URL.

Let me know if this helps :)

Thanks
sathishkumar periyasamysathishkumar periyasamy
Thanks for your response Amit.

Finally found root cause of this issue

Custom button "Behavior" should be "Display in existing window without sidebar or header"

User-added image
This was selected as the best answer