• senies12 joe
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 4
    Replies
Hi,
total earnings=63,967
standard_deduction_monthly__c=4167
Professional_Tax__c=200
TDS__c=5333.33
Company_s_Contributionto_PF_Monthly__c=5400

for manual calculation i got  15100.33
In this formula i got   51566


CASE( Tax_Regime__c ,
"Old Regime",(Total_Earnings__c -( standard_deduction_monthly__c+Professional_Tax__c+Company_s_Contributionto_PF_Monthly__c+ TDS__c)), 
"New Regime",( Total_Earnings__c -TDS__c ) ,0)

can anyone guide me what went wrong?

Thanks in Advance

 
How to write the test cases for this batch class
can anyone write the test class for this batch, I'm  very thankful to him
Thanks in Advance

global class DeleteBulkRecordBatch2 implements Database.Batchable<SObject>, Database.Stateful {
    
    String query = '';
    String sObjectType = '';
    List<String> list_Employee= new List<String>();
    Date FROM_DATE = Null;
    Date toDate = Null;
    Set<Id> set_nonDeleteId = new Set<Id>();
    
    // Constructor
    global DeleteBulkRecordBatch2(String sObjectType, List<String> list_Employee,Date FROM_DATE,Date toDate){
        this.sObjectType = sObjectType;
        this.list_Employee = list_Employee;
        this.FROM_DATE = FROM_DATE;
        this.toDate = toDate;
        
    }
    global Database.QueryLocator start(Database.BatchableContext bc){
        
      
        if(sObjectType == 'Order'){
            if(FROM_DATE == Null && toDate == Null ){
                query='Select Id,account_holder__r.Account__c,account_holder__r.AccountId from Order__c WHERE account_holder__r.AccountId=:list_Employee';
            }else{
                query='Select Id,account_holder__r.Account__c,account_holder__r.AccountId from Order__c WHERE (account_holder__r.AccountId = :list_Employee) AND (NOT (LastmodifiedDate >=:FROM_DATE AND LastmodifiedDate <=: toDate))'; 
            }
        }else if(sObjectType == 'Contact'){
            if(FROM_DATE == Null && toDate == Null ){
                query='Select Id,Account.id,Account.name,Account__c,Parent_Member_Name__r.id,(Select Id from cases),(select Id from Contact_Products__r) from Contact WHERE Account.id=:list_Employee';
            }else{
                query='Select Id,Account.id,Account.name,Account__c,Parent_Member_Name__r.id,(Select Id from cases),(select Id from Contact_Products__r) from contact WHERE (Account.id = :list_Employee) AND (NOT(account__c =:set_nonDeleteId)) AND (LastmodifiedDate >=:FROM_DATE AND LastmodifiedDate <=:toDate)';
            }
        }else if(sObjectType=='CustmAccount'){
            if(FROM_DATE == Null && toDate == Null ){
                query='Select Id,Instructing_Party__c,(Select id from Account_Allowances__r) from Account__c WHERE Instructing_Party__c=:list_Employee';
            }else{    
                query='Select Id,Instructing_Party__c,(Select id from Account_Allowances__r) from Account__c WHERE Id NOT IN (Select Account__c From Contact) And (Instructing_Party__c = :list_Employee) AND (NOT(Id=:set_nonDeleteId)) AND (lastModifiedDate >= :FROM_DATE And lastModifiedDate <= :toDate)';
            }
        }
        System.debug(query);
        return Database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext bc, List<SObject> s_object){
        System.debug('--execute---');
        System.debug('--set_nonDeleteId---'+set_nonDeleteId);
        System.debug('--list_Employee---'+list_Employee);
        
        if(sObjectType == 'Order') {
            List<order__c> list_Order = new List<order__c>();
            // todo=merge both the for Loop
            for(SObject obj : s_object){
                order__c order  = (order__c)obj;
                list_Order.add(order);
                System.debug('--list_Order---'+list_Order);
            }
            for(Order__c obj_Order : list_Order){
                set_nonDeleteId.add(obj_Order.Account_Holder__r.account__c);
                System.debug('--set_nonDeleteId---'+set_nonDeleteId);
            }
        }else if(sObjectType == 'Contact'){
            Contact[] cont = Database.query(query);
            List<Contact> list_contact = new List<contact>();
            List<Case> list_Case = new List<Case>();
            List<Contact_Products__c> list_Contact_Products = new List<Contact_Products__c>(); 
            for(Contact obj : cont){
                Contact contacts  = (contact)obj;
                list_contact.add(contacts);
                System.debug('--list_contact---'+list_contact);
                for(Case c : obj.cases){
                    Case Cas  = (Case)c;
                    list_Case.add(Cas); 
                    System.debug('--list_Case---'+list_Case);
                }
                for(Contact_Products__c Contact_Products : obj.Contact_Products__r){
                    Contact_Products__c ContactProducts  = (Contact_Products__c)Contact_Products;
                    list_Contact_Products.add(ContactProducts);
                    System.debug('--list_Contact_Products---'+list_Contact_Products);
                }
            }
            delete list_Case;
            delete list_Contact_Products;
            delete list_contact;
            
        }else if(sObjectType== 'CustmAccount'){
            Account__c[] acnt = Database.query(query);
            List<Account__c> list_CustAccount = new List<Account__c>();
            List<Account_Allowances__c> list_AccountAllowences = new List<Account_Allowances__c>();
            for(Account__c obj : acnt){
                Account__c CustAccount  = (Account__c)obj;
                list_CustAccount.add(CustAccount);
                for(Account_Allowances__c AcntAlwnc : obj.Account_Allowances__r){
                    Account_Allowances__c AccountAllowances  = (Account_Allowances__c)AcntAlwnc;
                    list_AccountAllowences.add(AccountAllowances); 
                }
            }
            delete list_AccountAllowences;
            delete list_CustAccount;
        }
        
    }       
    global void finish(Database.BatchableContext bc){
        if (sObjectType == 'Order') {       
            Id batchJobId = Database.executeBatch(new DeleteBulkRecordBatch2('Contact',list_Employee,FROM_DATE,toDate), 1000);
        }else if(sObjectType == 'Contact'){
            Id batchJobId = Database.executeBatch(new DeleteBulkRecordBatch2('CustmAccount',list_Employee,FROM_DATE,toDate), 1000);
        
        }
    }    
    
}
Apex Class:
public with sharing class ChangeOpptyOwnerCtrl {
    private string oppId;
    public Opportunity oppobj {get;set;}
    public boolean isErrInSave {get;set;}
    
    public ChangeOpptyOwnerCtrl(ApexPages.StandardController ctrl){
        oppId = ApexPages.currentPage().getParameters().get('oppId');
        if(oppId != null)
            oppobj = [Select id, Name, OwnerId from Opportunity where id =: oppId limit 1];
    }
    
    public void saveOwner(){
        isErrInSave = false;
        try{
            if(oppobj != null)
                update oppobj;
        }catch(Exception e){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error , e.getMessage()));
            isErrInSave = true;
        }
    }
}


TestClass:

@isTest
public with sharing class ChangeOpptyOwnerCtrlTest {
    @testSetup
    static void setupTestData(){
        Account acc = TestUtility.createAccount('Test A');
        insert acc;
        Opportunity opp = TestUtility.createOpportunity('@test opp', Date.today(), 'To be Invoiced', acc.id);
        opp.Follow_up_Date__c = date.today();
        insert opp;
    }
    
    testmethod static void saveOwnerTest(){
        Opportunity opp = [Select id from Opportunity limit 1];
        test.startTest();
        
        Test.setCurrentPageReference(new PageReference('Page.ChangeOpptyOwnerPage'));
        System.currentPageReference().getParameters().put('oppId',opp.id);        
        ApexPages.StandardController sc = new ApexPages.StandardController(opp);
        ChangeOpptyOwnerCtrl ctrlObj = new ChangeOpptyOwnerCtrl(sc);
        
        ctrlObj.saveOwner();
        
        test.stopTest();
        
    }
    
}



can any one help me to cover catch(Exception e) lines