You need to sign in to do that
Don't have an account?

Test class
Hi,
Please help me writing the testclass below as follows,
public class DonorDetailsController
{
public List<CommitmentDetails> commitmentDetailsList {get;set;}
public List<PaymentDetails> paymentDetailsList {get;set;}
public Preference__c preObj {get;set;}
public String contactId {get;set;}
public String preferenceId {get;set;}
public DonorDetailsController()
{
User oUser = [Select Id, ContactId From User Where Id=:UserInfo.getUserId()];
contactId = oUser.contactId;
preObj = new Preference__c();
getAllCommitmentDetails();
getAllPaymentDetails();
}
public class CommitmentDetails
{
public String childName {get;Set;}
public String projectName {get;set;}
public String commitmentType {get;set;}
public String commitmentStartDate {get;set;}
public String commitmentEndDate {get;set;}
public String perferenceId {get;set;}
public String childId {get;set;}
}
public class PaymentDetails
{
public Double amount {get;set;}
public Double opportunityAmount {get;set;}
public String paymentMode {get;set;}
public String paymentFrequency {get;set;}
public Date paymentStartDate {get;set;}
public Date paymentEndDate {get;set;}
public String paymentStatus{get;set;}
}
public void getAllCommitmentDetails()
{
commitmentDetailsList = new List<CommitmentDetails>();
for (Commitment__c oCommitment : [Select Id, Child__c, Child__r.Name, Start_Date__c, Project__c,
Project__r.Name, Commitment_Type__c, End_Date__c,
Preference__c, Status__c From Commitment__c Where Contact__c=:contactId])
//System.debug(oCommitment);
{
CommitmentDetails oCommitmentDetails = new CommitmentDetails();
oCommitmentDetails.childName = oCommitment.Child__r.Name;
oCommitmentDetails.projectName = oCommitment.Project__r.Name;
oCommitmentDetails.commitmentType = oCommitment.Commitment_Type__c;
oCommitmentDetails.commitmentStartDate = oCommitment.Start_Date__c != null ? oCommitment.Start_Date__c.format() : '';
oCommitmentDetails.commitmentEndDate = oCommitment.End_Date__c != null ? oCommitment.End_Date__c.format() : '';
oCommitmentDetails.perferenceId = oCommitment.Preference__c;
oCommitmentDetails.childId = oCommitment.Child__c;
commitmentDetailsList.add(oCommitmentDetails);
}
}
public void getAllPaymentDetails()
{
paymentDetailsList = new List<PaymentDetails>();
String opportunityId = [Select OpportunityId From OpportunityContactRole Where ContactId=:contactId limit 1].OpportunityId;
for (Payment_Schedule__c obj : [Select Amount__c, Payment_End_Date__c, Opportunity__r.Amount,
Payment_Frequency__c, Payment_Mode__c, Payment_Start_Date__c
From Payment_Schedule__c Where Opportunity__c=:opportunityId])
{
PaymentDetails oPaymentDetails = new PaymentDetails();
oPaymentDetails.amount = obj.Amount__c;
oPaymentDetails.opportunityAmount = obj.Opportunity__r.Amount;
oPaymentDetails.paymentMode = obj.Payment_Mode__c;
oPaymentDetails.paymentFrequency = obj.Payment_Frequency__c;
oPaymentDetails.paymentStartDate = obj.Payment_Start_Date__c;
oPaymentDetails.paymentEndDate = obj.Payment_End_Date__c;
paymentDetailsList.add(oPaymentDetails);
}
}
public void loadPreference()
{
preObj = [Select Id, Age_From__c, Age_To__c, Sex__c,
Continent__c, Country__c, Language__c, Religion__c
From Preference__c Where Id=:preferenceId];
System.debug( preObj + ' == ' );
}
}