0

I'm having an issue with this visualforce page. I'm able to save the record with my logic, but it won't listen to redirect to the 'saveRecord' method in the class. When I select a record, it does save it but doesn't close and redirect the page to the previous page. Any help would be wonderful. Thanks ahead of time!

Before I click 'Save'

https://i.sstatic.net/iwmUb.jpg


Then the record saves, but doesn't close the VF page container and redirect.

https://i.sstatic.net/6Z7Bj.jpg



VF Page:

<apex:page standardController="Lab__c" extensions="MassAssociateController" showHeader="false" standardStylesheets="false" sidebar="false" applyHtmlTag="false" applyBodyTag="false" docType="html-5.0">
<html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">  

<apex:includeScript value="/soap/ajax/35.0/connection.js"/>
<apex:includeScript value="/soap/ajax/35.0/apex.js"/>
<apex:includeScript value="/canvas/sdk/js/publisher.js"/>
<apex:stylesheet value="{!URLFOR($Resource.SLDS092, 'assets/styles/salesforce-lightning-design-system-vf.css')}" />           
<apex:stylesheet value="{!URLFOR($Resource.SLDS092, 'assets/styles/salesforce-lightning-design-system.css')}" />

<apex:form >

<div class="slds">
        <div class="slds-page-header" role="banner">
          <div class="slds-grid">
            <div class="slds-col slds-has-flexi-truncate">
              <div class="slds-media">
                <div class="slds-media__figure">
                  <svg aria-hidden="true" class="slds-icon slds-icon--large slds-icon-standard-user">
                      <use xlink:href="{!URLFOR($Resource.slds092, 'assets/icons/custom-sprite/svg/symbols.svg#custom58')}" />
                  </svg>
                </div>
        <div class="slds-media__body">
            <p class="slds-text-heading--label">{!Lab__c.Name}</p>
                <div class="slds-grid">
                    <h1 class="slds-table slds-table--bordered slds-max-medium-table--stacked-horizontal" title="Record Title">Equipment Association</h1>
                <div class="slds-col slds-shrink-none">             
            </div>
          </div>
        </div>
      </div>
    </div>
    </div>
    <br />   

 <nav role="navigation">
  <p id="bread-crumb-label" class="slds-assistive-text"></p>
  <ol class="slds-breadcrumb slds-list--horizontal" aria-labelledby="bread-crumb-label">
    <li class="slds-list__item slds-text-heading--label">{!Lab__c.Account_Name_VF__c}</li>
  </ol>
</nav> 
</div>
</div>


<apex:PageBlock >   
  <div align="center" draggable="false">        
              <apex:commandbutton style="float:centre" styleClass="slds-button slds-button--brand" value="Save" action="{!saveRecord}"/>             
               <!-- &nbsp; &nbsp;
              <apex:commandbutton style="float:centre" styleClass="slds-button slds-button--brand" value="Cancel" action="{!cancel}"/> -->                                         
  </div>

  <script>
  if((typeof sforce != 'undefined') && (sforce != null) ) {
  sforce.one.navigateToSObject(recId,'detail');
  }
  </script>

</apex:PageBlock>



  <apex:pageBlock >      

      <apex:pageBlockTable styleClass="slds-table slds-table--bordered" value="{!cb}" var="Equipment">



          <apex:column >

          <apex:inputCheckBox value="{!Equipment.s}"/>





          </apex:column>

          <apex:column value="{!Equipment.t.Name}"/>

          <apex:column value="{!Equipment.t.Account_Name__c}"/>

          <apex:column value="{!Equipment.t.Product_Category__c}"/>

          <apex:column value="{!Equipment.t.System_Manufacturer__c}"/>

          <apex:column value="{!Equipment.t.Version_Type__c}"/>

          <apex:column value="{!Equipment.t.Warranty_Status__c }"/>

      </apex:pageBlockTable>



  </apex:pageBlock>

  </apex:form>
</html>
</apex:page>


Apex Controller:

public class MassAssociateController {
    string recId;
    /*public String getsaveRecord() {
        system.debug('this is test method');
        return null;
    }*/

    public list<Equipment__c> equip{get;set;}
    public List<checkbox> cb{get;set;}

    public MassAssociateController(ApexPages.StandardController controller) {
        recId = controller.getRecord().Id;

        cb=getData();

    }

    public List<checkbox> getData(){
        Lab__c recName=[SELECT Account_Name__c FROm Lab__c WHERE Id =:recId];  

        equip = [SELECT Name, Account_Name__c,Account_Name__r.Name, Product_Category__c, System_Manufacturer__c, Version_Type__c, Warranty_Status__c FROM Equipment__c WHERE Account_Name__c=:recName.Account_Name__c AND Account_Name__c != NULL AND Lab__c =null  ];

        cb = new List<checkbox>();

        for(Equipment__c pe: equip) {
            cb.add(new checkbox(false,pe));
        }

        return cb;
    }

    public class checkbox{

        public Boolean s{get;set;}
        public Equipment__c t {get;set;}

        public checkbox(Boolean s,Equipment__c t){        
            this.s=s;
            this.t=t;
        }
    }

     public pageReference saveRecord(){  

        PageReference pageRef = new PageReference('/'+recId);
        pageRef.setredirect(true);


        List<Equipment__c> lstEqu = new  List<Equipment__c>();
        system.debug('cb======='+cb);
        system.debug('recId===='+recId);

        for(checkbox wapper:cb ){
            system.debug('wapper.s======='+wapper.s);
            // check this record is selected or not
            if(wapper.s == true){
                lstEqu.add(wapper.t);// selected records are add to list        
            }
        }

        for(Equipment__c obj:lstEqu){

            obj.Lab__c= recId;

        }

        update lstEqu;
        return pageRef;
     }

    public pageReference cancelRecord(){

        PageReference pageRef = new PageReference('/'+recId);
        pageRef.setredirect(true);

        return pageRef;

    }

   }

1 Answer 1

0

You should add an onComplete action to your apex:commandbutton you can then either use JS or jQuery to refresh the page if it's not working correctly with setredirect()

Check this out: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_commandButton.htm

3
  • I tried that with a script tag, and instead it redirected the page back (to the correct page), but the Classic version instead of the SF1 version of it. Code: <script> 'function myFunction(){ sforce.one.back(true); } </script> Commented Jan 14, 2016 at 19:51
  • Result: imgur.com/gallery/oxzuekP Commented Jan 14, 2016 at 19:55
  • @JoshuaDavis hmmmmm have a look here: help.salesforce.com/apex/… they mention using a different format for SF1 links "salesforce1://sObject/001D000000Jwj9v/view"
    – Tim
    Commented Jan 14, 2016 at 21:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .