• Akshay Mhetre
  • NEWBIE
  • 135 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 23
    Questions
  • 13
    Replies
trigger sendEmailtoinitiator on Case (after update) {
    
    
    List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
    
    Map<Id, Case> objMap = new Map<Id, Case>([ SELECT Id, Allocated_By__r.Email FROM Case WHERE Id IN : Trigger.new ]);
    for (Case newCase : Trigger.new){
        if((newCase.RCU_Stage__c == 'RCU Completion'|| newCase.RCU_Stage__c == 'RCU Clear' || newCase.RCU_Stage__c == 'RCU Negative')  
             && newCase.RCU_completion_Status__c !=null && newCase.Completion_Submit__c == true ){
            
            Messaging.SingleEmailMessage mail =  new Messaging.SingleEmailMessage();
            
           
            String[] toAddresses = new String[] {(objMap.get(newCase.Id).Allocated_By__r.Email)};
            mail.setToAddresses(toAddresses);
            
           
            
            EmailTemplate et = [select id,Subject,Body from EmailTemplate where developername='CaseStageEmailAlert'];
            mail.setTemplateId(et.Id );
            mail.setWhatId(newCase.Id);
            mail.setSubject(et.Subject);
          
            mail.setPlainTextBody(et.Body);
           
          mail.setTreatBodiesAsTemplate(true);
            
            
            //adding email to master list
            mails.add(mail);
            
        }
    }
    
           
            Messaging.sendEmail(mails);
}
 

Hello Experts,

In my org, there are 3 Public group.PG-A,PG-B,PG-C.

PG-A has 2 Users having RCU Initiator profile.

PG-B and PG-C each has 1 user.

I have a requirment,

When Case passes from PG-A (RCU_Stage__c='RCU Initiator') user to PG-B (RCU_Stage__c='RCU Verification') to PG-C (RCU_Stage__c='RCU Completion'), Once RCU_Stage__c become 'RCU Completion', email should send to the User who passed the case to PG-B user.

Allocated_By__c is the case field which shows the User (Who send the case to 'RCU Verification' (PG-B) stage.

***I dont want to write HardCoded email id in sendTo***

My Code-

trigger sendEmailtoinitiator on Case (after update) {
    
    //master list to hold the emails we'll send
    List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
    
    for (Case newCase : Trigger.new){
        if(newCase.RCU_Stage__c == 'RCU Completion' ){
            //Create a new Email
            Messaging.SingleEmailMessage mail =  new Messaging.SingleEmailMessage();
            
           //Setting list of people to get the email
            List<String> sendTo = new List<String>();
           // sendTo.add(newCase.Allocated_By_Text__c);
            sendTo.add(newCase.Allocated_By__c);
            mail.setToAddresses(sendTo);
            
            //Setting ReplyTo email 
            mail.setReplyTo(newCase.OwnerId);
            
            //list of people who should be CC
            List<String> ccTo = new List<String>();
            ccTo.add(newCase.CreatedById);
            mail.setCcAddresses(ccTo);
            
            //Email TemplateId (NOT SURE)
            EmailTemplate et = [select id,Subject from EmailTemplate where developername='CaseStageEmailAlert'];
            mail.setTemplateId(et.Id );
            
            //Subject
            //mail.setSubject('Case reached at Completion Stage');
            mail.setSubject(et.Subject);
            
            //adding email to master list
            mails.add(mail);
            
        }
    }
    
            //Send email to master list
            Messaging.sendEmail(mails);
}

 

Hello

I have a requirmnet, When user click Risk Rafer button,RCU Sub Stage is getting select as RCU Completion - Fresh....Now when user clicking  on submit button (Completion_Submit__c), RCU Sub Stage field should change from RCU Completion - Fresh to 'UW Confirmation Awaited'.

But its not changing to  'UW Confirmation Awaited'..its remaining as it is (RCU Completion - Fresh).

My Code--

 if(oldMap.get(caseRecord.Id).RCU_completion_Status__c != caseRecord.RCU_completion_Status__c
                   && caseMap.get('RCU Completion') == caseRecord.RecordTypeId) {
                       caseRecord.RCU_Completion_date__c = System.now();
                       if(caseRecord.RCU_completion_Status__c == 'Risk Refer'  && oldMap.get(caseRecord.Id).Completion_Submit__c != caseRecord.Completion_Submit__c ) {
                           caseRecord.RCU_Sub_Stage__c = 'UW Confirmation Awaited'; 
                            
                       }
                   }

 

User-added image

User-added image

User-added image

Error element myRule_1_A1 (FlowActionCall).
Probably Limit Exceeded or 0 recipients --- Probably Limit Exceeded or 0 recipients

Flow Details
Flow API Name: RCU_Email_alert
Type: Record Change Process
Version: 1
Status: Active

Flow Interview Details
Interview Label: RCU_Email_alert-1_InterviewLabel
Interview GUID: 2360926e2f91946c38bb3db0096017d1a6e20dd-7350
Current User: Automated Process (0058p000000HgMq)
Start time: 15/11/2021, 3:53 pm

 

There are 3 Users.. User1,User2,User3.
All 4 Users have same profile.

Scenario:-

On case object there is 1 Picklist field --> Stage__c
There are 3 stages of cases --> Initiation,Verification,Completion (Picklists value of Stage__c)
Case is moving from User1(Initiator) to User2(Verifier) to User3(Completion).
 Once case reaches to Users3 (Means at Completion Stage),Email Should send only to User1(to Initiator) (who sent the case to User2).
           
For above requirment I created Process Builder,It works fine..But Email goes only to previous case owner. I am expecting it should go only to whom who assigned case to User2.

Please Help with apex triggers or class.

if(
                    (caseMap.get('RCU Completion') == caseRecord.RecordTypeId
                     && oldMap.get(caseRecord.Id).Completion_Submit__c != caseRecord.Completion_Submit__c
                     && yB_RCUUtility.rcuNegativeCompletionList.contains(caseRecord.RCU_completion_Status__c)
                     
                    )) {
                        caseRecord.RCU_Stage__c = 'RCU Negative';
                        caseRecord.RCU_Sub_Stage__c = 'RCU Negative';
                        caseRecord.RecordTypeId = caseMap.get('RCU Negative');
                       
                        caseRecord.setOptions(dmlOpts);
                    }
                
                if(
                    (caseMap.get('RCU Completion') == caseRecord.RecordTypeId
                     && oldMap.get(caseRecord.Id).RCU_completion_Status__c != caseRecord.RCU_completion_Status__c
                     && caseRecord.RCU_completion_Status__c == 'Rework' && caseRecord.RCU_Initiator__c != null
                     
                    )) {
                        caseRecord.OwnerId = caseRecord.RCU_Initiator__c;
                        caseRecord.RCU_Stage__c = 'RCU Initiated';
                        caseRecord.RecordTypeId = caseMap.get('RCU Initiation');
                        
                        caseRecord.RCU_Total_Sample_Count__c = 0;
                        caseRecord.RCU_Verification_Status_Count__c = 0;
                        caseRecord.RCU_Verification_End_Date__c = null;
                        caseRecord.RCU_Completion_date__c = null;
                        
                        caseRecord.RCU_Initiator_Action_Complete__c = false;
                        caseRecord.RCU_Screen_All_set_flg__c = false;
                        
                    }
                
                if( caseMap.get('RCU Initiation') == caseRecord.RecordTypeId
                   && oldMap.get(caseRecord.Id).RCU_Ratification_Status__c != caseRecord.RCU_Ratification_Status__c &&
                   caseRecord.RCU_Ratification_Status__c!=null && caseRecord.RCU_Ratification_Status__c == 'Reinitiate'
                  ) {
                      caseRecord.OwnerId = caseRecord.RCU_Initiator__c;
                      caseRecord.RCU_Stage__c = 'RCU Initiated';
                      caseRecord.RecordTypeId = caseMap.get('RCU Initiation');
                      
                      caseRecord.RCU_Total_Sample_Count__c = 0;
                      caseRecord.RCU_Verification_Status_Count__c = 0;
                      caseRecord.RCU_Verification_End_Date__c = null;
                      caseRecord.RCU_Completion_date__c = null;
                  }
                
                
                
                System.debug('RCU_completion_Status__c' +caseRecord.RCU_completion_Status__c );
                string recodid=caseMap.get('RCU Initiation');                
                if(
                    (caseMap.get('RCU Completion') == caseRecord.RecordTypeId
                     && oldMap.get(caseRecord.Id).Completion_Submit__c != caseRecord.Completion_Submit__c
                     && (caseRecord.RCU_completion_Status__c == 'Recommended'||
                         caseRecord.RCU_completion_Status__c == 'CNV')
                     
                    )) {
                        caseRecord.RCU_Stage__c = 'RCU Clear';
                        caseRecord.recordTypeId=recodid;
                        if (caseRecord.RCU_Stage__c == 'RCU Clear'){
                            System.debug('==caseRecord.RCU_Stage__c=='+caseRecord.RCU_Stage__c);
                            if(caseRecord.RCU_Initiator_Group_Id__c!= '')
                            {
                                System.debug('==caseRecord.RCU_Initiator_Group_Id__c=='+caseRecord.RCU_Initiator_Group_Id__c);   
                                caseRecord.OwnerId = caseRecord.RCU_Initiator_Group_Id__c; 
                                System.debug('==caseRecord.OwnerId=='+caseRecord.OwnerId);  
                            }  
                        }
                        caseRecord.RCU_Sub_Stage__c ='RCU Clear';     
                        
                      
                    }
              
                if(
                    (caseMap.get('RCU Ratification') == caseRecord.RecordTypeId
                     && oldMap.get(caseRecord.Id).Flag__c != caseRecord.Flag__c
                     && (caseRecord.RCU_Ratification_Status__c == 'Ratified RPD' || caseRecord.RCU_Ratification_Status__c == 'Ratified RDD')
                     
                    )) {
                        caseRecord.RCU_Stage__c = 'RCU Clear';
                        
                    }
                if (caseRecord.RCU_Stage__c == 'RCU Clear'){
                    
                    if(caseMap.get('RCU Ratification') == caseRecord.RecordTypeId ||
                       caseMap.get('RCU Negative') == caseRecord.RecordTypeId ||
                       caseMap.get('RCU Initiation') == caseRecord.RecordTypeId ||
                       caseMap.get('RCU Completion') == caseRecord.RecordTypeId){
                           caseRecord.recordTypeId=recodid;
                           caseRecord.RCU_Sub_Stage__c ='RCU Clear';
                       }
                  
                    System.debug('==caseRecord.RCU_Stage__c=='+caseRecord.RCU_Stage__c);
                    if(String.isNotBlank(caseRecord.RCU_Initiator_Group_Id__c))
                    {
                        System.debug('==caseRecord.RCU_Initiator_Group_Id__c=='+caseRecord.RCU_Initiator_Group_Id__c);   
                        caseRecord.OwnerId = caseRecord.RCU_Initiator_Group_Id__c; 
                        System.debug('==caseRecord.OwnerId=='+caseRecord.OwnerId);  
                    }  
                }
                if(oldMap.get(caseRecord.Id).ownerId != caseRecord.ownerId
                   && caseMap.get('RCU Initiation') == caseRecord.RecordTypeId
                   && String.valueOf(caseRecord.ownerId).startsWithIgnoreCase('005')
                   && runningUser.Profile.Name == 'RCU Initiator') {
                       caseRecord.RCU_Initiator__c = runningUser.id;
                    
                       caseRecord.RCU_Initiation_Date__c = System.now();
                       caseRecord.RCU_Initiation_Started__c = 'Yes';
                   }
                if(oldMap.get(caseRecord.Id).RCU_completion_Status__c != caseRecord.RCU_completion_Status__c
                   && caseMap.get('RCU Completion') == caseRecord.RecordTypeId) {
                       caseRecord.RCU_Completion_date__c = System.now();
                       if(caseRecord.RCU_completion_Status__c == 'Risk Refer') {
                           caseRecord.RCU_Sub_Stage__c = 'UW Confirmation Awaited';
                       }
                   }
                if(caseMap.get('RCU Negative') == caseRecord.RecordTypeId
                   && oldMap.get(caseRecord.Id).RCU_Negative_Decision__C != caseRecord.RCU_Negative_Decision__C
                   && caseRecord.RCU_Negative_Decision__C=='Query'
                  ) {
                      caseRecord.RCU_Sub_Stage__c = 'RCU Negative Query Raised';
                      System.debug('rcuQueueNegativeId: ');
                  }
                if(oldMap.get(caseRecord.Id).RCU_Stage__c != caseRecord.RCU_Stage__c
                   && caseMap.get('RCU Negative') == caseRecord.RecordTypeId
                   && caseRecord.RCU_Stage__C == 'RCU Ratification') {
                       caseRecord.RecordTypeId = caseMap.get('RCU Ratification');
                       caseRecord.RCU_Ratification_Status__c = 'New';
                       
                   }
public class YB_RCUReportVFController {
    
     public Id caseId;
     public YB_RCUReportWrapper rcuReportData{get;set;}
    
      public YB_RCUReportVFController()
    {
        this.caseId = Apexpages.currentpage().getparameters().get('id');
        this.rcuReportData = new YB_RCUReportWrapper(this.caseId);
        
        
    }

}

Hello Experts,

I recevied one request from Client that, just like Admin can edit List View's Filters, Client also wants to give permission to particular profile to Edit List View's Filters.

Possible?? Any Way??

User-added image

 

@AuraEnabled
     public static void updateFilesMainCase(String contentVersionIds,String recordId)
     {
     System.debug('============contentVersionIds===='+contentVersionIds);
         if(contentVersionIds != null){
             String[] contentVersionIdArr = contentVersionIds.split(',');
        Set<String> contentDocumentIds = new Set<String>();
        for(String docId : contentVersionIdArr)
        {
            if(docId != null && docId.length() > 0)
                contentDocumentIds.add(docId);
        }
        System.debug('============contentDocumentIds===='+contentDocumentIds);
      //  List<Case> listCase = [select Type,Subject from Case where Id=:recordId];
       String imgTitle;
        List<User> agencyName= [Select Id ,Contact.Account.Name,Profile.Name from User where Id =:UserInfo.getUserId() AND Profile.Name='RCU Agent Community'];
        if(agencyName.size()> 0){
            imgTitle = agencyName[0].Contact.Account.Name+'-'+String.valueOf(System.now());
            }
        System.debug('============imgTitle===='+imgTitle);
        List<ContentVersion> versionList = [SELECT FileExtension, Title FROM ContentVersion 
                                            WHERE ContentDocumentId IN :contentDocumentIds and IsLatest=true ] ;
        List<ContentVersion> contentVersionsToUpdate = new List<ContentVersion>();
        for(ContentVersion contVersion : versionList)
        {
            if(imgTitle != null){
              contVersion.Title = imgTitle;  
            }
        }
         update versionList;   
         System.debug('recordId: '+recordId);
        List<Case> caselist= [Select Id, isAgentReportUploaded__c From Case Where ParentId=:RecordId]; 
         for(Case subC: caseList){
             subC.isAgentReportUploaded__c = true;
         }
         if(!caselist.isEmpty()){
             update caselist;
         }
        //return imgTitle;
       } 
        // return 'error';
         }
}
@AuraEnabled
    public static List<Case> submitSubCases(Id RecordId) {
        List<Case> csUpdateList = new List<Case>();
        List<Case> isAgentUploaded = [Select Id,isAgentReportUploaded__c from Case WHERE 
                                          ParentId=:RecordId AND isAgentReportUploaded__c = false 
                                          ];
        if(isAgentUploaded.size() == 0){
            String subStage =[Select Id, RCU_Sub_Stage__c from Case where Id=:RecordId].RCU_Sub_Stage__c;
            if(subStage == 'Rework'){
            List<Case> subCaselist= [Select Id, RCU_Sub_Stage__c From Case Where ParentId=:RecordId]; 
            if(subCaselist != null && subCaselist.size()>0){
                for(Case c:subCaselist)
                {
                    c.RCU_Sub_Stage__c = 'Agent Rework Submitted'; 
                    csUpdateList.add(c);
                }
            }
        }
        try {
            if (csUpdateList.size() > 0) {
                System.debug('csUpdateList: '+csUpdateList.size());
                update csUpdateList;
            }
        } catch(Exception ex) {
            System.debug(ex.getMessage());
        }
        return csUpdateList;
       } 
        else{
            return isAgentUploaded;
        }
        //System.debug('Successfully Agent Rework Submitted to All the Cases.');
        //return csUpdateList;
    }
  @AuraEnabled
    public static string getProfileCached(Id RecordId){
        Id profileId = UserInfo.getProfileId();
        String profileName =[Select Id, Name from Profile where Id=:profileId].Name;
        system.debug('Profile Name'+profileName);
        if('RCU Agent Community' == profileName){
            List<Case> caselist= [Select Id, RecordTypeId, OwnerId, Agent_Decision__c, Allocated_By__C, RCU_Sampling_Status__c
                                  From Case Where ParentId=:RecordId and RCU_Agency_Action__c <>'Accepted'];
            if(caseList != null && caseList.size()>0){
                return 'show';
            }else{
                return 'hide';
            }
        }
        return 'hide';
    }
Hello Everyone....Here I am sharing some methods from class which are not getting covered. Need help
 
 @AuraEnabled(cacheable = true)
    public static string getProfile(Id RecordId){
        Id profileId = UserInfo.getProfileId();
        String profileName =[Select Id, Name from Profile where Id=:profileId].Name;
        system.debug('Profile Name'+profileName);
        if('RCU Agent Community' == profileName){
            List<Case> caselist= [Select Id, RecordTypeId, OwnerId, Agent_Decision__c, Allocated_By__C, RCU_Sampling_Status__c
                                  From Case Where ParentId=:RecordId and RCU_Agency_Action__c <>'Accepted'];
            if(caseList != null && caseList.size()>0){
                return 'show';
            }else{
                return 'hide';
            }
        }
        return 'hide';
    }

Hello Everyone,

There are two fields  Citytext__c [ Text(255) ]  and City__c [Picklist] and one picklist RCU Location Type contains 2 value-- i)Local ii)OGL.

Requirment: If Citytext__c   and  City__c matches,then RCU  Location Type will automatically change to Local,if both cities are diffrent then RCU Location Type will become OGL.

Facing Problem::-User-added image Please give me solution or any idea to complete this.

 

 

Hello Everyone...

I have one picklist  Hunter_Final_Status__c  having Pending,Clear,Decline,Suspect values.

Condition:: Once any of (Hunter_Final_Status__c) above value is selected, that value should populate/Display in Hunter_Status__c (Text).

 

Hello Everyone,I need help. I have a class who has wrapper too. Confused.

Main Class:::

public without sharing class DownloadAllFilesController {
    public static Per_ResponseWrapper response = new Per_ResponseWrapper();
    @AuraEnabled
    public static Per_ResponseWrapper getAllContentDocumentIds(String recordId){
        system.debug('recordId is :::: ' + recordId);
        try{
            Set<Id> setDocumentChecklistIds = new Set<Id>();
            Set<Id> setCaseIds = new Set<Id>();
             for(Case subCase: [select Id,Document_Checklist__c from Case 
                               where ParentId =:recordId and RecordType.Name in ('RCU Document Check','RCU Profile Check Off')]){
                                   setDocumentChecklistIds.add(subCase.Document_Checklist__c);
                                   setDocumentChecklistIds.add(subCase.Id);
                               }
            String ContentdocumentIds = '';
            if(setDocumentChecklistIds.size() >0){
                List<ContentDocumentLink> contentDocumentLinkDatafrmCase = [select id, ContentdocumentId, LinkedEntityId from ContentDocumentLink 
                                                                            where LinkedEntityId IN : setDocumentChecklistIds WITH SECURITY_ENFORCED];
                System.debug('contentDocumentLinkDatafrmCase: '+contentDocumentLinkDatafrmCase.size());
                if(contentDocumentLinkDatafrmCase.size() > 0){  
                    for(integer i=0; i < contentDocumentLinkDatafrmCase.size(); i++){                    
                        ContentdocumentIds += '/' + contentDocumentLinkDatafrmCase[i].ContentdocumentId;  
                    }
                }
            }
            response.success = true;
            response.data = ContentdocumentIds;                   
        }
        catch(Exception e)
        {
            system.debug('exception:' + e.getMessage());
            response.success = false;
            response.message = e.getMessage();
        }
        system.debug('Content Document ID is:::: ' + response);
        return response;
    }
}

Wrapper Class:::

public with sharing class Per_ResponseWrapper {
    
    @AuraEnabled public String message {get; set;}
    @AuraEnabled public Boolean success {get; set;}
    @AuraEnabled public object data {get; set;}    
    @AuraEnabled public Boolean hasEditAccess {get; set;}
    @AuraEnabled public String lastModifiedBy {get; set;}    

    public class LabelValueWrapper{
        @AuraEnabled public Object label;
        @AuraEnabled public Object value;
        @AuraEnabled public Object optionKey;
        @AuraEnabled public Object subQuestionID;

        public LabelValueWrapper(Object newLabel, Object newValue){
            label = newLabel;
            value = newValue;
        }
        public LabelValueWrapper(Object newLabel, Object newValue, Object newKey){
            label = newLabel;
            value = newValue;
            optionKey = newKey;
        }
        public LabelValueWrapper(Object newLabel, Object newValue, Object newKey, Object newSubQuestionID){
            label = newLabel;
            value = newValue;
            optionKey = newKey;
            subQuestionID = newSubQuestionID;
        }
    }

    
    public static List<FieldWrapper> getFieldSet(String fieldSetName, String objectName) {
        List<FieldWrapper> lstfieldWrapper = new List<FieldWrapper>();
        if (String.isNotBlank(fieldSetName) && String.isNotBlank(objectName)) {
            Schema.DescribeSObjectResult describeSObjectResult = Schema.getGlobalDescribe().get(objectName).getDescribe();
            Map<String,Schema.SObjectField> objFieldMap = describeSObjectResult.fields.getMap();
            Schema.FieldSet fieldSetObj = describeSObjectResult.FieldSets.getMap().get(fieldSetName);
            if (fieldSetObj != null) {
                for(Schema.FieldSetMember fieldSet : fieldSetObj.getFields() ) {
                    System.debug(fieldSet);
                    lstfieldWrapper.add( new FieldWrapper(
                        String.ValueOf(fieldSet.getLabel()+'$$'+String.valueOf(fieldSet.getType())),
                        String.ValueOf(fieldSet.getFieldPath()), 
                        (fieldSet.getDBRequired() || fieldSet.getRequired())
                    ));
                }
            }
        }
        return lstfieldWrapper; 
    }

    @AuraEnabled
    public static Per_ResponseWrapper getPicklistValues(Id recordId, List<String> fieldApiNames){
        Per_ResponseWrapper response = new Per_ResponseWrapper();
        List<Per_ResponseWrapper.LabelValueWrapper> fieldPicklistValueList = new List<LabelValueWrapper>();
        Schema.DescribeSObjectResult describeSObjectResult = recordId.getSobjectType().getDescribe();
        Map<String,Schema.SObjectField> objFieldMap = describeSObjectResult.fields.getMap();
        for(String fieldName : objFieldMap.keySet()){
            if(fieldApiNames.contains(fieldName)){
                List<Schema.PicklistEntry> picklistValues = objFieldMap.get(fieldName).getDescribe().getPicklistValues();
                fieldPicklistValueList.add(new Per_ResponseWrapper.LabelValueWrapper(fieldName, picklistValues));
            }   
        }
        response.success = true;
        response.data = fieldPicklistValueList;
        return response;
    }
    
    public class FieldWrapper {
        @AuraEnabled public String fieldName {get;set;}
        @AuraEnabled public String fieldLabel {get;set;}
        @AuraEnabled public String dataType {get;set;}
        @AuraEnabled public Boolean isRequired {get;set;}
        
        public FieldWrapper(String fieldLabel,String fieldName,Boolean isRequired ) {
            this.fieldLabel  = fieldLabel;
            this.fieldName   = fieldName;
            this.isRequired  = isRequired;
        }
    }
}

public class PL_FIAutoAllocationCounterResetBatch  implements Database.Batchable<sObject> {
    
    public Database.QueryLocator start(Database.BatchableContext BC){
        String query = 'SELECT id, Count__c FROM Sales_To_CPA_Allocation_Rule1__c WHERE Count__c !=0';
        return Database.getQueryLocator(query);

    }
    
    public void execute(Database.BatchableContext BC, List<Sales_To_CPA_Allocation_Rule1__c> scope){
        List<Sales_To_CPA_Allocation_Rule1__c> lstRulesToUpdate = new List<Sales_To_CPA_Allocation_Rule1__c>();
        for(Sales_To_CPA_Allocation_Rule1__c rule : scope){
             rule.Count__c = 0;
            lstRulesToUpdate.add(rule);
        }
        if(lstRulesToUpdate.size() > 0){
        update lstRulesToUpdate;
        }
    }
    
    public void finish(Database.BatchableContext BC){
    }
}

Please help me.

Hello Everyone...I am not aware how to write a test class  which include Try Catch and having Aura unabled.... Please help. So I can learn too.

public with sharing class FISuperVisorRefireChecker {

    @AuraEnabled
    public static string refireCase(String recordId){
        try {
            if(String.isNotBlank(recordId)){
                List<Case> caseToUpdate = [select Id,FI_Stage__C,Decision__c,Agent_Case_Status__c,Fi_Agent__c,FI_Refire_Toggle__c
            from case where Id=: recordId];
            for(Case caseRecord: caseToUpdate){
                    if(String.isNotBlank(caseRecord.Decision__c) && !caseRecord.FI_Refire_Toggle__c){
                        return 'You cannot refire your decisioned case';
                    }
                    else if(caseRecord.Agent_Case_Status__c == 'Refire'){
                        return 'This case is already re-fired.'; 
                    }else if(caseRecord.FI_Agent__c == null){
                        return 'Please assign an agent before re-firing.'; 
                    }else if(caseRecord.FI_Stage__C == 'FI Verification In Progress'){
                        return 'You cannot refire as the case is still assigned to the agent.';
                    }
                    else{
                        caseRecord.Agent_Case_Status__c = 'Refire';
                    }
                } 
                update caseToUpdate;
                return 'Case was refired.Please ask agent to check';
            }else{
                return 'Something went wrong please try again';
            }
            
            
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
            //return JSON.serialize(e.getMessage());
        }
    }
}

Stack Trace:: Class.SharingUtilityTest.testSetup: line 90, column 1

Error:: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AgentMapping: execution of BeforeInsert

caused by: System.QueryException: unexpected token: 'in'

Class.AgentMappingTriggerHandlerException.beforeInsert: line 50, column 1
Trigger.AgentMapping: line 15, column 1: [ ]

---Method from AgentMappingTriggerHandlerException line 50---

  public static void beforeInsert(List<FI_Agent_Mapping__c> AgentMappingList){
       
        List<String> useridList = new List<String>();
        List<Id> pincodeList = new List<Id>();
        for(FI_Agent_Mapping__c obj : AgentMappingList){
            useridList.add(String.valueOf(obj.get('Fi_Agent__c')));
            pincodeList.add(obj.PinCode__c);
        }
        String agentmappingquery='select id,Pincode_Map__c,Fi_Agent__c from FI_Agent_Mapping__c where in: pincodeList AND Fi_Agent__c IN:useridList';
     //line 50-->   List<FI_Agent_Mapping__c> targetobj=Database.query(agentmappingquery);
        if(targetobj.size() > 0){
            AgentMappingList.get(0).addError( 'User Has already Mapped to the same pincode');   
        }  
    } 

---Trigger---

trigger AgentMapping on FI_Agent_Mapping__c (after insert, after update,before insert, before update) {
if(Trigger.isBefore && Trigger.IsUpdate){
        AgentMappingTriggerHandlerException.beforeUpdate(Trigger.OldMap, Trigger.NewMap, Trigger.New);
    }
    
    if (Trigger.isAfter && Trigger.IsInsert) {
         AgentMappingTriggerHandlerException.afterInsert(Trigger.OldMap, Trigger.NewMap, Trigger.New); 
    }
    
    if(Trigger.IsAfter && Trigger.IsUpdate){
        AgentMappingTriggerHandlerException.afterUpdate(Trigger.OldMap, Trigger.NewMap, Trigger.New);
    }
    
    if(Trigger.IsBefore && Trigger.IsInsert){
        AgentMappingTriggerHandlerException.beforeInsert(Trigger.New);
    }
}

----Main Test Class----

public without sharing class SharingUtility {
    public static void recalculateSharing(String ObjectAPIName, Map<Id,String> sObjectIdVsStage, Map<Id,sObject> sObjectMap) {
            List<sObject> sharingList = new List<sObject>();
            List<Record_Access__mdt> recordAccessMeta = new List<Record_Access__mdt>();
            map<Id, Sobject> shareMap = new Map<Id, Sobject>();
            recordAccessMeta = [SELECT MasterLabel, rowCause__c, userField__c, access__c FROM Record_Access__mdt WHERE MasterLabel IN: sObjectIdVsStage.values() AND Object_API_Name__c =:ObjectAPIName];
            for(Id loanid : sObjectIdVsStage.keyset()) {
                for(Record_Access__mdt mdt: recordAccessMeta) {
                    if(mdt.MasterLabel.equalsIgnoreCase(sObjectIdVsStage.get(loanid)) && sObjectMap.get(loanid).get(mdt.userField__c)!=null ){
                        System.debug('in If');
                        String userid = mdt.userField__c;
                        sharingList.add(getLoanShareRecord(loanid,string.valueof(sObjectMap.get(loanid).get(userid)),mdt.access__c,mdt.rowCause__c));
                        shareMap.putall(sharingList); //when same cpa agent do D1 and D2  duplicate record is getting added in list so make it unique adding in map
                    }
                }
            }
            List<Database.upsertResult> srList = Database.upsert(shareMap.values(), true);
            for(Database.upsertResult dr : srList) {
                if (dr.isSuccess()) {
                    System.debug('Successfully account with ID: ' + dr.getId());
                }
                else {
                    for(Database.Error err : dr.getErrors()) {
                        System.debug('The following error has occurred.');                    
                        System.debug(err.getStatusCode() + ': ' + err.getMessage());
                        System.debug('Account fields that affected this error: ' + err.getFields());
                    }
                }
            }
    }
    public static void shareCaseRecordwithAgent (String sobj,Map<String,String> usercaseMap,String access, String reason){
         caseShareRecordBulk(sobj, usercaseMap, access, reason);
    }
    public static sObject getLoanShareRecord (String parentId, String userId, String access, String reason){
        String sObjectName = Id.valueOf(parentId).getSObjectType().getDescribe().getName();
        System.debug('sObjectName:: '+sObjectName);
        if(sObjectName.endsWithIgnoreCase('__c')) { 
            system.debug('sObjectName:'+sObjectName);
            sObjectName = sObjectName.removeEnd('__c')+'__Share';
            sObject obj = Schema.getGlobalDescribe().get(sObjectName).newSObject();
            obj.put('AccessLevel', access != null ?access : 'Read');
            obj.put('ParentId', parentId);
            obj.put('UserOrGroupId', userId);
            obj.put('rowCause', 'reason');//
            return obj;    
        }
        else if(sObjectName.equalsIgnorecase('Account')) {
            sObjectName = 'AccountShare';
            sObject obj = accountShareRecord(sObjectName,parentId,userId,access,reason);
                 return obj;    
        }else if(sObjectName.equalsIgnorecase('DocumentChecklistItem')) {
            sObjectName = 'DocumentChecklistItemShare';
            sObject obj = docCheckItemShareRecord(sObjectName,parentId,userId,access,reason);
                 return obj;    
        } else if(sObjectName.equalsIgnorecase('Case')) {
              sObjectName = 'CaseShare';
              sObject obj =caseShareRecord(sObjectName,parentId,userId,access,reason);
                 return obj;    
                } else if(sObjectName.equalsIgnorecase('Opportunity')) {
                    sObject obj = opportunityTeamRecord(sObjectName,parentId,userId,access,reason);
                    System.debug('Opportunity Share:: '+obj);
                 return obj;    
                }else{
                  system.debug('inside else:'+sObjectName);
                  return null; 
                }
    }
    @testvisible
    private static sObject opportunityTeamRecord(String sobj,String parentId, String userId, String access, String reason){
        if(userId.startsWith('005')){
        OpportunityTeamMember oldTeamMemberRec = getPrevCreatedOppShare(parentId, userId);
        OpportunityTeamMember oppTeamMember = new OpportunityTeamMember();
        if(oldTeamMemberRec != null){
            oppTeamMember.Id = oldTeamMemberRec.Id;
            oppTeamMember.OpportunityAccessLevel =  access;
        }else{
            oppTeamMember.OpportunityId = parentId;
            oppTeamMember.UserId = userId;
            oppTeamMember.OpportunityAccessLevel =  access;
            oppTeamMember.TeamMemberRole ='Team Member'; 
        }
            System.debug('oppTeamMember:: '+oppTeamMember);
            return oppTeamMember;
        }else{
            return opportunityShareRecord(sobj, parentId, userId, access, reason);
        }
     }
    @testvisible
    private static OpportunityTeamMember getPrevCreatedOppShare(string parentId, string userId){
        try{
        OpportunityTeamMember oppTeamMember = [SELECT Id FROM OpportunityTeamMember WHERE OpportunityId=:parentId AND UserId=:userId Limit 1];
        if(oppTeamMember != null){
            return oppTeamMember;
        }else{
            return null;
        }
        }catch(Exception e){   
            return null;
        }
    }
    @testvisible
    private static sObject opportunityShareRecord(String sobj,String parentId, String userId, String access, String reason){
       OpportunityShare oppShare = new OpportunityShare(OpportunityAccessLevel=access, OpportunityId = parentId,  UserOrGroupId = userId);
        return oppShare;
    }
    @testvisible
    private static sObject accountShareRecord (String sobj,String parentId, String userId, String access, String reason){
          sObject obj = Schema.getGlobalDescribe().get(sobj).newSObject();
          obj.put('AccountAccessLevel', access != null ?access : 'Read');
          obj.put('OpportunityAccessLevel','Read');
          //obj.put('AccountAccessLevel', access != null ?access : 'Read');
          obj.put('AccountId', parentId);
          obj.put('UserOrGroupId', userId);
          // obj.put('rowCause', reason);
          return obj;
     }
    @testvisible
    private static void removeAccess (Set<Id> parentId){
        // delete all the existing sharing of these loan applications 
        System.debug('In removeAccess');
        list<OpportunityShare> loanShareRecords = new list<OpportunityShare>();
        loanShareRecords = [SELECT Id FROM OpportunityShare WHERE OpportunityId in :parentId];
        Database.DeleteResult[] drList = Database.delete(loanShareRecords, false);
    }
    @testvisible
    private static sObject docCheckItemShareRecord (String sobj,String parentId, String userId, String access, String reason){
        sObject obj = Schema.getGlobalDescribe().get(sobj).newSObject();
        obj.put('AccessLevel', access != null ?access : 'Read');
        obj.put('ParentId', parentId);
        obj.put('UserOrGroupId', userId);
        return obj;
     }
    @testvisible
    private static sObject caseShareRecord (String sobj,String parentId, String userId, String access, String reason){
        String query = 'select id from CaseShare where UserOrGroupId =: userId and CaseId =: parentId';
        List<SObject> targetObjRecords = Database.query(query);
        delete targetObjRecords;
        CaseShare obj = new CaseShare(CaseAccessLevel = access ,CaseId = parentId, UserOrGroupId = userId, RowCause = reason);
        return obj;
     }
    @testvisible
    private static void caseShareRecordBulk (String sobj,Map<String,String> parentId,String access, String reason){
        List<Sobject> caseshareList= new List<Sobject>();
        List<String> userIdList=parentId.values();
        Set<String> CaseIdList=parentId.keySet();
        String query = 'select id from CaseShare where UserOrGroupId in: userIdList and CaseId in: CaseIdList';
        List<SObject> targetObjRecords = Database.query(query);
        if(targetObjRecords.size() > 0){
        delete targetObjRecords;    
        }else{
        sendNotification(parentId);    
        }
        for (String key : parentId.keySet()) {
            Sobject sObjec = Schema.getGlobalDescribe().get('CaseShare').newSobject();
            sObjec.put('CaseAccessLevel',access);
            sObjec.put('CaseId',key);
            sObjec.put('UserOrGroupId',parentId.get(key));
            sObjec.put('RowCause',reason);
            caseshareList.add(sObjec); 
        }        
        insert caseshareList;
     }
    @testvisible
    public static void agentMappingShareRecord(Map<String,String> parentId,String access, String reason){
        List<Sobject> caseshareList= new List<Sobject>();
        Set<String> userIdList=parentId.keySet();
        List<String> CaseIdList=parentId.values();
        String query = 'select id from FI_Agent_Mapping__Share where UserOrGroupId in: userIdList and ParentId in: CaseIdList';
        List<SObject> targetObjRecords = Database.query(query);
        delete targetObjRecords;
        for (String key : parentId.keySet()) {
            Sobject sObjec = Schema.getGlobalDescribe().get('FI_Agent_Mapping__Share').newSobject();
            sObjec.put('AccessLevel',access);
            sObjec.put('ParentId',key);
            sObjec.put('UserOrGroupId',parentId.get(key));
            sObjec.put('RowCause',reason);
            caseshareList.add(sObjec); 
        }        
        insert caseshareList;
     }
    public static void setDefaultOwner(List<Loan_Application_Actors__c> loanApplicationActorsList){
        insert loanApplicationActorsList;
    }
    @testvisible
    public static void removeAccess(Map<String,String> parentId){
        List<String> userIdList=parentId.values();
        Set<String> CaseIdList=parentId.keySet();
        String query = 'select id,UserOrGroupId,CaseAccessLevel,CaseId from CaseShare where UserOrGroupId in: userIdList and CaseId in: CaseIdList';
        List<sObject> targetObjRecords = Database.query(query);
        if(targetObjRecords.size() > 0){
            delete targetObjRecords;    
        }
    }
    public static void sendNotification(Map<String,String> caseuser){
        Id typeId = [SELECT Id FROM CUstomNotificationType WHERE DeveloperName = 'FI_Agent_Notification'].Id;
        for (String key : caseuser.keySet()) {
            Messaging.CustomNotification notification = new Messaging.CustomNotification();
            notification.setBody('FI Case Has Been Assigned To You');
            notification.setTitle('FI Case Has Been Assigned To You');
            notification.setSenderId(Userinfo.getUserId());
            notification.setNotificationTypeId(typeId );
            notification.setTargetId(key); // target object id
            notification.send(new Set<String> { caseuser.get(key) }); // target user id.
        } 
    }
    public static List<Case> getCasesToShare(Set<Id> loanAppIdSet){
      return  [SELECT Id, Loan_Application__c FROM Case WHERE Loan_Application__c IN: loanAppIdSet];
    }
    public static void tvrCasesValidation(map<Id, Opportunity> lstCPAReviewApplications, map<Id, Opportunity>newMap){
                    if(lstCPAReviewApplications.size() > 0){
                List<AggregateResult> lstAggrReult = [SELECT COUNT(Id) cnt, Loan_Application__c  FROM Case WHERE Loan_Application__c IN: lstCPAReviewApplications.KeySet() AND Type Like 'TVR%' GROUP BY Loan_Application__c];
                System.debug('lstAggrReult:: '+lstAggrReult);
                if(lstAggrReult.size() > 0){
                for(AggregateResult aggrResult :  lstAggrReult){ 
                    String oppId = String.ValueOf(aggrResult.get('Loan_Application__c'));
                    Opportunity loanApplication = newMap.get(oppId);
                    System.debug('aggrResult:: '+aggrResult);
                    if(Integer.ValueOf(aggrResult.get('cnt')) < 2){
                    loanApplication.addError('Before Submitting to CPA Review, it is must to raise TVR CPV');
                    }
                }
                }else{
                    newMap.values()[0].addError('Before Submitting to CPA Review, it is must to raise TVR CPV');
                }
            }
    }
}

Hello guys, I want to remove Change Owner button form case list view drop-down.I remove that button from Compact layout succesfully but not able to remove from drop-down.

User-added image
I tried following link but no luck.

https://salesforce.stackexchange.com/questions/298187/how-can-i-remove-change-owner-button-from-a-list-view-in-salesforce
Thanks.

Hello Guys,

I need a LWC component which will show(Preview) Uploaded File/Image. Following component is working,But its not previewing the img/file and after refreshing the page file/image is disappearing

I dont need Preview button,but expecting 5cm X 5cm preview after uploading.

Please help me.

hunterFileUpload.html

<template>
    <lightning-card title="Hunter Offline responce excel file">
        <div class="slds-p-horizontal_x-small" >
            <lightning-layout>
                <lightning-layout-item size="6">
                    <div class="slds-p-left_medium"> 
                        <lightning-file-upload
                            label="Attach Files"
                            name="uploadFile"
                            accept={acceptedFormats}
                            record-id={recordId}    
                            onuploadfinished={handleUploadFinished} multiple>
                        </lightning-file-upload>
                    </div> 
                </lightning-layout-item>
                <lightning-layout-item size="6">
                    <div class="slds-p-left_medium">
                        Uploaded Files: <br/>
                        <template for:each={lstAllFiles} for:item="fileIterator">
                            <div key={fileIterator} style="margin-top:10px;">
                                <lightning-icon icon-name="doctype:image" size="small" title="Image"></lightning-icon>
                                  {fileIterator}
                            </div>
                        </template>
                    </div>
                </lightning-layout-item>
            </lightning-layout>
        </div>
    </lightning-card>
</template>

hunterFileUpload.js

import { LightningElement,track,api } from 'lwc';
export default class HunterFileUpload extends LightningElement {
    @track lstAllFiles = [];
    @api recordId;
    get acceptedFormats() {
        return ['.pdf', '.jpg'];
    }
    handleUploadFinished(event) {
        // Get the list of uploaded files
        const lstUploadedFiles = event.detail.files;
        lstUploadedFiles.forEach(fileIterator => this.lstAllFiles.push(fileIterator.name));
    }
}

hunterFileUpload.js-meta.xml

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>51.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__AppPage</target>
        <target>lightning__RecordPage</target>
        <target>lightning__HomePage</target>
        <target>lightningCommunity__Page</target>
        <target>lightningCommunity__Default</target>
    </targets>
    <targetConfigs>
        <targetConfig targets="lightningCommunity__Default">
            <property name="recordId" type="String" ></property>
        </targetConfig>
    </targetConfigs>    
</LightningComponentBundle>

Thanks.

public class YB_RCUReportVFController {
    
     public Id caseId;
     public YB_RCUReportWrapper rcuReportData{get;set;}
    
      public YB_RCUReportVFController()
    {
        this.caseId = Apexpages.currentpage().getparameters().get('id');
        this.rcuReportData = new YB_RCUReportWrapper(this.caseId);
        
        
    }

}

User-added image

User-added image

Error element myRule_1_A1 (FlowActionCall).
Probably Limit Exceeded or 0 recipients --- Probably Limit Exceeded or 0 recipients

Flow Details
Flow API Name: RCU_Email_alert
Type: Record Change Process
Version: 1
Status: Active

Flow Interview Details
Interview Label: RCU_Email_alert-1_InterviewLabel
Interview GUID: 2360926e2f91946c38bb3db0096017d1a6e20dd-7350
Current User: Automated Process (0058p000000HgMq)
Start time: 15/11/2021, 3:53 pm

 

Hello Everyone...

I have one picklist  Hunter_Final_Status__c  having Pending,Clear,Decline,Suspect values.

Condition:: Once any of (Hunter_Final_Status__c) above value is selected, that value should populate/Display in Hunter_Status__c (Text).

 

public class PL_FIAutoAllocationCounterResetBatch  implements Database.Batchable<sObject> {
    
    public Database.QueryLocator start(Database.BatchableContext BC){
        String query = 'SELECT id, Count__c FROM Sales_To_CPA_Allocation_Rule1__c WHERE Count__c !=0';
        return Database.getQueryLocator(query);

    }
    
    public void execute(Database.BatchableContext BC, List<Sales_To_CPA_Allocation_Rule1__c> scope){
        List<Sales_To_CPA_Allocation_Rule1__c> lstRulesToUpdate = new List<Sales_To_CPA_Allocation_Rule1__c>();
        for(Sales_To_CPA_Allocation_Rule1__c rule : scope){
             rule.Count__c = 0;
            lstRulesToUpdate.add(rule);
        }
        if(lstRulesToUpdate.size() > 0){
        update lstRulesToUpdate;
        }
    }
    
    public void finish(Database.BatchableContext BC){
    }
}

Please help me.

Hello Everyone...I am not aware how to write a test class  which include Try Catch and having Aura unabled.... Please help. So I can learn too.

public with sharing class FISuperVisorRefireChecker {

    @AuraEnabled
    public static string refireCase(String recordId){
        try {
            if(String.isNotBlank(recordId)){
                List<Case> caseToUpdate = [select Id,FI_Stage__C,Decision__c,Agent_Case_Status__c,Fi_Agent__c,FI_Refire_Toggle__c
            from case where Id=: recordId];
            for(Case caseRecord: caseToUpdate){
                    if(String.isNotBlank(caseRecord.Decision__c) && !caseRecord.FI_Refire_Toggle__c){
                        return 'You cannot refire your decisioned case';
                    }
                    else if(caseRecord.Agent_Case_Status__c == 'Refire'){
                        return 'This case is already re-fired.'; 
                    }else if(caseRecord.FI_Agent__c == null){
                        return 'Please assign an agent before re-firing.'; 
                    }else if(caseRecord.FI_Stage__C == 'FI Verification In Progress'){
                        return 'You cannot refire as the case is still assigned to the agent.';
                    }
                    else{
                        caseRecord.Agent_Case_Status__c = 'Refire';
                    }
                } 
                update caseToUpdate;
                return 'Case was refired.Please ask agent to check';
            }else{
                return 'Something went wrong please try again';
            }
            
            
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
            //return JSON.serialize(e.getMessage());
        }
    }
}

Stack Trace:: Class.SharingUtilityTest.testSetup: line 90, column 1

Error:: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AgentMapping: execution of BeforeInsert

caused by: System.QueryException: unexpected token: 'in'

Class.AgentMappingTriggerHandlerException.beforeInsert: line 50, column 1
Trigger.AgentMapping: line 15, column 1: [ ]

---Method from AgentMappingTriggerHandlerException line 50---

  public static void beforeInsert(List<FI_Agent_Mapping__c> AgentMappingList){
       
        List<String> useridList = new List<String>();
        List<Id> pincodeList = new List<Id>();
        for(FI_Agent_Mapping__c obj : AgentMappingList){
            useridList.add(String.valueOf(obj.get('Fi_Agent__c')));
            pincodeList.add(obj.PinCode__c);
        }
        String agentmappingquery='select id,Pincode_Map__c,Fi_Agent__c from FI_Agent_Mapping__c where in: pincodeList AND Fi_Agent__c IN:useridList';
     //line 50-->   List<FI_Agent_Mapping__c> targetobj=Database.query(agentmappingquery);
        if(targetobj.size() > 0){
            AgentMappingList.get(0).addError( 'User Has already Mapped to the same pincode');   
        }  
    } 

---Trigger---

trigger AgentMapping on FI_Agent_Mapping__c (after insert, after update,before insert, before update) {
if(Trigger.isBefore && Trigger.IsUpdate){
        AgentMappingTriggerHandlerException.beforeUpdate(Trigger.OldMap, Trigger.NewMap, Trigger.New);
    }
    
    if (Trigger.isAfter && Trigger.IsInsert) {
         AgentMappingTriggerHandlerException.afterInsert(Trigger.OldMap, Trigger.NewMap, Trigger.New); 
    }
    
    if(Trigger.IsAfter && Trigger.IsUpdate){
        AgentMappingTriggerHandlerException.afterUpdate(Trigger.OldMap, Trigger.NewMap, Trigger.New);
    }
    
    if(Trigger.IsBefore && Trigger.IsInsert){
        AgentMappingTriggerHandlerException.beforeInsert(Trigger.New);
    }
}

----Main Test Class----

public without sharing class SharingUtility {
    public static void recalculateSharing(String ObjectAPIName, Map<Id,String> sObjectIdVsStage, Map<Id,sObject> sObjectMap) {
            List<sObject> sharingList = new List<sObject>();
            List<Record_Access__mdt> recordAccessMeta = new List<Record_Access__mdt>();
            map<Id, Sobject> shareMap = new Map<Id, Sobject>();
            recordAccessMeta = [SELECT MasterLabel, rowCause__c, userField__c, access__c FROM Record_Access__mdt WHERE MasterLabel IN: sObjectIdVsStage.values() AND Object_API_Name__c =:ObjectAPIName];
            for(Id loanid : sObjectIdVsStage.keyset()) {
                for(Record_Access__mdt mdt: recordAccessMeta) {
                    if(mdt.MasterLabel.equalsIgnoreCase(sObjectIdVsStage.get(loanid)) && sObjectMap.get(loanid).get(mdt.userField__c)!=null ){
                        System.debug('in If');
                        String userid = mdt.userField__c;
                        sharingList.add(getLoanShareRecord(loanid,string.valueof(sObjectMap.get(loanid).get(userid)),mdt.access__c,mdt.rowCause__c));
                        shareMap.putall(sharingList); //when same cpa agent do D1 and D2  duplicate record is getting added in list so make it unique adding in map
                    }
                }
            }
            List<Database.upsertResult> srList = Database.upsert(shareMap.values(), true);
            for(Database.upsertResult dr : srList) {
                if (dr.isSuccess()) {
                    System.debug('Successfully account with ID: ' + dr.getId());
                }
                else {
                    for(Database.Error err : dr.getErrors()) {
                        System.debug('The following error has occurred.');                    
                        System.debug(err.getStatusCode() + ': ' + err.getMessage());
                        System.debug('Account fields that affected this error: ' + err.getFields());
                    }
                }
            }
    }
    public static void shareCaseRecordwithAgent (String sobj,Map<String,String> usercaseMap,String access, String reason){
         caseShareRecordBulk(sobj, usercaseMap, access, reason);
    }
    public static sObject getLoanShareRecord (String parentId, String userId, String access, String reason){
        String sObjectName = Id.valueOf(parentId).getSObjectType().getDescribe().getName();
        System.debug('sObjectName:: '+sObjectName);
        if(sObjectName.endsWithIgnoreCase('__c')) { 
            system.debug('sObjectName:'+sObjectName);
            sObjectName = sObjectName.removeEnd('__c')+'__Share';
            sObject obj = Schema.getGlobalDescribe().get(sObjectName).newSObject();
            obj.put('AccessLevel', access != null ?access : 'Read');
            obj.put('ParentId', parentId);
            obj.put('UserOrGroupId', userId);
            obj.put('rowCause', 'reason');//
            return obj;    
        }
        else if(sObjectName.equalsIgnorecase('Account')) {
            sObjectName = 'AccountShare';
            sObject obj = accountShareRecord(sObjectName,parentId,userId,access,reason);
                 return obj;    
        }else if(sObjectName.equalsIgnorecase('DocumentChecklistItem')) {
            sObjectName = 'DocumentChecklistItemShare';
            sObject obj = docCheckItemShareRecord(sObjectName,parentId,userId,access,reason);
                 return obj;    
        } else if(sObjectName.equalsIgnorecase('Case')) {
              sObjectName = 'CaseShare';
              sObject obj =caseShareRecord(sObjectName,parentId,userId,access,reason);
                 return obj;    
                } else if(sObjectName.equalsIgnorecase('Opportunity')) {
                    sObject obj = opportunityTeamRecord(sObjectName,parentId,userId,access,reason);
                    System.debug('Opportunity Share:: '+obj);
                 return obj;    
                }else{
                  system.debug('inside else:'+sObjectName);
                  return null; 
                }
    }
    @testvisible
    private static sObject opportunityTeamRecord(String sobj,String parentId, String userId, String access, String reason){
        if(userId.startsWith('005')){
        OpportunityTeamMember oldTeamMemberRec = getPrevCreatedOppShare(parentId, userId);
        OpportunityTeamMember oppTeamMember = new OpportunityTeamMember();
        if(oldTeamMemberRec != null){
            oppTeamMember.Id = oldTeamMemberRec.Id;
            oppTeamMember.OpportunityAccessLevel =  access;
        }else{
            oppTeamMember.OpportunityId = parentId;
            oppTeamMember.UserId = userId;
            oppTeamMember.OpportunityAccessLevel =  access;
            oppTeamMember.TeamMemberRole ='Team Member'; 
        }
            System.debug('oppTeamMember:: '+oppTeamMember);
            return oppTeamMember;
        }else{
            return opportunityShareRecord(sobj, parentId, userId, access, reason);
        }
     }
    @testvisible
    private static OpportunityTeamMember getPrevCreatedOppShare(string parentId, string userId){
        try{
        OpportunityTeamMember oppTeamMember = [SELECT Id FROM OpportunityTeamMember WHERE OpportunityId=:parentId AND UserId=:userId Limit 1];
        if(oppTeamMember != null){
            return oppTeamMember;
        }else{
            return null;
        }
        }catch(Exception e){   
            return null;
        }
    }
    @testvisible
    private static sObject opportunityShareRecord(String sobj,String parentId, String userId, String access, String reason){
       OpportunityShare oppShare = new OpportunityShare(OpportunityAccessLevel=access, OpportunityId = parentId,  UserOrGroupId = userId);
        return oppShare;
    }
    @testvisible
    private static sObject accountShareRecord (String sobj,String parentId, String userId, String access, String reason){
          sObject obj = Schema.getGlobalDescribe().get(sobj).newSObject();
          obj.put('AccountAccessLevel', access != null ?access : 'Read');
          obj.put('OpportunityAccessLevel','Read');
          //obj.put('AccountAccessLevel', access != null ?access : 'Read');
          obj.put('AccountId', parentId);
          obj.put('UserOrGroupId', userId);
          // obj.put('rowCause', reason);
          return obj;
     }
    @testvisible
    private static void removeAccess (Set<Id> parentId){
        // delete all the existing sharing of these loan applications 
        System.debug('In removeAccess');
        list<OpportunityShare> loanShareRecords = new list<OpportunityShare>();
        loanShareRecords = [SELECT Id FROM OpportunityShare WHERE OpportunityId in :parentId];
        Database.DeleteResult[] drList = Database.delete(loanShareRecords, false);
    }
    @testvisible
    private static sObject docCheckItemShareRecord (String sobj,String parentId, String userId, String access, String reason){
        sObject obj = Schema.getGlobalDescribe().get(sobj).newSObject();
        obj.put('AccessLevel', access != null ?access : 'Read');
        obj.put('ParentId', parentId);
        obj.put('UserOrGroupId', userId);
        return obj;
     }
    @testvisible
    private static sObject caseShareRecord (String sobj,String parentId, String userId, String access, String reason){
        String query = 'select id from CaseShare where UserOrGroupId =: userId and CaseId =: parentId';
        List<SObject> targetObjRecords = Database.query(query);
        delete targetObjRecords;
        CaseShare obj = new CaseShare(CaseAccessLevel = access ,CaseId = parentId, UserOrGroupId = userId, RowCause = reason);
        return obj;
     }
    @testvisible
    private static void caseShareRecordBulk (String sobj,Map<String,String> parentId,String access, String reason){
        List<Sobject> caseshareList= new List<Sobject>();
        List<String> userIdList=parentId.values();
        Set<String> CaseIdList=parentId.keySet();
        String query = 'select id from CaseShare where UserOrGroupId in: userIdList and CaseId in: CaseIdList';
        List<SObject> targetObjRecords = Database.query(query);
        if(targetObjRecords.size() > 0){
        delete targetObjRecords;    
        }else{
        sendNotification(parentId);    
        }
        for (String key : parentId.keySet()) {
            Sobject sObjec = Schema.getGlobalDescribe().get('CaseShare').newSobject();
            sObjec.put('CaseAccessLevel',access);
            sObjec.put('CaseId',key);
            sObjec.put('UserOrGroupId',parentId.get(key));
            sObjec.put('RowCause',reason);
            caseshareList.add(sObjec); 
        }        
        insert caseshareList;
     }
    @testvisible
    public static void agentMappingShareRecord(Map<String,String> parentId,String access, String reason){
        List<Sobject> caseshareList= new List<Sobject>();
        Set<String> userIdList=parentId.keySet();
        List<String> CaseIdList=parentId.values();
        String query = 'select id from FI_Agent_Mapping__Share where UserOrGroupId in: userIdList and ParentId in: CaseIdList';
        List<SObject> targetObjRecords = Database.query(query);
        delete targetObjRecords;
        for (String key : parentId.keySet()) {
            Sobject sObjec = Schema.getGlobalDescribe().get('FI_Agent_Mapping__Share').newSobject();
            sObjec.put('AccessLevel',access);
            sObjec.put('ParentId',key);
            sObjec.put('UserOrGroupId',parentId.get(key));
            sObjec.put('RowCause',reason);
            caseshareList.add(sObjec); 
        }        
        insert caseshareList;
     }
    public static void setDefaultOwner(List<Loan_Application_Actors__c> loanApplicationActorsList){
        insert loanApplicationActorsList;
    }
    @testvisible
    public static void removeAccess(Map<String,String> parentId){
        List<String> userIdList=parentId.values();
        Set<String> CaseIdList=parentId.keySet();
        String query = 'select id,UserOrGroupId,CaseAccessLevel,CaseId from CaseShare where UserOrGroupId in: userIdList and CaseId in: CaseIdList';
        List<sObject> targetObjRecords = Database.query(query);
        if(targetObjRecords.size() > 0){
            delete targetObjRecords;    
        }
    }
    public static void sendNotification(Map<String,String> caseuser){
        Id typeId = [SELECT Id FROM CUstomNotificationType WHERE DeveloperName = 'FI_Agent_Notification'].Id;
        for (String key : caseuser.keySet()) {
            Messaging.CustomNotification notification = new Messaging.CustomNotification();
            notification.setBody('FI Case Has Been Assigned To You');
            notification.setTitle('FI Case Has Been Assigned To You');
            notification.setSenderId(Userinfo.getUserId());
            notification.setNotificationTypeId(typeId );
            notification.setTargetId(key); // target object id
            notification.send(new Set<String> { caseuser.get(key) }); // target user id.
        } 
    }
    public static List<Case> getCasesToShare(Set<Id> loanAppIdSet){
      return  [SELECT Id, Loan_Application__c FROM Case WHERE Loan_Application__c IN: loanAppIdSet];
    }
    public static void tvrCasesValidation(map<Id, Opportunity> lstCPAReviewApplications, map<Id, Opportunity>newMap){
                    if(lstCPAReviewApplications.size() > 0){
                List<AggregateResult> lstAggrReult = [SELECT COUNT(Id) cnt, Loan_Application__c  FROM Case WHERE Loan_Application__c IN: lstCPAReviewApplications.KeySet() AND Type Like 'TVR%' GROUP BY Loan_Application__c];
                System.debug('lstAggrReult:: '+lstAggrReult);
                if(lstAggrReult.size() > 0){
                for(AggregateResult aggrResult :  lstAggrReult){ 
                    String oppId = String.ValueOf(aggrResult.get('Loan_Application__c'));
                    Opportunity loanApplication = newMap.get(oppId);
                    System.debug('aggrResult:: '+aggrResult);
                    if(Integer.ValueOf(aggrResult.get('cnt')) < 2){
                    loanApplication.addError('Before Submitting to CPA Review, it is must to raise TVR CPV');
                    }
                }
                }else{
                    newMap.values()[0].addError('Before Submitting to CPA Review, it is must to raise TVR CPV');
                }
            }
    }
}

After execution of test ,Its showing errors for these two fields--

  FAM3.Fi_Agent__c='FAMagent3';
  FAM3.PinCode__c='400 003';

Main Class::::

public class AgentMappingTriggerHandlerException  extends Exception {
public static void afterInsert(map<Id, FI_Agent_Mapping__c> oldMap, map<Id, FI_Agent_Mapping__c> newMap, List<FI_Agent_Mapping__c> newList){
    
        Map<String,String> AgentMappingMap = new Map<String,String>();
        Map<String,String> GroupMap = new Map<String,String>();
        Map<String,String> agentmappingUserMap = new Map<String,String>();
        List<String> AgencyList  = new List<String>();
        
        for(Sobject obj : newList){
            AgentMappingMap.put(String.valueOf(obj.get('Id')),String.valueOf(obj.get('Agency_Name__c')));
            AgencyList.add(String.valueOf(obj.get('Agency_Name__c')));
        }
    system.debug('AgentMappingMap==='+AgentMappingMap);
    
        
        String groupquery='select id,name from Group where name in: AgencyList';
        List<Sobject> targetobj=Database.query(groupquery);
        if(targetobj.size() > 0){
            for(Sobject obj : targetobj){
                GroupMap.put(String.valueOf(obj.get('Name')),String.valueOf(obj.get('Id')));   
                
            }
            system.debug('Group Map==='+GroupMap);
        }
    
     for(Sobject obj : newList){
            agentmappingUserMap.put(String.valueOf(obj.get('Id')),GroupMap.get(String.valueOf(AgentMappingMap.get(String.valueOf(obj.get('Id'))))));
     system.debug('agentmappingUserMap=='+agentmappingUserMap);   
     }
    
        SharingUtility.agentMappingShareRecord(agentmappingUserMap,'Edit', 'Manual');        
     }
    
    public static void beforeUpdate(map<Id, FI_Agent_Mapping__c> oldMap, map<Id, FI_Agent_Mapping__c> newMap, List<FI_Agent_Mapping__c> newList){
           
    }

    public static void afterUpdate(map<Id, FI_Agent_Mapping__c> olaMap, map<Id, FI_Agent_Mapping__c> newMap, List<FI_Agent_Mapping__c> newList){
    }
   
    public static void beforeInsert(List<FI_Agent_Mapping__c> AgentMappingList){
       
        List<String> useridList = new List<String>();
        List<Id> pincodeList = new List<Id>();
        for(FI_Agent_Mapping__c obj : AgentMappingList){
            useridList.add(String.valueOf(obj.get('Fi_Agent__c')));
            pincodeList.add(obj.PinCode__c);
        }
        String agentmappingquery='select id,Pincode_Map__c,Fi_Agent__c from FI_Agent_Mapping__c where PinCode__c in: pincodeList';
        List<FI_Agent_Mapping__c> targetobj=Database.query(agentmappingquery);
        if(targetobj.size() > 0){
            AgentMappingList.get(0).addError( 'User Has already Mapped to the same pincode');   
        }
    } 
}

Please Correct my Test class:::

@isTest
public class AgentMappingTriggerHandlerExceptionTest {
    
@isTest         
    public static void afterInsertTest(){
    
     FI_Agent_Mapping__c FAM1 = new FI_Agent_Mapping__c();
      FAM1.Name ='FAMname1';
      FAM1.Agency_Name__c='A R ASSOCIATES';
      FAM1.Fi_Agent__c='FAMagent1';
      FAM1.PinCode__c='400 001';
      insert FAM1;
      
      FI_Agent_Mapping__c FAM2 = new FI_Agent_Mapping__c();
      FAM2.Name ='FAMname2';
      FAM2.Agency_Name__c= 'COGENT';
      FAM2.Fi_Agent__c='FAMagent2';
      FAM2.PinCode__c='400 002';
      insert FAM2;
       
      
      Map<Id,FI_Agent_Mapping__c> afterInsertMap  =  New Map<Id,FI_Agent_Mapping__c>();
      FI_Agent_Mapping__c FAM3 = new FI_Agent_Mapping__c();
      FAM3.Name ='FAMname3';
      FAM3.Agency_Name__c= 'BEST SERVICES';
      FAM3.Fi_Agent__c='FAMagent3';
      FAM3.PinCode__c='400 003';
      insert FAM3;
      afterInsertMap.put(FAM3.Id,FAM3);
      
      List<FI_Agent_Mapping__c> newListA = new List<FI_Agent_Mapping__c>();
      FI_Agent_Mapping__c FAM4 = new FI_Agent_Mapping__c();
      FAM4.Name ='FAMname4';
      FAM4.Agency_Name__c='BANRAD FINSERV';
      FAM4.Fi_Agent__c='FAMagent4';
      FAM4.PinCode__c='400 004';
      insert FAM4;
      newListA.add(FAM4);
        
       Test.startTest();
       AgentMappingTriggerHandlerException.afterInsert(afterInsertMap,afterInsertMap,newListA ); 
       Test.stopTest();
      
    }
@isTest
    public static void beforeUpdateTest(){
        
    }
@isTest
    public static void afterUpdateTest(){
        
    }
@isTest
    public static void beforeInsertTest(){
    
    }
}

 

Modify an AppExchange dashboard
Maria Jimenez is looking for reports and dashboards on AppExchange to track her team's transition to Lightning Experience. Install the AppExchange Dashboard Pack for Sales, Marketing and Service package into your Trailhead Playground and make some modifications. 

You’ll need your hands-on org username and password to complete this challenge. If you're using a Trailhead Playground, this article shows you how to find your username and reset your password. If you have trouble installing the package, follow the steps in this article.

In your Trailhead Playground, install the AppExchange Dashboard Pack for Sales, Marketing and Service.
Clone the 1-Account, Contact & Opportunity Data Quality dashboard and name it My Account and Contact Dashboard.
Add a dashboard filter on the Billing City field so that the dashboard only shows info about Accounts in London.
Save and refresh the dashboard.

I am trying to complete this challenge from past 4 hours still am not able to do it. Please help me guys! Guide me!!!!
Hi All,

I am writing a test class for a batch class but my current code coverage is 0% and not able to cover. I am geetting error as:
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_FILTER_VALIDATION_EXCEPTION, Value does not exist or does not match filter criteria.: [Account__c]
Batch class is as belows:
global class UpdatePickUpstatusBatch implements 
    Database.Batchable<sObject>, Database.Stateful {
    

    global Database.QueryLocator start(Database.BatchableContext bc) {
        return Database.getQueryLocator('SELECT ID, Pickup_Date__c, Pickup_Status__c, Name FROM Pickup_Request__c Where Pickup_Date__c != null and Pickup_Status__c==\'Waitlisted\'');

    }

    global void execute(Database.BatchableContext bc, List<Pickup_Request__c> PRScope){
        // process each batch of records
        List<Pickup_Request__c> updateprlist = new List<Pickup_Request__c>();
        for (Pickup_Request__c pr : PRScope) {
           if(Date.today()==pr.Pickup_Date__c-Integer.valueof(Label.PickDateDaysforBatch))
           {
               pr.Pickup_Status__c = 'Open';
               updateprlist.add(pr);
                // make http callouts here Start
                
                
                // End              
           }
        }
        if(!updateprlist.IsEmpty()){
            update updateprlist;
        }
    }    

    global void finish(Database.BatchableContext bc){
        
    }    

}

My test class is as belows:
 
@isTest
public class UpdatePickUpstatusBatch_Test {
    static testMethod void UpdatePickUpstatusBatchtest1(){
    
    Schema.DescribeSObjectResult ACCobj1 = Schema.SObjectType.Account;
    Map<String,Schema.RecordTypeInfo> rtMapByName = ACCobj1 .getRecordTypeInfosByName();
    Schema.RecordTypeInfo rtByName = rtMapByName.get('Site');
    ID ACCSiteRecTypeid = rtByName.getRecordTypeId(); 
    
    Schema.DescribeSObjectResult ACCobj2 = Schema.SObjectType.Account;
    Map<String,Schema.RecordTypeInfo> rtMapByName2 = ACCobj2 .getRecordTypeInfosByName();
    Schema.RecordTypeInfo rtByName2 = rtMapByName2.get('Customer');
    ID ACCCustRecTypeid = rtByName2.getRecordTypeId(); 
    
    Schema.DescribeSObjectResult ACCobj3 = Schema.SObjectType.Account;
    Map<String,Schema.RecordTypeInfo> rtMapByName3 = ACCobj3 .getRecordTypeInfosByName();
    Schema.RecordTypeInfo rtByName3 = rtMapByName3.get('Billing');
    ID ACCBillingRecTypeid = rtByName3.getRecordTypeId(); 
    
        
        
        Account AccRecCustomer = new Account();
            AccRecCustomer.Name = 'Acme';
            AccRecCustomer.Phone = '1234';            
            AccRecCustomer.RecordTypeId= ACCCustRecTypeid;
            AccRecCustomer.Password__c = 'test data';
            AccRecCustomer.Status__c = 'Active';
        insert AccRecCustomer;
        
        Account AccRec = new Account();
            AccRec.Name = 'Acme';
            AccRec.Phone = '1234';
            AccRec.Parent = AccRecCustomer;
        
           //AccRec.Parent =  AccRecCustomer.id;
            AccRec.Status__c = 'Active';
            AccRec.RecordTypeId= ACCSiteRecTypeid;
            AccRec.Password__c = 'test data';
        insert AccRec;
        
        Account AccRecBilling = new Account();
            AccRecBilling.Name = 'Acme';
            AccRecBilling.Parent = AccRecCustomer;
            AccRecBilling.Phone = '1234';
            AccRecBilling.Status__c = 'Active';
            AccRecBilling.RecordTypeId= ACCBillingRecTypeid;
            
        insert AccRecBilling;

               
        Contact ConRec = new Contact();
            ConRec.FirstName = 'John';
            ConRec.LastName = 'Smith';
            ConRec.Phone = '1234';
            ConRec.Email = 'abc@gmail.com';
            
        insert ConRec;
        
         Contact ConRec1 = new Contact();
            ConRec1.FirstName = 'John1';
            ConRec1.LastName = 'Smith1';
            ConRec1.Phone = '12345';
            ConRec1.Email = 'abc1@gmail.com';
            
        insert ConRec1;
        
        Address__c AddRec = new Address__c();
            AddRec.Address1__c = 'G  370 Docklands Dr';
            AddRec.Country__c = 'AUSTRALIA';
            AddRec.State__c = 'VIC';
            AddRec.Suburb__c = 'Docklands';
            AddRec.Zipcode__c = 3008;
            AddRec.Shipping_Address_Validation_Status__c = 'Verified by Experian';
            AddRec.Shipping_Address_Validation_Timestamp__c = system.today();
            
        Insert AddRec;
        String AddRecId = AddRec.id; 
        CustAddrAssoc__c  CustAddRec = new CustAddrAssoc__c ();
            CustAddRec.Account__c = AccRec.id;
            CustAddRec.Address__c = AddRec.id; 
            CustAddRec.Type__c = 'Site';
            CustAddRec.InActive__c = false;
        
        Insert CustAddRec;
        
        Suburbs__c  SuburRec = new Suburbs__c ();
            SuburRec.Name = 'DOCKLANDS';
            SuburRec.Post_Code__c = '3008';
            SuburRec.State__c = 'VIC';
            SuburRec.Depot__c = 'MEL';
            SuburRec.City__c = '818 Bourke Street';
         
        insert SuburRec; 
        
        Holiday__c  HolRec = new Holiday__c ();
            HolRec.Name = 'ADELAIDE CUP DAY';
            HolRec.Type__c = 'Normal';
            HolRec.State_Name__c = 'VIC';
            HolRec.Start_Date__c = System.today();
            HolRec.End_Date__c = System.today()+2;
        Insert HolRec ;
        
        Pickup_Request__c  PickReqRec = new Pickup_Request__c();
        
           /** PickReqRec.Pickup_Type__c = 'Pickup';
            PickReqRec.Pickup_Status__c = 'Draft';
            PickReqRec.Source__c = 'Email';
            PickReqRec.Third_Party_Contact__c = ConRec1.id;
            PickReqRec.Contact__c = ConRec.id;
            PickReqRec.Billing_A_c__c = AccRecBilling.id;
            PickReqRec.Ready_Time__c = '12:00';
            PickReqRec.Close_Time__c = '19:00';
            PickReqRec.SuburbT__c = 'DOCKLANDS';
            PickReqRec.Pickup_Date__c = System.today()+1;
            PickReqRec.State__c = 'test Sate';
            PickReqRec.Service__c ='Priority';
            PickReqRec.Total_Wt__c = 3000;
            //PickReqRec.Address__c = AddRec.id;
            PickReqRec.password__c = 'test data';
            
        Insert PickReqRec;**/
       
            PickReqRec.Pickup_Type__c = 'Pickup';
            PickReqRec.Pickup_Status__c = 'Waitlisted';
            PickReqRec.Source__c = 'Email';
            PickReqRec.Third_Party_Contact__c = ConRec1.id;
            PickReqRec.Contact__c = ConRec.id;
            PickReqRec.Billing_A_c__c = AccRecBilling.id;
            PickReqRec.Ready_Time__c = '12:00';
            PickReqRec.Close_Time__c = '19:00';
            PickReqRec.SuburbT__c = 'DOCKLANDS';
            PickReqRec.Pickup_Date__c = System.today()+1;
            PickReqRec.State__c = 'test Sate';
            PickReqRec.Service__c ='Priority';
            PickReqRec.Total_Wt__c = 3000;
            PickReqRec.Address__c = CustAddRec.id;
            PickReqRec.password__c = 'test data';
            PickReqRec.Destination_SuburbL__c = SuburRec.id;
            PickReqRec.H_cm__c = 444;
            PickReqRec.Item_Description__c ='Item';
            PickReqRec.L_cm__c = 44;
            PickReqRec.No_of_Items__c =4;
            PickReqRec.Customer__c = AccRecCustomer.id;
            //PickReqRec.Customer__c = AccRec.id;
        	PickReqRec.Account__c =AccRec.id;

            PickReqRec.W_cm__c = 400;
            PickReqRec.Food_Stuff__c  = 'Yes';
            
        Insert PickReqRec;
        
        
       
        Pickup_Request__c PickReqRecObj = [Select id ,Pickup_Status__c ,Pickup_Date__c from Pickup_Request__c  where id =:PickReqRec.id LIMIT 1];
        
        System.debug('----->'+PickReqRecObj );

        //PickReqRec.Pickup_Status__c = 'Open';
        //update PickReqRec;
        
        Test.startTest();

        UpdatePickUpstatusBatch UpdateBatch = new UpdatePickUpstatusBatch();
          //DataBase.executeBatch(UpdateBatch);
        ID batchprocessid = Database.executeBatch(UpdateBatch);
        Test.stopTest();
    }
}

Below is the look up filter:
Object-Pickup Request
Field label: Site
Field API: Account__c
User-added image

When I removed the filter then my code coverage becomes 72% but that is not a correct approach. I need not have to remove the filter infact I do need to cover the same in my test class which I am not getting.

Kindly help me

Thanks & Regards,
Harjeet
 

trigger getmanager on Opp__c ( before update){
Set<Id> id= new Set<Id>();
Set<String> empid=new Set<String>();
Set<String> mngid=new Set<String>();
List<Opp__c> OppyLocation = new List<Opp__c>();

for (Opp__c opp:trigger.old){
  id.add(trigger.newmap.get(opp.id).Current_Year_Rep__c );
  system.debug('id:'+id);
  }
for (HR__c empnum: [select Employee_Number__c from HR__c where  id  in :id ]){
    empid.add(empnum.Employee_Number__c);
      }
      
    system.debug('id:'+id);
    system.debug('empid:'+empid);
 
 for (Contact con: [select Employee_Id__c,Reports_To_Employee_Id__c from contact where Employee_Id__c in:empid]){
    mngid.add(con.Reports_To_Employee_Id__c );
    }
    system.debug('mngid:'+mngid);
    
 for (HR__c empnu: [select Employee_Number__c,Name from HR__c where Employee_Number__c in: mngid]){

      for (Opp__c opp:trigger.new){
     opp.Cureent_Year_Rep_Manager__c=empnu.id; 
     system.debug('emp:'+ empnu.id );
     system.debug('emp:'+ empnu.Name );

     OppyLocation.add(opp);
     
      
         }
             }

  
  
      
      
}