• Hiral Shah 16
  • NEWBIE
  • 10 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 2
    Replies
Hii Experts,
Please help me to write apex test class...
Apex class is here...
public Pagereference save(){
       system.debug('2');
       tax.Resource__c=user[0].id;
       try{
           insert tax;
           //statusM = true; 
           ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Thank you!Record saved'));
           
       }
       catch(Exception ex){
           ApexPages.addMessages(ex);
           return null;
       }
       
       ITax=[select id,Rent_paid_to_landlord__c,Leave_travel_concessions_or_assistance__c,Employees_PF__c,
                           Interest_payable_paid_to_lender__c,Children_s_Education_Fee__c,PPF__c,Insurance_Premium__c,
                           NSC__c,Deduction_under_Pension_scheme__c,Housing_loan_principal_repayment__c,ELSS_Mutual_Fund__c,
                           NPS__c,Payment_for_Medical_Insurance_Premium__c,Medical_treatment_for_handicapped__c,
                           Medical_for_specified_diseases__c,Education_Loan_Interest_Repayment__c,Interest_on_loan_taken_for_house__c,
                           Donation__c,Rent_deduction_only_if_HRA_not_received__c,Saving_interest__c,Rebate_of_Rs_2000__c,RGESS__c,
                           Royalty__c,Professional_Development_Allowance__c,Car_Maintenance_Allowance__c,
                           Conveyance_Allowance__c,Helper_Allowance__c,Telephone_Internet_allowance__c,
                           Tax_by_previous_employer__c,TDS_already_deducted_by_Current_Company__c,Donation_to_Other__c
                           from Income_Tax__c where id=:tax.id];
       If(ITax.Rent_paid_to_landlord__c!=null){
           Attachment a = new Attachment(parentid=ITax.id, Name = 'Rent paid to landlord.jpeg' , Body = myfile.body);
           try {insert a;}
           catch(Exception ex){
               ApexPages.addMessages(ex);
               return null;
           }
       }
       
       If(ITax.Leave_travel_concessions_or_assistance__c!=null){
           Attachment a1 = new Attachment(parentid=tax.id, Name = 'Leave travel concessions or assistance.jpeg', Body = myfile1.body);
           try {insert a1;}
           catch(Exception ex){
               ApexPages.addMessages(ex);
               return null;
           }
       }
       
       If(ITax.Interest_payable_paid_to_lender__c!=null){
           Attachment a2 = new Attachment(parentid=tax.id, Name = 'Interest payable paid to lender.jpeg' , Body = myfile2.body);
           try {insert a2;}
           catch(Exception ex){
               ApexPages.addMessages(ex);
               return null;
           }
       }


The code which i have written not covering if condition please help me.
@isTest
   public static void rentPaidToLord() {
      
       system.debug('hii=====');
       Resource__c res=new Resource__c();
       res.Name='Test';
       res.Emp_ID__c=201;
       res.Joining_Date__c=Date.newInstance(2019,1,1);
       insert res;
       system.debug('====res===='+res);
       
       Income_Tax__c rentPaidToLordTax = new Income_Tax__c();
       rentPaidToLordTax.Rent_paid_to_landlord__c = 12345;
       rentPaidToLordTax.Resource__c=res.Id;
       rentPaidToLordTax.Leave_travel_concessions_or_assistance__c=600;
       Insert rentPaidToLordTax;
       
       system.debug('++++++dcbsd++++++'+rentPaidToLordTax);
       system.debug('=======rent======'+rentPaidToLordTax.Rent_paid_to_landlord__c);
       test.startTest();
       PageReference pageRef = Page.IncomeTaxPage;
       Test.setCurrentPage(pageRef);
       pageRef.getParameters().put('name',res.name);
       ApexPages.StandardController sc = new ApexPages.standardController(rentPaidToLordTax);
       Taxclass tc = new Taxclass (sc);
       system.debug('success==============');
       tc.save();
       List<Attachment> at = [SELECT id FROM Attachment WHERE parentid=:rentPaidToLordTax.id AND Name = :'Rent paid to landlord.jpeg'];
       //System.assert(at.isEmpty()!=null);
       system.assert(Apexpages.hasMessages());

       test.stopTest();
   }

Thank you
Regards,
Hiral
Hey Frieds,
how i can access the Month wise records of custom_Object2__c using lightining component on custom_Object1__c.
where  have From_Date__c and to_Date__c fields on custom_Object1__c.
and count all records of that month and put the number in count__c field on custom_Object1__c.
If any query please ask me.

Please suggest me any link/code.

Thanks in advace
Regards,
Hiral
Hello guys help me to write test class for the apex class
Hii Guys,

I want to calaculate Total Leaves for the particular month taken by Resource
I have 3 custom object
1 ) Resource__c
2 ) Month__c has master detail with Resource__c,Number field Leaves_Taken__c
3) Leave__c has lookup with Resource__c , Leave_Date__c, picklist Decision__c(Approved/Rejected).

Need to create  future call & write a function which looks at all Leaves & each time calculates & updates Month__c object records if there is a change.

If the Decision__c is Approved then want to achieve following condition.
1) If Leaves are taken on both Friday & Monday, then 4 leaves to be added in Leaves_Taken__c field ( In Month__c object) for that particulr Month.
2) If Leaves are taken from Monday to Friday, then 9 Leaves to be added in Leaves_Taken__c field ( In Month__c object) for that particulr Month.
3) If single day taken leaves then 1 to be added in the Leaves_Taken field for that Month.
4) On Delete of Leave__c decrement will happen in Leaves_Taken__c.
5) On update of Leave__c repested action will happen.(increment/decrement).

Please help me to write this code.
Reply me!
Its urgent.
If any query plzz ask me!
Thanks you so much!
Regards,
Hiral.
In this Leave and the Resource are custom object. Leave has lookup relationship with Resource . Leave has the custom field Leaves__c. For the one Resource total Leaves__c will be calculated in Total_Used_Paid_Leaves__c (custom field) in Resource__c object.

my apex trigger

trigger LeaveTrigger on Leave__c (after insert,after update) {
    
    if(trigger.isInsert || trigger.isUpdate){
        HRLeaveController.getTotalLeaves(Trigger.New);
     
    }
}
Apex class code
public class HRLeaveController{
    
    public static void  getTotalLeaves(List<Leave__c> newLeaves){
        Set<ID> resId = new Set<ID>();
        List<Resource__c> listRes = new List<Resource__c>();
        List<Resource__c> updateRes = new List<Resource__c>();
        
        for(Leave__c lev : newLeaves){
            resId.add(lev.Resource__c);
        }
        
        if(resId.size() > 0){
            listRes = [select Id,Total_Used_Paid_Leaves__c ,(select Id,Leaves__c from Leaves__r) from Resource__c where Id IN : resId];
        }
        
        for(Resource__c resrc : listRes){
            Decimal val = 0;
            for(Leave__c levs : resrc.Leaves__r){
                
                val += levs.Leaves__c;
                System.debug('**val**'+val);
            }
            resrc.Total_Used_Paid_Leaves__c = val;
            updateRes.add(resrc);
        }
        
        if(!updateRes.isEmpty()){
            update updateRes;
        }
    }
}
 
Hii Guys,

I want to calaculate Total Leaves for the particular month taken by Resource
I have 3 custom object
1 ) Resource__c
2 ) Month__c has master detail with Resource__c,Number field Leaves_Taken__c
3) Leave__c has lookup with Resource__c , Leave_Date__c, picklist Decision__c(Approved/Rejected).

Need to create  future call & write a function which looks at all Leaves & each time calculates & updates Month__c object records if there is a change.

If the Decision__c is Approved then want to achieve following condition.
1) If Leaves are taken on both Friday & Monday, then 4 leaves to be added in Leaves_Taken__c field ( In Month__c object) for that particulr Month.
2) If Leaves are taken from Monday to Friday, then 9 Leaves to be added in Leaves_Taken__c field ( In Month__c object) for that particulr Month.
3) If single day taken leaves then 1 to be added in the Leaves_Taken field for that Month.
4) On Delete of Leave__c decrement will happen in Leaves_Taken__c.
5) On update of Leave__c repested action will happen.(increment/decrement).

Please help me to write this code.
Reply me!
Its urgent.
If any query plzz ask me!
Thanks you so much!
Regards,
Hiral.
In this Leave and the Resource are custom object. Leave has lookup relationship with Resource . Leave has the custom field Leaves__c. For the one Resource total Leaves__c will be calculated in Total_Used_Paid_Leaves__c (custom field) in Resource__c object.

my apex trigger

trigger LeaveTrigger on Leave__c (after insert,after update) {
    
    if(trigger.isInsert || trigger.isUpdate){
        HRLeaveController.getTotalLeaves(Trigger.New);
     
    }
}
Apex class code
public class HRLeaveController{
    
    public static void  getTotalLeaves(List<Leave__c> newLeaves){
        Set<ID> resId = new Set<ID>();
        List<Resource__c> listRes = new List<Resource__c>();
        List<Resource__c> updateRes = new List<Resource__c>();
        
        for(Leave__c lev : newLeaves){
            resId.add(lev.Resource__c);
        }
        
        if(resId.size() > 0){
            listRes = [select Id,Total_Used_Paid_Leaves__c ,(select Id,Leaves__c from Leaves__r) from Resource__c where Id IN : resId];
        }
        
        for(Resource__c resrc : listRes){
            Decimal val = 0;
            for(Leave__c levs : resrc.Leaves__r){
                
                val += levs.Leaves__c;
                System.debug('**val**'+val);
            }
            resrc.Total_Used_Paid_Leaves__c = val;
            updateRes.add(resrc);
        }
        
        if(!updateRes.isEmpty()){
            update updateRes;
        }
    }
}