• Sampada ambikar 9
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies
Hi I also have below method in my case trigger handler.In test class I am trying to cover this.But everytime the newcase owner and old case owner is same.So it is not coeverd.What mistake I am making.



------------------------------*Apex Class---------
 if(objOldCase.OwnerId!=null)
            {
                if((Id)OwnerId != objOldCase.OwnerId){
                    System.debug('Sampada inside main condition__17');
                    System.debug('Sampada inside main condition OwnerId__18' +(Id)OwnerId);
                    System.debug('Sampada inside main condition objOldCase.OwnerId__19' +objOldCase.OwnerId);
                    System.debug('Sampada inside main condition isWholesaler' +isWholesaler);
                        
                    if(isMGR == true || isSRMGR == true){
                        if(strQueueFlag == 'NOQueue'){
                            System.debug('Sampada Manager Inside NOQueue__20');
                            System.debug('Sampada Manager strQueueFlag__21' + strQueueFlag);
                            caseRec.addError('Logged in user ' + UserInfo.getName() + ' does not belong to any queue');
                        }
                    }
                    
                    else if(oldOwnerId.startsWith('005')){
                        System.debug('oldOwnerId' +oldOwnerId);
                        if (objOldCase.OwnerId == UserInfo.getUserId()){
                            System.debug('Sampada inside condition to chk is user is owner__22' );
                            System.debug('Sampada inside condition to chk is user is owner objOldCase.OwnerId__23' +objOldCase.OwnerId);
                            System.debug('Sampada inside condition to chk is user is owner UserInfo.getUserId()__24' +UserInfo.getUserId());
                            if(strQueueFlag == 'NONPQ'){
                                System.debug('Sampada Inside NONPQ' +strQueueFlag);
                                // System.debug('Sampada objOldCase.ownerID' + objOldCase.ownerID );
                                if(caseRec.OwnerId == NULL || OwnerId.startsWith('005') || (OwnerId != idNONPQ && OwnerId != idPQ && OwnerId != idSME)){
                                    caseRec.addError('Core user can assign case only to PQ or NONPQ Queue');
                                }
                            }            
                            else if(strQueueFlag == 'PQ'){
                                System.debug('Sampada Inside PQ__25' +strQueueFlag);
                                
                                if (caseRec.OwnerId == NULL 
                                    || (OwnerId.startsWith('005') && !setUserIDsPQ.contains(caseRec.OwnerId) && !setUserIDsSME.contains(caseRec.OwnerId)) 
                                    || (OwnerId.startsWith('00G') && OwnerId != idNONPQ && OwnerId != idPQ && OwnerId != idSME )){
                                        caseRec.addError('PQ user can assign case only to PQ User or PQ or NONPQ Queue');
                                    }   
                                
                            }
                            else if(strQueueFlag == 'Wholesaler'){
                                System.debug('Sampada Inside PQ__26' +strQueueFlag);
                                
                                if (caseRec.OwnerId == NULL 
                                    || (OwnerId.startsWith('005') && !setUserIDsWholesaler.contains(caseRec.OwnerId)) 
                                    || (OwnerId.startsWith('00G') && OwnerId != idWholesaler)){
                                        caseRec.addError('Wholesaler can assign case only to wholesaler or wholesaler queue');
                                    }   
                                
                            }
                            else if(strQueueFlag == 'NOQueue'){
                                System.debug('Sampada Inside NOQueue__26');
                                System.debug('Sampada strQueueFlag__27' + strQueueFlag);
                                
                                caseRec.addError('Logged in user ' + UserInfo.getName() + ' does not belong to any queue');
                            }            
                        }    
                        else {
                            caseRec.addError('You are not an owner of the case or case is In Progress');    
                        }  
                    }
                    else if(oldOwnerId.startsWith('00G')){
                        if(strQueueFlag == 'NONPQ'){
                            System.debug('Sampada Inside NONPQ__28');
                            System.debug('Sampada inside condition to chk is QUEUE is owner__29' );
                            System.debug('Sampada inside condition to chk is QUEUE is owner objOldCase.OwnerId__30' +objOldCase.OwnerId);
                            System.debug('Sampada inside condition to chk is QUEUE is owner UserInfo.getUserId()__31' +UserInfo.getUserId());
                            // System.debug('Sampada objOldCase.ownerID' + objOldCase.ownerID );
                            if(caseRec.OwnerId == NULL || OwnerId.startsWith('00G')
                               || (OwnerId.startsWith('005') && (!setUserIDsNONPQ.contains(userId) || (Id)OwnerId != userId || (Id)oldOwnerId != idNONPQ))){
                                   caseRec.addError('Core user can assign case only to PQ or NONPQ Queue.Also Queue to Queue case assignment is not allowed');
                               }
                        }            
                        else if(strQueueFlag == 'PQ'){
                            System.debug('Sampada Inside PQ__32');
                            if (caseRec.OwnerId == NULL || OwnerId.startsWith('00G')
                                || (OwnerId.startsWith('005') && (!setUserIDsPQ.contains(userId) || (Id)OwnerId != userId || (Id)oldOwnerId != idPQ))){
                                    caseRec.addError('PQ user can assign case only to PQ User or PQ or NONPQ Queue.Also Queue to Queue case assignment is not allowed');
                                }   
                            
                        }
                        else if(strQueueFlag == 'Wholesaler'){
                            System.debug('Sampada Inside PQ__33');
                            if (caseRec.OwnerId == NULL || OwnerId.startsWith('00G')
                                || (OwnerId.startsWith('005') && (!setUserIDsWholesaler.contains(userId) || (Id)OwnerId != userId || (Id)oldOwnerId != idWholesaler))){
                                    caseRec.addError('Wholesaler User can assign case only to wholesaler User or Wholesaler queue');
                                }   
                            
                        }
                        else if(strQueueFlag == 'NOQueue'){
                            caseRec.addError('Logged in user ' + UserInfo.getName() + ' does not belong to any queue');
                        }
                    }
                }
            }
        }
        
        
        
    }

---Test Class method----
static void ChangeOwner_NONPQ() 
    {
        //Create User U1
         User nonPQusr  = B2C_TestDataFactory.CreateUserNONPQ('CSM-User','CSM-User');
         Insert nonPQusr;
        system.debug('SAMPADA_case nonPQusr' +nonPQusr);
        
        //Insert U1 User in the NONPQ Queue
        Group gNONPQ = [select Id from Group where Name='ABI_B2C_NONPQ' AND Type = 'Queue'];
        GroupMember member = new GroupMember();
        member.UserOrGroupId = nonPQusr.Id;
        member.GroupId = gNONPQ.Id;
        insert member;  
        
        //Create User U3
       User abiAgent123 = B2C_TestDataFactory.CreateUserAgent('CSM-User','CSM');
        Insert abiAgent123;
        
      try{  
          Test.startTest();
        System.runAs(nonPQusr){
            List<Case> Cases = B2C_TestDataFactory.createCaseswithName(1);
            system.debug('SAMPADA_case nonPQusr Case' +Cases[0]);
            List<Case> caseList=new List<Case>();
            Id caseRecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('NON-PQ Complaints').getRecordTypeId();
            integer intRec=1;
            for (Case caseRec:Cases) {
                        system.debug('SAMPADA_caseRec' +caseRec.Id);
                        caseRec.RecordTypeId=caseRecordTypeId;
                        intRec ++;
                        caseList.add(caseRec);
                        system.debug('SAMPADA_caseRec' +caseRec.OwnerId); 
            }
            insert caseList;
            system.debug('SAMPADA_caseList' +caseList[0].OwnerId);
            
            //List<Case> updcase = [select Id from Case where Id = : caseList[0].Id];
            List<Case> updcase = B2C_TestDataFactory.createCaseswithName(1);
            List<Case> updcaseList=new List<Case>();
            system.debug('SAMPADA_updcase' +updcase[0].OwnerId);
            
            MAP<ID, Case> mapOldCases=new MAP<ID, Case>();
            for (Case caseRecUpd:updcase) {
                     caseRecUpd.RecordTypeId=caseRecordTypeId;
                    caseRecUpd.OwnerId = abiAgent123.Id;
                    mapOldCases.put(caseRecUpd.Id, caseRecUpd);
                    system.debug('caseRecUpd.OwnerId' +caseRecUpd.OwnerId);
                    updcaseList.add(caseRecUpd);
            }
            system.debug('SAMPADA_updcaseList' +updcaseList);
            insert updcaseList;                       
            ABI_Case_TriggerHandler.B2CChangeOwner(caseList,mapOldCases);
        }
            Test.stopTest();
        }catch(Exception e) {
        //    System.Assert(e.getMessage().contains('Core user can assign case only to PQ or NONPQ Queue'));

}
        }
Hi Everyone,

I am using bekow class to calculate business days.but when I am calling the method from anonymous window getting below error.Please let me know what mistake i m making.Thanks in advance.I am new to sfdc.

Calling from anonymous -- B2C_BusinessDays_Calculator.IsWeekendDay(11-16-2018);

Error
Line: 1, Column: 29
Method does not exist or incorrect signature: void IsWeekendDay(Integer) from the type B2C_BusinessDays_Calculator



public class B2C_BusinessDays_Calculator {

    List<Case> cases = [select Id,B2C_Pending_SME_Dt__c from Case where status in ('Pending SME','Pending Customer')];
    Id caseId = cases[0].Id;
    Date SMEDate = cases[0].B2C_Pending_SME_Dt__c;
    
    public static Boolean IsWeekendDay(Date SMEDate)
   {
      boolean result     = false;
      system.debug('SMEDate = '+SMEDate); 
      //Recover the day of the week
      Date startOfWeek   = SMEDate.toStartOfWeek();
      system.debug('startOfWeek = '+startOfWeek);
      Integer dayOfWeek  = SMEDate.day() - startOfWeek.day();
      system.debug('dayOfWeek = '+dayOfWeek);   
      result = dayOfWeek == 0 || dayOfWeek == 6 ? true : false;
      system.debug('result = '+result); 
      return result;
   } 
   
   
   public static Date AddBusinessDays(Date SMEDate, integer BusinessDaysToAdd )
   {
      //Add or decrease in BusinessDaysToAdd days 
      Date finalDate = SMEDate;
      system.debug('finaldate = '+finalDate);
      integer direction = BusinessDaysToAdd < 0 ? -1 : 1;
      system.debug('direction = '+direction);
       while(BusinessDaysToAdd != 0)
       {
           finalDate = finalDate.AddDays(direction);
           system.debug('BusinessDaysToAdd = '+BusinessDaysToAdd);            
           system.debug('finaldate = '+finalDate);
           if (!isWeekendDay(finalDate))
           {
               BusinessDaysToAdd -= direction;
               
           }
       }

       return finalDate;
   }
}

 
Hi,
I am adding formula under custom field(Which needs to populate record Modified date).I am putting below formula
IF(LastModifiedDate <> CreatedDate ,
   IF( NOW() > LastModifiedDate+ 1/(24*60), LastModifiedDate, null ), null 
)
But getting Error:Field LastModifiedDate may not be used in this type of formula.I m new to salesforce...please help to resolve this issue
 
Hi Everyone,

I am using bekow class to calculate business days.but when I am calling the method from anonymous window getting below error.Please let me know what mistake i m making.Thanks in advance.I am new to sfdc.

Calling from anonymous -- B2C_BusinessDays_Calculator.IsWeekendDay(11-16-2018);

Error
Line: 1, Column: 29
Method does not exist or incorrect signature: void IsWeekendDay(Integer) from the type B2C_BusinessDays_Calculator



public class B2C_BusinessDays_Calculator {

    List<Case> cases = [select Id,B2C_Pending_SME_Dt__c from Case where status in ('Pending SME','Pending Customer')];
    Id caseId = cases[0].Id;
    Date SMEDate = cases[0].B2C_Pending_SME_Dt__c;
    
    public static Boolean IsWeekendDay(Date SMEDate)
   {
      boolean result     = false;
      system.debug('SMEDate = '+SMEDate); 
      //Recover the day of the week
      Date startOfWeek   = SMEDate.toStartOfWeek();
      system.debug('startOfWeek = '+startOfWeek);
      Integer dayOfWeek  = SMEDate.day() - startOfWeek.day();
      system.debug('dayOfWeek = '+dayOfWeek);   
      result = dayOfWeek == 0 || dayOfWeek == 6 ? true : false;
      system.debug('result = '+result); 
      return result;
   } 
   
   
   public static Date AddBusinessDays(Date SMEDate, integer BusinessDaysToAdd )
   {
      //Add or decrease in BusinessDaysToAdd days 
      Date finalDate = SMEDate;
      system.debug('finaldate = '+finalDate);
      integer direction = BusinessDaysToAdd < 0 ? -1 : 1;
      system.debug('direction = '+direction);
       while(BusinessDaysToAdd != 0)
       {
           finalDate = finalDate.AddDays(direction);
           system.debug('BusinessDaysToAdd = '+BusinessDaysToAdd);            
           system.debug('finaldate = '+finalDate);
           if (!isWeekendDay(finalDate))
           {
               BusinessDaysToAdd -= direction;
               
           }
       }

       return finalDate;
   }
}