• Runi
  • NEWBIE
  • 20 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 3
    Replies
How to write test class for below class.

public with sharing class RecordsBatch implements Database.Batchable<sObject>,Schedulable{
    public Database.QueryLocator start(Database.BatchableContext pBatchContext) {
        system.debug('\n\n Label.RecordsBatchQueryOnFeeSplit :: '+Label.RecordsBatchQueryOnFeeSplit);
        return Database.getQueryLocator(Label.RecordsBatchQueryOnFeeSplit);
    }
    public void execute(Database.BatchableContext pBatchContext, List<bank__C> listFeeSplit) { 
        system.debug('...listFeeSplit...'+listFeeSplit);        
        List<bank__C> UpdateFeeSplit =  new List<bank__C>();                
        for(bank__C oppFS: listFeeSplit){
            bank__C UpdateObjFS = new bank__C();           
                system.debug('WIP*****');          
            if(oppFS.Recipient__r.Service_Line__c != oppFS.Recipient_Service_Line__c
               || oppFS.Recipient__r.Business_Unit__c != oppFS.Recipient_Business_Unit__c
               || oppFS.Recipient__r.Revenue_Generating_Team__c != oppFS.Recipient_Revenue_generating_team__c;
               || oppFS.Recipient__r.RGT_ID__c != oppFS.Recipient_RGT_ID__c){
                    
                    UpdateObjFS.id = oppFS.ID;
                    UpdateObjFS.Recipient_Service_Line__c = oppFS.Recipient__r.Service_Line__c;
                    UpdateObjFS.Recipient_Business_Unit__c = oppFS.Recipient__r.Business_Unit__c;
                    UpdateObjFS.Recipient_Revenue_generating_team__c = oppFS.Recipient__r.Revenue_Generating_Team__c;
                    UpdateObjFS.Recipient_RGT_ID__c = oppFS.Recipient__r.RGT_ID__c;
                    
                    system.debug('WIP UpdateObjFS*****'+UpdateObjFS);
                    UpdateFeeSplit.add(UpdateObjFS);              
               }                        
        }
         if(!UpdateFeeSplit.isEmpty()){
            Database.update(UpdateFeeSplit,false);
        }  
    }
     public void execute(SchedulableContext ctx) {
        RecordsBatch oWB = new RecordsBatch();
        database.executebatch(oWB,Integer.valueof(Label.RecordsBatchLimit));
    }
    public void finish(Database.BatchableContext bc){
    }
}
  • November 03, 2022
  • Like
  • 0
HI i AM new to apex how to write test class for below class.

public with sharing class RecordsBatch implements Database.Batchable<sObject>,Schedulable{
    public Database.QueryLocator start(Database.BatchableContext pBatchContext) {
        system.debug('\n\n Label.RecordsBatchQueryOnFeeSplit :: '+Label.RecordsBatchQueryOnFeeSplit);
        return Database.getQueryLocator(Label.RecordsBatchQueryOnFeeSplit);
    }
    public void execute(Database.BatchableContext pBatchContext, List<bank__C> listFeeSplit) { 
        system.debug('...listFeeSplit...'+listFeeSplit);        
        List<bank__C> UpdateFeeSplit =  new List<bank__C>();                
        for(bank__C oppFS: listFeeSplit){
            bank__C UpdateObjFS = new bank__C();           
                system.debug('WIP*****');          
            if(oppFS.Recipient__r.Service_Line__c != oppFS.Recipient_Service_Line__c
               || oppFS.Recipient__r.Business_Unit__c != oppFS.Recipient_Business_Unit__c
               || oppFS.Recipient__r.Revenue_Generating_Team__c != oppFS.Recipient_Revenue_generating_team__c;
               || oppFS.Recipient__r.RGT_ID__c != oppFS.Recipient_RGT_ID__c){
                    
                    UpdateObjFS.id = oppFS.ID;
                    UpdateObjFS.Recipient_Service_Line__c = oppFS.Recipient__r.Service_Line__c;
                    UpdateObjFS.Recipient_Business_Unit__c = oppFS.Recipient__r.Business_Unit__c;
                    UpdateObjFS.Recipient_Revenue_generating_team__c = oppFS.Recipient__r.Revenue_Generating_Team__c;
                    UpdateObjFS.Recipient_RGT_ID__c = oppFS.Recipient__r.RGT_ID__c;
                    
                    system.debug('WIP UpdateObjFS*****'+UpdateObjFS);
                    UpdateFeeSplit.add(UpdateObjFS);              
               }                        
        }
         if(!UpdateFeeSplit.isEmpty()){
            Database.update(UpdateFeeSplit,false);
        }  
    }
     public void execute(SchedulableContext ctx) {
        RecordsBatch oWB = new RecordsBatch();
        database.executebatch(oWB,Integer.valueof(Label.RecordsBatchLimit));
    }
    public void finish(Database.BatchableContext bc){
    }
}
  • November 02, 2022
  • Like
  • 0
Hi team,

How to write test class below calss.

public class InquiryConvertController {
    @AuraEnabled
    public static String getLeadId(String inquiryId){
        Inquiry__c leadId=[select id,Inquiry_Lead__c from Inquiry__c where id=:inquiryId];
        return leadId.Inquiry_Lead__c;
    }
    @AuraEnabled
    public static Id populateOpp(String leadId,String inquiryId) {
        if(leadId !=null){
            Database.update(new Lead(id=leadId,Inquiry__c=inquiryId));
        }
        return leadId;
    }
}
  • November 02, 2022
  • Like
  • 0
Hi All,

How to write test class for below code.

thanks
Swathi


public class Radius {
  @AuraEnabled
    public static Map<String, Object> getUserDetails1()    {

        Map<String, Object> returnMap = new Map<String, Object>();

        String userId = UserInfo.getUserId();

        User userRecord = [SELECT Id, ContactId, AccountId FROM User WHERE Id =: userId];
        Account personAccRecord = [SELECT  Name,  Phone FROM Account WHERE Id =: userRecord.AccountId];

        returnMap.put('personAccRecord', personAccRecord);
        return returnMap;
    }
}
  • July 06, 2022
  • Like
  • 0
Hi all,

How write test class for below trigger.


trigger Comment on CaseComment (before insert){
Set<Id> parentCase=new Set<Id>();
Map<Id,Case> mapCase=new Map<Id,Case>();
for (CaseComment t: Trigger.new){
parentCase.add(t.ParentId);
}
List<Case> lstCase=[Select Id,Status,Owner.name,Owner.Type from case where Id in :parentCase];
for(case c :lstCase){
mapCase.put(c.Id,c);
}
for (CaseComment t: Trigger.new){
if(mapCase.containskey(t.ParentId))
{

if( mapCase.get(t.ParentId).owner.Type=='Queue')
    {
        t.addError('please add comment.');     
    }
    
}
}
}
  • November 26, 2021
  • Like
  • 0
public class product1 {
  @AuraEnabled
    public static String updateReviewerComments(String oppId,String cmnt)
    {
        try{
            List<Opportunity> lstOpportunity =new List<Opportunity>();
            System.debug('Started '+oppId +' '+cmnt); 
            Opportunity oppRec=new Opportunity();
            oppRec=[Select Id,CMS_Approved__c,Send_Emails_to_BUH__c From Opportunity where Id=:oppId];
            oppRec.CMS_Approved__c=false;
             oppRec.Send_Emails_to_BUH__c=false;
            //lstOpportunity.add(oppRec);
            System.debug('Started ');
            List<Review_Comments__c> lstReview=new List<Review_Comments__c>();
            Review_Comments__c revcmnt=new Review_Comments__c();
            revcmnt.Comment__c=cmnt;
            revcmnt.Opportunity__c=oppId;
           // lstReview.add(revcmnt);
            String message;  
            Database.SaveResult resultComnt=database.insert(revcmnt,false);
            system.debug('resultComnt'+resultComnt.isSuccess());
            if(resultComnt.isSuccess()){
               
                Database.SaveResult resultOpp=database.update(oppRec,false); 
                 system.debug('resultOpp'+resultOpp.isSuccess());
                if(resultOpp.isSuccess()){
                    return 'Record is reviewed successfully';
                   
                } else {
                    
                    for(Database.Error err : resultOpp.getErrors()) {
                        System.debug('The following error has occurred.');                    
                        return err.getStatusCode() + ': ' + err.getMessage();
                        
                    }
                }
                
            } else {
                // Operation failed, so get all errors                
                for(Database.Error err : resultComnt.getErrors()) {
                    System.debug('The following error has occurred.');                    
                    return err.getStatusCode() + ': ' + err.getMessage();
                   
                }
            }
            //System.debug('Enterted  '+revcmnt);
           // System.debug('Opp Record value  '+oppRec);
            // Create an approval request for the Opportunity
            
            return message;
        }
        catch(exception e)
        {
            return e.getMessage();
        }
    }
}
  • October 14, 2021
  • Like
  • 0
public class ProductLighting {
 @AuraEnabled
    public static Opportunity fetchOpportunityLineItem(String opId) {
        Opportunity returnContactList = new Opportunity();
        
        returnContactList = [Select Id,StageName,(SELECT Id,UnitPrice,Quantity,Discount__c, From OpportunityLineItems Where Approved_c=True) from Opportunity Where Id=:opId];
        
        return returnContactList ;
    }
    
    
    @AuraEnabled
    public static List < String > Records(List < String > lstRecordId) {
        List < String > Msg = new List < String > ();
        List < OpportunityLineItem > lstDeprecateRec = [select Id,Product_Deprecated__c from OpportunityLineItem where id IN: lstRecordId];
        for(OpportunityLineItem ord:lstDeprecateRec)
        {
            ord.Product_Deprecated__c=True;
        }
        allowupdateopplineitem__c obj = allowupdateopplineitem__c.getInstance('isallowed');
        
        obj.allowupdate__c = true;
        update obj;
        Database.SaveResult[] DR_Dels = Database.update(lstDeprecateRec, false);
         obj.allowupdate__c = false;
        update obj;
        for (Database.SaveResult dr: DR_Dels) {
            if (dr.isSuccess()) {
                system.debug('successful Deprecate Opportunity Line Items');
            } 
            }
        return Msg;
        
    }
}
 
  • July 28, 2021
  • Like
  • 0
Hi team,

How to write test class below calss.

public class InquiryConvertController {
    @AuraEnabled
    public static String getLeadId(String inquiryId){
        Inquiry__c leadId=[select id,Inquiry_Lead__c from Inquiry__c where id=:inquiryId];
        return leadId.Inquiry_Lead__c;
    }
    @AuraEnabled
    public static Id populateOpp(String leadId,String inquiryId) {
        if(leadId !=null){
            Database.update(new Lead(id=leadId,Inquiry__c=inquiryId));
        }
        return leadId;
    }
}
  • November 02, 2022
  • Like
  • 0
Hi all,

How write test class for below trigger.


trigger Comment on CaseComment (before insert){
Set<Id> parentCase=new Set<Id>();
Map<Id,Case> mapCase=new Map<Id,Case>();
for (CaseComment t: Trigger.new){
parentCase.add(t.ParentId);
}
List<Case> lstCase=[Select Id,Status,Owner.name,Owner.Type from case where Id in :parentCase];
for(case c :lstCase){
mapCase.put(c.Id,c);
}
for (CaseComment t: Trigger.new){
if(mapCase.containskey(t.ParentId))
{

if( mapCase.get(t.ParentId).owner.Type=='Queue')
    {
        t.addError('please add comment.');     
    }
    
}
}
}
  • November 26, 2021
  • Like
  • 0
public class product1 {
  @AuraEnabled
    public static String updateReviewerComments(String oppId,String cmnt)
    {
        try{
            List<Opportunity> lstOpportunity =new List<Opportunity>();
            System.debug('Started '+oppId +' '+cmnt); 
            Opportunity oppRec=new Opportunity();
            oppRec=[Select Id,CMS_Approved__c,Send_Emails_to_BUH__c From Opportunity where Id=:oppId];
            oppRec.CMS_Approved__c=false;
             oppRec.Send_Emails_to_BUH__c=false;
            //lstOpportunity.add(oppRec);
            System.debug('Started ');
            List<Review_Comments__c> lstReview=new List<Review_Comments__c>();
            Review_Comments__c revcmnt=new Review_Comments__c();
            revcmnt.Comment__c=cmnt;
            revcmnt.Opportunity__c=oppId;
           // lstReview.add(revcmnt);
            String message;  
            Database.SaveResult resultComnt=database.insert(revcmnt,false);
            system.debug('resultComnt'+resultComnt.isSuccess());
            if(resultComnt.isSuccess()){
               
                Database.SaveResult resultOpp=database.update(oppRec,false); 
                 system.debug('resultOpp'+resultOpp.isSuccess());
                if(resultOpp.isSuccess()){
                    return 'Record is reviewed successfully';
                   
                } else {
                    
                    for(Database.Error err : resultOpp.getErrors()) {
                        System.debug('The following error has occurred.');                    
                        return err.getStatusCode() + ': ' + err.getMessage();
                        
                    }
                }
                
            } else {
                // Operation failed, so get all errors                
                for(Database.Error err : resultComnt.getErrors()) {
                    System.debug('The following error has occurred.');                    
                    return err.getStatusCode() + ': ' + err.getMessage();
                   
                }
            }
            //System.debug('Enterted  '+revcmnt);
           // System.debug('Opp Record value  '+oppRec);
            // Create an approval request for the Opportunity
            
            return message;
        }
        catch(exception e)
        {
            return e.getMessage();
        }
    }
}
  • October 14, 2021
  • Like
  • 0