You need to sign in to do that
Don't have an account?
praveen kumar 110
pubic class GSkController {
public GSkController (ApexPages.StandardSetController setController)
{
if(caseID!=null && caseId!='')
{
for(String strCaseId : caseId.split(','))
{
lstSelectedCaseIds.add(strCaseId);
}
if(lstSelectedCaseIds!=null && lstSelectedCaseIds.size()>0)
{
lstSelectedCase = [select Id,Contact.Id,Contact.Name, Status from Case where ID in : lstSelectedCaseIds];
System.debug('lstSelectedCase******'+lstSelectedCase[0].Contact.Id);
// "contact id is getting null"
}
}
------------------------------------------------------------------------------------------------
Test Class:
@isTest(seeAllData=true)
private class TestGSkController {
static testMethod void MyunitTest()
{
Profile p = [select id, name from Profile where name = 'System Administrator'];
User u = new User(Alias = 'standt', Email='standarduser@testorg.com',
EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p.Id,
TimeZoneSidKey='America/Los_Angeles', UserName='standarduser@testorg.com');
Insert u;
System.runAs(u)
{
Contact conTestContact = new contact();
conTestContact.name='test';
insert conTestContact;
System.debug('conTestContact***************'+conTestContact.id); // I am getting Id
Case ObjCase=new Case();
ObjCase.Name='test';
objCase.Contact=conTestContact;
insert objcase;
System.debug('objcase***********'+objcase.contact.id); // I am getting id value
pageReference.getParameters().put('id',ObjCase.id);
GSkController ObjKey = new GSkController(new ApexPages.StandardSetController(Database.getQueryLocator([select Id,Contact.id from Case where ID =:ObjCase.id])));
}
}
}
I am getting in null while running test class ,I have inserted proper data also but getting null ,Please any check it bleow help me out....?
pubic class GSkController {
public GSkController (ApexPages.StandardSetController setController)
{
if(caseID!=null && caseId!='')
{
for(String strCaseId : caseId.split(','))
{
lstSelectedCaseIds.add(strCaseId);
}
if(lstSelectedCaseIds!=null && lstSelectedCaseIds.size()>0)
{
lstSelectedCase = [select Id,Contact.Id,Contact.Name, Status from Case where ID in : lstSelectedCaseIds];
System.debug('lstSelectedCase******'+lstSelectedCase[0].Contact.Id);
// "contact id is getting null"
}
}
------------------------------------------------------------------------------------------------
Test Class:
@isTest(seeAllData=true)
private class TestGSkController {
static testMethod void MyunitTest()
{
Profile p = [select id, name from Profile where name = 'System Administrator'];
User u = new User(Alias = 'standt', Email='standarduser@testorg.com',
EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p.Id,
TimeZoneSidKey='America/Los_Angeles', UserName='standarduser@testorg.com');
Insert u;
System.runAs(u)
{
Contact conTestContact = new contact();
conTestContact.name='test';
insert conTestContact;
System.debug('conTestContact***************'+conTestContact.id); // I am getting Id
Case ObjCase=new Case();
ObjCase.Name='test';
objCase.Contact=conTestContact;
insert objcase;
System.debug('objcase***********'+objcase.contact.id); // I am getting id value
pageReference.getParameters().put('id',ObjCase.id);
GSkController ObjKey = new GSkController(new ApexPages.StandardSetController(Database.getQueryLocator([select Id,Contact.id from Case where ID =:ObjCase.id])));
}
}
}
To put parameters in page, you need to set current page with your page. See the code below, I have set the current page at line no 27, replace YourPageName with the name of the page. Let me know, if you need any other help.
Thanks,
Neetu
Event i have given "Test.setCurrentPageReference(new PageReference('Page.YourPageName'));" in Test class,after Running the class ,what ever the contact id putting in test class , not getting class ...i amgettin as "Null" ....what was the mistake i done, dont know.
Please help me out.
Thanks,
Praveen.
I think you are not setting the page name properly, let's suppose your page name is CaseView, then use the code like this: Try this, it will definately resolve your problem.
Thanks,
Neetu