You need to sign in to do that
Don't have an account?
Rakesh Imsani
How to write test class for this class Please help me..
Public class CustomCaseAlertsController
{
public CustomCaseAlertsController(ApexPages.StandardController stdController)
{
//how to get id here
//how to populate account look up in case obj... please help me
String caseId = stdController.getId();
caseObj = [Select id,AccountId,ContactId,CaseNumber from Case where id=:caseId];
......................................
................................
}
public void hideAlerts()
{
insert ListObj;
}
}
{
public CustomCaseAlertsController(ApexPages.StandardController stdController)
{
//how to get id here
//how to populate account look up in case obj... please help me
String caseId = stdController.getId();
caseObj = [Select id,AccountId,ContactId,CaseNumber from Case where id=:caseId];
......................................
................................
}
public void hideAlerts()
{
insert ListObj;
}
}
Suppose that if u have standard controller for Account :
Case caseObj = new Case();
//Fill data of case
insetr caseObj;
ApexPages.StandardController sc = new ApexPages.StandardController(caseObj);
CustomCaseAlertsController CCAC = new CustomCaseAlertsController(sc);
:::======================================================================:::
Qusetion Solved ? then mark as best answer to make helpful to others .....
Here is more about for u ...
http://salesforce.stackexchange.com/questions/39978/need-help-with-test-class-with-apexpages-currentpage-getparameters-id
This is extension for Case object
while i am populating account name look up in case object i am getting
System.NullPointerException: Attempt to de-reference a null object in test class exception
@isTest(SeeAllData=true)
Public Class CustomCaseAlertsControllerTest
{
static testmethod void myTest()
{
Case cObj=new Case();
cObj.Account.Name='Rakesh'; // here i am getting System.NullPointerException: Attempt to de-reference a null object in test class
cObj.Contact.Lastname='Yadav';
--------------------------------------
-------------
}
}
u r on wrong way ...
Account acc = new Account(name = 'Rakesh');
insert acc;
Case cObj=new Case();
cObj.AccountId = acc.id ; // here i am getting System.NullPointerException: Attempt to de-reference a null object in test class
Now u can try this one..
Error is on your code is that you are putting directly name in "cObj.Account.Name" ..
Qusetion Solved ?
i am getting one more error, can you plese help one more time
System.DmlException: Insert failed. First exception on row 0 with id a29R00000005OICIA2; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]
@isTest(SeeAllData=true)
Public Class CustomCaseAlertsControllerTest
{
static testmethod void myTest()
{
Account a =new Account();
a.name='Rakesh';
a.Type='Other';
a.Phone='89898989';
a.Bill_to_State__c='TG';
insert a;
//Pagereference ref = new Pagereference('apex/CustomAlertPopup?id=500R0000004pbU8');
//ref.getParameters().put('case',std.getId());
Case cObj=new Case();
cObj.AccountId =a.id ;
cObj.Origin='Phone';
cObj.Priority='Low';
cObj.status='Solving';
cObj.Subject='Test class';
insert cObj;
// cObj=[Select id,AccountId,ContactId,Site__c,Site__r.Name,CaseNumber,Account.name,contact.name,Origin,Priority,status,Subject from case where Id='500R0000004pbU8' ];
Hattrix_Account__c hattObj=new Hattrix_Account__c();
hattObj=[select id,Hatrix_Parent_Account__c from Hattrix_Account__c limit 1];
soalert__Hidden_Alert__c hideAlertObj=new soalert__Hidden_Alert__c();
List<soalert__Hidden_Alert__c> listObj =new List<soalert__Hidden_Alert__c>();
listObj=[Select soalert__Alert__c,soalert__Alert_Message__c,soalert__Object_ID__c,soalert__Record_Name__c,soalert__User__c from soalert__Hidden_Alert__c limit2 ];
test.starttest();
ApexPages.StandardController std =new ApexPages.StandardController(cObj);
CustomCaseAlertsController testObj=new CustomCaseAlertsController(std);
PageReference pageRef = Page.CustomAlertPopup;
pageRef.getParameters().put('id', String.valueOf(cObj.Id));
Test.setCurrentPage(pageRef);
testObj.hideAlerts();
insert listObj; // System.DmlException: Insert failed. First exception on row 0 with id a29R00000005OICIA2; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id] here
test.stoptest();
}
}
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000AwM4
Its big class bud. But error is that u r querfying and put list in "listObj" and u r inserting this.
U know that we can't insert record with id, we can only upsert or update .
Tq very much