2

I am trying to build a visualforce page which can work in salesforce and also salesforce1. I am trying to redirect after the action is completed it work just fine when i try it from desktop but from my salesforce1 app it don't work. i found out the javascript function which i am trying to call on oncomplete is not even invocking this fuction. please help.

<apex:page id="idPage" docType="html-5.0" showHeader="{!!isSF1}" sidebar="{!!isSF1}" applyBodyTag="{!!isSF1}" applyHtmlTag="{!!isSF1}" standardStylesheets="{!!isSF1}" standardController="Lead" extensions="leadConvertController">
    <script type='text/javascript' src='/canvas/sdk/js/publisher.js'></script>    
    <apex:includeScript value="{!URLFOR($Resource.Bootstrap, '/bootstrap-3.3.6-dist/js/bootstrap.min.js')}"></apex:includeScript>
    <style>
    .ui-mobile{
        min-height:200px;
    }
    </style>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script>
        function redirect(recordId) {
            //var url = "/{!Lead.Id}";
            system.log('Redirect: ' + recordId);
            if (typeof sforce !== 'undefined'){ 
                sforce.one.navigateToSObject(recordId); 
            } else { 
                //.top to deal with the fact that publisher actions in chatter feed are iframe 
                window.top.location.href= "/" + recordId; 
            } 


            //if ( (typeof sforce.one) !== "undefined" && sforce.one !== null ) {
            //    sforce.one.back(true);                
            //  //parent.frames.location.replace(url)
            //  //window.Location=url;
            //}
            //else {
            //    parent.frames.location.replace(url); 
            //  //sforce.one.back(true);
            //  //sforce.one.navigateToURL(url);
            //  //sforce.one.navigateToSObject(url,'detail');
            //}         
        }
       jQuery(document).ready(function($){
           //$('[class$=OutputTextClass]').attr("disabled",true);
           $('.OutputTextClass').attr("disabled",true);
       });
    </script>
    <apex:stylesheet value="{!URLFOR($Resource.Bootstrap,'/css/bootstrap-namespaced.min.css')}"/>
    <apex:outputPanel rendered="{!isOnError}" id="idOPMessage">
        <apex:form id="idFormErrorMessage">
            <apex:outputLabel value="{!ErrorMessage}" escape="false"></apex:outputLabel><BR/>
            <apex:commandButton action="{!Back}" rendered="{!ShowBack}" value="Back" onClick="redirect('{!Lead.Id}');"/>
            <apex:commandButton action="{!Ok}" rendered="{!ShowOk}" value="Ok" onClick="redirect('{!accountID.Id}');"/>
            <!--apex:commandButton action="{!Back}" value="Back" onClick="redirect();"/-->
        </apex:form>
    </apex:outputPanel>
    <apex:outputPanel rendered="{!!isOnError}" id="idOPContent"> 
        <apex:outputPanel rendered="{!!isSF1}">
            <!-- Page section header -->
            <apex:sectionHeader title="Convert Lead" subtitle="{!Lead.name}"/>
            <!-- Visualforce Component with custom page header text -->
            <!--c:leadConvertPageHeaderTextComponent /-->
            <!-- This form tag must include any fields or buttons used in the Lead Convert operation -->         
            <apex:form id="theForm" >
                <!-- This pageBlock component is a container that includes the visual elements of the Lead Convert page -->
                <!-- All custom Components should be included within this pageBlock unless you are using more advanced custom styling -->
                <apex:pageBlock mode="edit" id="pageBlock">        
                    <!-- This component is used to display error messages on the page -->                  
                    <apex:pageMessages />                  
                    <!-- This pageBlockButtons component is where you can add / remove custom buttons from the Lead Convert page -->           
                    <apex:pageBlockButtons >               
                        <apex:commandButton action="{!convertLead}" value="Convert"/>
                        <apex:commandButton action="{!cancel}" value="Cancel"/>                    
                    </apex:pageBlockButtons>                       

                    <apex:pageBlockSection id="pblockconvertLead" title="Convert Lead" collapsible="no" columns="1">

                        <!-- Leads Record Owner -->
                        <apex:pageBlockSectionItem >
                            <apex:outputLabel value="Record Owner" for="recordOwner" />
                            <apex:inputField value="{!contactId.ownerID}" id="recordOwner" />
                        </apex:pageBlockSectionItem>

                        <!-- Checkbox indicating whether to send an email to the owner -->    
                        <!--apex:pageBlockSectionItem >
                            <apex:outputLabel value="Send Email to the Owner" for="sendOwnerEmail" />
                            <apex:inputCheckbox value="{!sendOwnerEmail}" id="sendOwnerEmail" />
                        </apex:pageBlockSectionItem-->


                        <apex:pageBlockSectionItem id="convertLeadAccountBlockSectionItem" >
                            <apex:outputLabel value="Account Name" for="accountId" />
                            <apex:outputField value="{!accountID.Name}" id="accountId" />
                        </apex:pageBlockSectionItem>

                        <!-- Opportunity section -->
                        <apex:pageBlockSectionItem id="oppSection" >

                            <apex:outputPanel id="oppPanel" >
                                <apex:outputLabel value="Opportunity Name" for="opportunityName" />
                            </apex:outputPanel>


                            <apex:outputPanel id="opportunityPanel" layout="block">
                                <apex:outputPanel rendered="{!NOT(doNotCreateOppty)}" styleClass="requiredInput" id="block">
                                <div class="requiredBlock"></div>

                                <!-- Opportunity Name -->
                                <apex:inputField required="false" 
                                    value="{!opportunityID.Name}" id="opportunityName"/>
                                </apex:outputPanel>

                                <!--  This is only shown if the Do Not Create Opportunity is true -->    
                                <apex:inputText disabled="true" rendered="{!doNotCreateOppty}"  value="{!opportunityID.Name}" id="opportunityNameDisabled"/>
                                <apex:outputPanel layout="block" styleClass="requiredInput">
                                <apex:outputPanel layout="block" />

                                <!-- Checkbox indicating whether to create an Opportunity -->
                                <apex:inputCheckbox value="{!doNotCreateOppty}" id="doNotCreateOppty">
                                    <apex:actionSupport event="onchange" 

                                        rerender="opportunityPanel"
                                         />
                                </apex:inputCheckbox>
                                Do not create a new opportunity upon conversion.
                            </apex:outputPanel> 
                            </apex:outputPanel>
                        </apex:pageBlockSectionItem>

                        <!-- Converted Status -->
                        <!--apex:pageBlockSectionItem >
                            <apex:outputLabel value="Converted Status" for="leadStatus" />
                            <apex:outputPanel styleClass="requiredInput" layout="block">
                                <div class="requiredBlock"></div>
                                <apex:selectList id="LeadStatusList" size="1" 
                                    value="{!LeadToConvert.Status}" multiselect="false" required="true">
                                    <apex:selectOptions value="{!LeadStatusOption}"/>
                                </apex:selectList> 
                            </apex:outputPanel>
                        </apex:pageBlockSectionItem-->
                    </apex:pageBlockSection>
                </apex:pageBlock>
            </apex:form>       
        </apex:outputPanel>    
        <apex:outputPanel rendered="{!isSF1}" id="opSF1">
            <head>          
                <meta charset="utf-8" />
                <meta name="apple-mobile-web-app-capable" content="yes" />
                <!-- jQuery Mobile -->
                <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
                <apex:stylesheet value="https://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" />
                <apex:includeScript value="https://code.jquery.com/jquery-1.9.1.min.js" />
                <apex:includeScript value="https://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js" />
                <!-- Salesforce1 -->
                <apex:includeScript value="/canvas/sdk/js/publisher.js" />                
            </head>


            <body>          
                <div data-role="page">
                    <!--h1>{!$ObjectType.Lead.Label}: <small>{!Lead.name}</small></h1-->
                    <div data-role="content">
                        <div data-role="popup" id="statusPopupID" class="ui-content" data-overlay-theme="a">
                            Please Wait...<br/>
                            <img src="{!$Resource.ProgressBar}"/>
                        </div>
                        <apex:form id="idFormSF1">
                            <center>
                                <!--apex:pageBlockButtons -->               

                                     <!--apex:commandButton value="Convert" action="{!convertLead}" status="closer"/-->
                                     <!--apex:commandButton action="{!convertLead}" value="Convert" reRender="redirect('{!accountID.Id}'); "/-->
                                      <!--apex:commandButton value="Convert" action="{!convertLead}" onComplete="redirect('{!accountID.Id}'); retun false;"/-->
                                   <apex:commandButton action="{!convertLead}" value="Convert" onComplete="redirect('{!accountID.Id}'); return false;"/>
                                    <!--apex:actionStatus startText="(Saving...)" stopText="" onStop="redirect();" id="closer"/-->
                                    <!--apex:actionFunction reRender="idPage" action="{!convertLead}" name="CallConvert" id="CallConvert" /-->

                                <!--/apex:pageBlockButtons--> 
                            </center>

                            <label for="OwnerValueID">Record Owner </label> <br/>                                   
                            <apex:inputField value="{!contactId.ownerID}" id="OwnerValueID" styleClass="OutputTextClass"/> <br/>

                            <label for="AccountNameID">Account Name </label> <br/>                                           
                            <apex:inputField value="{!accountId.Name}" id="AccountNameID" styleClass="OutputTextClass"/> <br/>              

                            <label for="OpportunityNameID">Opportunity Name</label> <br/>                                   
                            <apex:inputField value="{!opportunityID.Name}" id="OpportunityNameID"/> <br/>
                        </apex:form>
                    </div>
                </div>
            </body>
        </apex:outputPanel> 
    </apex:outputPanel>
</apex:page>


17:34:28.142 (1142728575)|USER_DEBUG|[175]|DEBUG|leadConvertResult : Database.LeadConvertResult[getAccountId=0014B000004TFeNQAW;getContactId=0034B000‌​003lE0fQAE;getErrors=();getLeadId=00Q4B000001SWDlUAO;getOpportunityId=0064B000002‌​WxdfQAC;isSuccess=true;] 
17:34:28.178 (1178579313)|USER_DEBUG|[187]|DEBUG|Redirect : System.PageReference[/0014B000004TFeN] 
17:34:28.178 (1178716268)|SYSTEM_MODE_EXIT|false 
17:34:28.313 (1313965307)|CODE_UNIT_FINISHED|leadConvertController invoke(convertLead)
4
  • If an error is thrown in your code and you do not display it in a page message component then you may be missing an error which IIRC will cause the oncomplete to no be fired. Take a step back, write a page that has a single button with the JS code. Get that button to work then debug from there. If you get the button working alone you will be more confident / focused in your debugging knowing that it is not the button that is the issue. Oh and is AccountID.id an actual thing? Why is the var named AccountiD if it is not an id?
    – Eric
    Dec 28, 2015 at 19:26
  • Thank for reply Brian, actually i am getting the account value in my function. function is being called but i dont knwo why page is not redirecting to account page. see the logs
    – user9982
    Dec 28, 2015 at 19:36
  • 17:34:28.142 (1142728575)|USER_DEBUG|[175]|DEBUG|leadConvertResult : Database.LeadConvertResult[getAccountId=0014B000004TFeNQAW;getContactId=0034B000003lE0fQAE;getErrors=();getLeadId=00Q4B000001SWDlUAO;getOpportunityId=0064B000002WxdfQAC;isSuccess=true;] 17:34:28.178 (1178579313)|USER_DEBUG|[187]|DEBUG|Redirect : System.PageReference[/0014B000004TFeN] 17:34:28.178 (1178716268)|SYSTEM_MODE_EXIT|false 17:34:28.313 (1313965307)|CODE_UNIT_FINISHED|leadConvertController invoke(convertLead)
    – user9982
    Dec 28, 2015 at 19:38
  • Your comment is in contradiction to what you say is your questions: i found out the javascript function which i am trying to call on oncomplete is not even invocking this function So which is correct?
    – Eric
    Dec 28, 2015 at 19:39

0

You must log in to answer this question.

Browse other questions tagged .