[SalesForce] Redirect from VisualForce page to the created record

On my VF page when I click on 'submit' button, I have pop-up with confirmation message. Then after clicked 'OK' button on this pop-up, I am redirected to the created record. Things are ok at this stage. Now I want conditional redirection when i'm in Classic or in Console mode. Actually when redirect to Console Mode I can't figure how to not display header and sidebar.

Thanks for any support/advice.

Below the codes :

Archive file

function parseSapExpressOrderResponse(obj,id){
if (obj.ErrorLines && obj.ErrorLines.length > 0) {
var s = ''; for (var i = 0; i < obj.ErrorLines.length; ++ i) s += '\n\t' + 
    obj.ErrorLines [i].Message
      alert(orderError + s);
       normalCursor ();
    }

    else {
      alert(orderSuccess + obj.PurchaseNumber__c);               
       window.location = '/'+id;
    }

VF page

<apex:actionFunction name="validateExpressOrder" action="
{!validateExpressOrder}" rerender="messages,hiddenParams"  
oncomplete="SForderCreated();" >
<!--    <apex:param name="jsonparam" value="{!jsonparam}" /> -->
        </apex:actionFunction> 

    </apex:PageBlock> <!-- class="globalSection" -->
 </div>
 </apex:form>

   <script type="text/javascript" src="{!URLFOR($Resource.ExpressOrderJS)}" 
  />
 </apex:page>

Best Answer

When you are in console mode you can check sforce.console.isInConsole() using Salesforce Console Integration Toolkit.

<apex:page standardController="Case">
    <A HREF="#" onClick="testIsInConsole();return false">
         Click here to check if the page is in the Service Cloud console</A> 

    <apex:includeScript value="/support/console/22.0/integration.js"/>
    <script type="text/javascript">
        function testIsInConsole() {
            if (sforce.console.isInConsole()) {
                  alert('in console');
               } else {
                  alert('not in console');
            }
        }
    </script>
</apex:page>

In your case, I hope this blog post will help.

How to open a new record inside a console in SubTab by inline visual force page

<script>

 var preRecordId;

        function testOpenSubtab(id, name) 
        {
            preRecordId= id;
            //First find the ID of the primary tab to put the new subtab in

            alert('URL----->'+'{!$CurrentPage.URL}');

             if (sforce.console.isInConsole())
                sforce.console.getEnclosingPrimaryTabId(openSubtab);
             else
              window.top.location.href = '/' + id;
        }

        var openSubtab = function openSubtab(result) 
        {
            //Now that we have the primary tab ID, we can open a new subtab in it
            var primaryTabId = result.id;

            sforce.console.openSubtab(primaryTabId , '/'+preRecordId , true, 
                preRecordId , null , openSuccess, 'salesforceSubtab');
        };

        var openSuccess = function openSuccess(result) 
        {
            //Report whether we succeeded in opening the subtab
            /*
                if (result.success == true) 
                {
                    alert('subtab successfully opened');
                } 
                else 
                {
                    alert('subtab cannot be opened');
                }
            */
        };



</script>
Related Topic