• Poornima HR 5
  • NEWBIE
  • 25 Points
  • Member since 2016

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 5
    Replies
Hello, My test class is only covering 70% of my class. How can I get it to cover 100%?

Here is the Class:
public class CBOHandler {
    public static void onAfterUpdate(List<CBO__c> CBOList, Map<Id, CBO__c> oldCBOMap) {

        for (CBO__c cbo : CBOList){
            if(oldCBOMap.get(cbo.Id).Pending_for_5_min__c == false && cbo.pending_for_5_min__c == true){
                         Set<string> cboSet = new Set<string>();
                            cboSet.add(cbo.id);
                            List<Discharge__c> disList = [select id,Referrals_Status__c from discharge__c where id in (select discharge_name__c from cbo__c where id in :cboset )];
                for (Discharge__c dis : disList){
                    if (dis.Referrals_Status__c != 'Pending Outcome'){
                        dis.Referrals_Status__c = 'Pending Outcome';
                    }
                     update disList;
                }
               
            }
            
        }
            
        
}
}


This portion is not being covered by the test:
                    if (dis.Referrals_Status__c != 'Pending Outcome'){
                        dis.Referrals_Status__c = 'Pending Outcome';
                    }
                     update disList;
                }



Here is the Test:
@isTest
public class CBOHandlerTest {
@isTest
    Static Void CboHandlerTestMethod(){
            Discharge__c d = new Discharge__c();
            d.Name = 'Test';
            d.Referrals_Status__c='Documents Uploaded';
                insert d;
        
        Cbo__c c = new Cbo__c();
        c.Pending_for_5_min__c = false;
        insert c;
        
         c = [SELECT Id, name FROM CBO__c WHERE Id =:c.Id];
        c.Pending_for_5_min__c = true;
        update c;
        system.debug(d.Referrals_Status__c);
 

  }
}
Can you let me know if there is way I can query the apps that are available for a profile and permission set? 
Thanks
Hi,
I have an apex trigger to count the total Opportunities related to an Account and Sum of Opportunity Amount related to Account. I am trying to implement "after undelete" in my trigger. But it isn't working. Can someone help to do this?
Below is my Trigger

trigger OpportunityCount on Opportunity (after insert, after delete, after update, after Undelete) {
    Map<Id, List<Opportunity>> acctIdOpptyListMap = new Map<Id, List<Opportunity>>();
    Set<Id> acctIds = new Set<Id>();
    List<Opportunity> opptyList = new List<Opportunity>();
    if(trigger.isUpdate && trigger.isInsert){
        for(Opportunity oppty : trigger.New){
            if(oppty.AccountId != null){
                acctIds.add(oppty.AccountId);
            }
        }    
    }
    if(trigger.isDelete){
        for(Opportunity oppty : trigger.old){
            if(oppty.AccountId != null){
                acctIds.add(oppty.AccountId);
            }
        }    
    }
    if(acctIds.size() > 0){
        opptyList = [SELECT Amount, AccountId 
                     FROM Opportunity 
                     WHERE AccountId IN : acctIds];
        for(Opportunity oppty : opptyList){
            if(!acctIdOpptyListMap.containsKey(oppty.AccountId)){
                acctIdOpptyListMap.put(oppty.AccountId, new List<Opportunity>());
            }
            acctIdOpptyListMap.get(oppty.AccountId).add(oppty); 
        }
       
        List<AggregateResult> lstResult = [SELECT AccountId, COUNT(Id) countId 
                                           FROM Opportunity 
                                           WHERE AccountId IN:acctIds
                                           GROUP BY AccountId];
        
        List<Account> lstAccount = new List<Account>();
        for(AggregateResult result:lstResult){
            Account acct = new Account (Id=(Id)result.get('AccountId'), Total_Opportunities__c = (Integer)result.get('countId'));
            lstAccount.add(acct);
        }
        update lstAccount;  
        
        List<Account> acctList = new List<Account>();
        acctList = [SELECT Total_Amount__c 
                    FROM Account 
                    WHERE Id IN: acctIds];
        for(Account acct : acctList){
            List<Opportunity> tempOpptyList = new List<Opportunity>();
            tempOpptyList = acctIdOpptyListMap.get(acct.Id);
            Double totalOpptyAmount = 0;
            for(Opportunity oppty : tempOpptyList){
                if(oppty.Amount != null){
                    totalOpptyAmount += oppty.Amount;
                }
            }
            acct.Total_Amount__c = totalOpptyAmount;
        }
        update acctList;
    }
}
  • March 02, 2020
  • Like
  • 0
Hi, 
i have a Time-Tracking app in salesforce where users track their work in percent of their time per workday. i want to autocalculate the overhead ( 100 - actually tracked work form multiple records) every morning in a batch job.
Therefore i think it would be needed that all TimeTracking-records with the same employee and day have to be included in the same batch to compare everything and calculate the overhead. is There an option to make sure that, if for example 5 TimeTrackingrecords with the same employeee-entry and the same date exist, dont get spread over two batches?

best regards,
Thomas
Hello, My test class is only covering 70% of my class. How can I get it to cover 100%?

Here is the Class:
public class CBOHandler {
    public static void onAfterUpdate(List<CBO__c> CBOList, Map<Id, CBO__c> oldCBOMap) {

        for (CBO__c cbo : CBOList){
            if(oldCBOMap.get(cbo.Id).Pending_for_5_min__c == false && cbo.pending_for_5_min__c == true){
                         Set<string> cboSet = new Set<string>();
                            cboSet.add(cbo.id);
                            List<Discharge__c> disList = [select id,Referrals_Status__c from discharge__c where id in (select discharge_name__c from cbo__c where id in :cboset )];
                for (Discharge__c dis : disList){
                    if (dis.Referrals_Status__c != 'Pending Outcome'){
                        dis.Referrals_Status__c = 'Pending Outcome';
                    }
                     update disList;
                }
               
            }
            
        }
            
        
}
}


This portion is not being covered by the test:
                    if (dis.Referrals_Status__c != 'Pending Outcome'){
                        dis.Referrals_Status__c = 'Pending Outcome';
                    }
                     update disList;
                }



Here is the Test:
@isTest
public class CBOHandlerTest {
@isTest
    Static Void CboHandlerTestMethod(){
            Discharge__c d = new Discharge__c();
            d.Name = 'Test';
            d.Referrals_Status__c='Documents Uploaded';
                insert d;
        
        Cbo__c c = new Cbo__c();
        c.Pending_for_5_min__c = false;
        insert c;
        
         c = [SELECT Id, name FROM CBO__c WHERE Id =:c.Id];
        c.Pending_for_5_min__c = true;
        update c;
        system.debug(d.Referrals_Status__c);
 

  }
}
Hi All,

We have requirement as mentioend below senario:

How to create/generate a new Opportunity with Related Lists to be populated on new Opportunity from Old Opportunity based on the closure of  ContractEnd date  of a existing opportunity.

Can any one please help us to create a new trigger.

Thanks in Advance