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'
Then the record saves, but doesn't close the VF page container and redirect.
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}"/>
<!--
<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;
}
}