Salesforce大師:無法驗證保存新記錄
我正在寫一個Salesforce Visualforce頁面擴展控制器來實現其中的驗證和其他biz邏輯。但是,我的代碼不能按預期工作。看來驗證子類別和序列號的代碼永遠不會到達。儘管我在VF頁面中有輸入值,但系統調試日誌顯示子類別始終爲空。你能幫忙嗎?非常感謝你!
public class CaseCreationExtension {
ApexPages.StandardController stdCtrl;
Case newCase;
public CaseCreationExtension(ApexPages.StandardController controller){
if (!Test.isRunningTest()){
controller.addFields(new List<String>{'Categ__c', 'Sub_Category__c', 'Id', 'Serial_Number__c', 'Refund_Required__c', 'Total_Value__c', 'Per_Month__c'});
system.debug('AddFields');
}
system.debug('Initial Controller');
this.stdCtrl = controller;
newCase = (Case)stdCtrl.getRecord();
system.debug('AccountId' + newCase.AccountId);
}
public PageReference validateSaveRedirect(){
system.debug('Sub Category:' + newCase.Sub_Category__c);
system.debug('Serial Number:' + newCase.Serial_Number__c);
if(newCase.Sub_Category__c == 'Cancellations' && newCase.Serial_Number__c == null){
system.debug('Adding error message');
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error: Serial Number must be specified for cancellation case.');
ApexPages.addMessage(myMsg);
system.debug('finished Adding error message');
return null;
}else{
if(null==stdCtrl.save()){
return null;
}
/*try{
stdCtrl.save();
}
catch(system.Exception e){
ApexPages.Message msg = new apexPages.Message(Apexpages.Severity.ERROR, e.getdmlMessage(0));
ApexPages.addMessage(msg);
return null;
}*/
stdCtrl.save();
system.debug('New Case Id:' + newCase.Id);
PageReference pr = new PageReference('/' + newCase.Id);
pr.setRedirect(true);
return pr;
}
}
public PageReference cancelRedirect(){
stdCtrl.cancel();
system.debug('New Case Id:' + newCase.Contact);
PageReference pr = new PageReference('/' + newCase.Contact);
pr.setRedirect(true);
return pr;
}
}
感謝,EYESCREAM,我已經找到了ID不是可供查閱。謝謝你回覆我的問題。 –