You need to sign in to do that
Don't have an account?
sf training 36
Can someone help me in writing test class for the following code
public class LPT_InterestAccrued_TriggerHandler {
public static void updateIAonLoan(List<loan__Loan_Payment_Transaction__c> lptNewData){
List<loan__Loan_Account__c> loanList = new List<loan__Loan_Account__c>();
List<loan__Loan_Payment_Transaction__c> lptList = [select id, loan__Cleared__c,
loan__Loan_Account__r.loan__Loan_Status__c,
loan__Loan_Account__r.loan__Interest_Accrued_Not_Due__c
from loan__Loan_Payment_Transaction__c where id in:lptNewData];
System.debug('Loan payment trsansactions list:====='+lptList);
for(loan__Loan_Payment_Transaction__c lpt: lptList){
System.debug('Loan payment trsansactions list:====='+lpt);
if(lpt.loan__Loan_Account__r.loan__Loan_Status__c=='Closed- Written Off')
{
loan__Loan_Account__c l = new loan__Loan_Account__c();
l.id = lpt.loan__Loan_Account__c;
System.debug('Loans:====='+l);
if(lpt.loan__Loan_Account__r.loan__Interest_Accrued_Not_Due__c!=0){
l.loan__Interest_Accrued_Not_Due__c=0;
loanList.add(l);
System.debug('Loans list:====='+loanList);
}
}
}
try{
update loanList;
}
Catch(Exception e){
System.debug('Exception Occurred:'+e);
}
}
}
public static void updateIAonLoan(List<loan__Loan_Payment_Transaction__c> lptNewData){
List<loan__Loan_Account__c> loanList = new List<loan__Loan_Account__c>();
List<loan__Loan_Payment_Transaction__c> lptList = [select id, loan__Cleared__c,
loan__Loan_Account__r.loan__Loan_Status__c,
loan__Loan_Account__r.loan__Interest_Accrued_Not_Due__c
from loan__Loan_Payment_Transaction__c where id in:lptNewData];
System.debug('Loan payment trsansactions list:====='+lptList);
for(loan__Loan_Payment_Transaction__c lpt: lptList){
System.debug('Loan payment trsansactions list:====='+lpt);
if(lpt.loan__Loan_Account__r.loan__Loan_Status__c=='Closed- Written Off')
{
loan__Loan_Account__c l = new loan__Loan_Account__c();
l.id = lpt.loan__Loan_Account__c;
System.debug('Loans:====='+l);
if(lpt.loan__Loan_Account__r.loan__Interest_Accrued_Not_Due__c!=0){
l.loan__Interest_Accrued_Not_Due__c=0;
loanList.add(l);
System.debug('Loans list:====='+loanList);
}
}
}
try{
update loanList;
}
Catch(Exception e){
System.debug('Exception Occurred:'+e);
}
}
}
Let us know if this will help you
All Answers
I will recommend you to start using trailhead to learn about test classes
1) https://trailhead.salesforce.com/modules/apex_testing
Pleasse check below post sample test class
1) http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html
Also please check below post
1) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
2) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_example.htm
You write a test class for this the same way that you would any other:
- Set up some data for the Apex Class to access (loan__Loan_Payment_Transaction__c, loan__Loan_Account__c etc)
- Execute a method/methods:-
- Verify the behaviour with asserts.
Please try below code
Let us know if this will help you
@isTest
public class LPT_InterestAccrued_TriggerHandlerTest
{
public static testMethod void testMethod1()
{
loan__Loan_Account__c loanList = new loan__Loan_Account__c();
loan__Loan_Account__c acc = new loan__Loan_Account__c();
acc.loan__Interest_Accrued_Not_Due__c = 100;
acc.loan__Loan_Status__c='Closed- Written Off';
insert acc;
loan__Loan_Payment_Transaction__c paymet = new loan__Loan_Payment_Transaction__c();
paymet.loan__Cleared__c= True;
paymet.loan__Loan_Account__c =acc.id;
insert paymet;
if(acc.loan__Loan_Status__c =='Closed- Written Off')
{
loan__Loan_Account__c l = new loan__Loan_Account__c();
l.id = acc.id;
System.debug('Loans:====='+l);
if(paymet.loan__Interest_Accrued_Not_Due__c!=0){
l.loan__Interest_Accrued_Not_Due__c=0;
loanList.add(l);
System.debug('Loans list:====='+loanList);
}
}
Update loanList;
System.assert(acc.id,loanList.id);
}
}
Let us know if this will help you