In extension controller, when after execute StandardController.save(), i can get the newly created record Id using StandardController.getRecord(). BUT, the getRecord() method in test will not contain the Id.
is that because test is not commit? if so, how can i get the test pass?
any help would be appreciated.
here is my code:
public with sharing class accCtrl {
public ApexPages.StandardController stdCtrl;
public accCtrl(ApexPages.StandardController controller) {
stdCtrl = controller;
}
public PageReference save() {
PageReference pageRef = stdCtrl.save(); // Useyes, save()i insteadcan ofuse Insertupsert, tobut autoin enforcethis permissioncase, checki'm trying to use save().
system.debug(stdCtrl.getRecord()); // In actual run, can see the Id, but in test, can not.
return pageRef;
}
}
Test Class
@isTest
public class accCtrl_Test{
static testMethod void test() {
PageReference pf = Page.accTest ;
Test.setCurrentPage(pf);
Account acc = new Account(Name = 'Test Account');
accCtrl controller = new accCtrl(new ApexPages.StandardController(acc));
controller.save();
// use newly created id to do other things.
}
}