samedi 24 janvier 2015

How to write Test class for below class

How to write test class please help me


Public class CustomCaseAlertsController { public Case caseObj {get; set;} public boolean hasAlerts { get{ return (Alerts.size()==0? false: true); } set; }



public integer popupWindowHeight
{
get{ return (230+Alerts.size()*40); }
set;
}
private Set<ID> hattrixParentIds=new Set<ID>();
private Set<ID> queryAlertIds=new set<ID>();

public List<soalert__Hidden_Alert__c> Alerts {get; set;}
private List<Hattrix_Account__c> listOfHattrixParent=new List<Hattrix_Account__c>();
public List<soalert__Hidden_Alert__c> userSelectedAlerts=new List<soalert__Hidden_Alert__c>();

public CustomCaseAlertsController(ApexPages.StandardController stdController)
{
String caseId = stdController.getId();

Alerts = new List<soalert__Hidden_Alert__c>();
Map<Id, soalert__Hidden_Alert__c> mapAlertIdToWrapper = new Map<Id, soalert__Hidden_Alert__c>();

caseObj = [Select id,AccountId,ContactId,Site__c,Site__r.Name,CaseNumber from Case where id=:caseId];


for(Hattrix_Account__c idObj:[select id,Hatrix_Parent_Account__c from Hattrix_Account__c where Hatrix_Parent_Account__c =:caseObj.site__c or Hatrix_Parent_Account__c=:caseObj.accountID])
{
hattrixParentIds.add(idObj.id);
}


for(soalert__Alert__c alertObj: [SELECT Id,Name,soalert__Account__c,soalert__Account__r.Name,soalert__Contact__c,soalert__Contact__r.Name,soalert__Alert_Begin_Date__c,soalert__Alert_End_Date__c,soalert__Alert_Message__c,soalert__Alert_Status__c,soalert__Case__c,soalert__User__c FROM soalert__Alert__c
Where ((soalert__Case__c=:caseObj.Id or soalert__Account__c=:caseObj.AccountId or soalert__Account__c=:caseobj.Site__c or soalert__Account__c in:hattrixParentIds or soalert__Contact__c=:caseObj.ContactId) and (soalert__Alert_Begin_Date__c <= today and soalert__Alert_End_Date__c >= today))] )

{
soalert__Hidden_Alert__c alertWrapper = new soalert__Hidden_Alert__c();

alertWrapper.soalert__Alert__c=alertObj.Id;
alertWrapper.soalert__Hidden__c = false;
alertWrapper.soalert__Alert_Message__c = alertObj.soalert__Alert_Message__c;
alertWrapper.soalert__User__c = UserInfo.getUserId();

if(alertObj.soalert__Account__c != null)
{

alertWrapper.soalert__Object_ID__c=alertObj.soalert__Account__c;
alertWrapper.soalert__Object_Type__c=alertObj.soalert__Account__c.getSObjectType().getDescribe().getLabel();
alertWrapper.soalert__Record_Name__c = alertObj.soalert__Account__r.Name;
System.debug('alertObj.soalert__Account__c.getSObjectType().getDescribe().getLabel();'+alertObj.soalert__Account__c.getSObjectType().getDescribe().getLabel());
}
else if(alertObj.soalert__Contact__c !=null)
{

// alertWrapper.soalert__Object_Type__c=alertObj.soalert__Contact__c.getSObjectType().getDescribe().getLabel();
alertWrapper.soalert__Object_ID__c=alertObj.soalert__Contact__c;
alertWrapper.soalert__Object_Type__c=alertObj.soalert__Contact__c.getSObjectType().getDescribe().getLabel();
alertWrapper.soalert__Record_Name__c = alertObj.soalert__Contact__r.Name;


}
else if(alertObj.soalert__Case__c !=null)
{
System.debug('case');
//alertWrapper.soalert__Object_Type__c=alertObj.soalert__Case__c.getSObjectType().getDescribe().getLabel();
alertWrapper.soalert__Object_ID__c=alertObj.soalert__Case__c;
alertWrapper.soalert__Object_Type__c=alertObj.soalert__Case__c.getSObjectType().getDescribe().getLabel();
alertWrapper.soalert__Record_Name__c = caseObj.CaseNumber;// need to clarify

}

mapAlertIdToWrapper.put(alertObj.Id, alertWrapper);

//Alerts.add(alertWrapper);
}

for (soalert__Hidden_Alert__c hiddenObj: [Select id,soalert__Alert__c,soalert__User__c from soalert__Hidden_Alert__c
where (soalert__User__c=:UserInfo.getUserID() and soalert__Hidden__c=true
and soalert__Alert__c in : mapAlertIdToWrapper.KeySet())])
{
mapAlertIdToWrapper.remove(hiddenObj.soalert__Alert__c);
}

Alerts = mapAlertIdToWrapper.values();
}

public void hideAlerts()
{
//Method for hiding the selected alerts
for(soalert__Hidden_Alert__c c: Alerts)
{
if(c.soalert__Hidden__c==true )
{
userSelectedAlerts.add(c);
}
}

insert userSelectedAlerts;
}


}


I am new to salesforce please help me


Aucun commentaire:

Enregistrer un commentaire