• charlie west 5
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 0
    Replies
Hello, I am trying to share Cases between Accounts through a Junction Object called Permission_Access__c. On the object, I select the Account that is to be shared, the Account that is receiving the share, and select a check box to "Share Files". Once this is done, the user then can go to the Community Page for Cases, and see the shared Accounts on the page.
 
public with sharing class PermissionAccessHandler {
  public static void getPermAccessList(List<Permission_Access__c> triggerNew)
    {
   		List<Permission_Access__Share> permissionAccessList = new List<Permission_Access__Share>();
        List<CaseShare> caseShareList = new List<CaseShare>();
        
        if(Trigger.isAfter)
        {
			for(Permission_Access__c currRec : [SELECT Id, Account_That_Is_Sharing__c, Account_That_is_receiving__c from Permission_access__c Where Share_Cases__c = TRUE])
            {
                Permission_Access__Share pAShare = new Permission_Access__Share();
                pAShare.ParentId = currRec.Account_That_Is_Sharing__c;
                pAShare.UserOrGroupId = currRec.Account_That_Is_Receiving__c;
                pAShare.AccessLevel = 'Edit';
                pAShare.RowCause = Schema.CaseShare.RowCause.Manual;
                PermissionAccessList.add(pAShare);
            }
            
            Database.SaveResult[] lsr = Database.insert(PermissionAccessList, false);
I am using a handler + test classes which grant code coverage. However, the Cases are not showing up in the community. I see on AccountShare and CaseShare objects that there is the ability to grance AccessLevel, but I am told not to user Standard Objects for this kind of feature. What am I missing here? Thanks :D
 
Hello, I am trying to get code coverage for a trigger, but am having trouble writing unit tests. The purpose of the trigger is to throw an error when a user tries to close a Case with outstanding Tasks associated with the record. Here is the trigger
public class OpenTaskHandler {
    
    public static void getCaseList(List<Case> triggerNew, Map<id, Case> newMap){
    	Set<Case> newlyClosedCaseIds = new Set<Case>();
        
    	for (Case caseId : newlyClosedCaseIds)
    	{
        	if (caseId.IsClosed)
        		{
                	newlyClosedCaseIds.add(caseId);
            	}
    	}
    
    	for (AggregateResult aggResult : [ 
        	SELECT Count(Id), WhatId From Task WHERE WhatId In :newlyClosedCaseIds AND isClosed = false
        	Group by WhatId
        	having Count(Id) > 0
    	]) {
        	Case openCase = (Case) aggResult.get('WhatId');
        	Case errorCase = newMap.get(openCase.Id);
        
        	errorCase.addError('Cannot close case since there are non closed tasks: ' + errorCase.Id);
    	}
}
Here is one of my tests:
@isTest public class CaseTaskTriggers {
    @isTest public static void TestOpenTasks() {
        
       Case testCase = new Case();
        testCase.Status='New';
        insert testCase;
        
       Task tsk = new Task();
        tsk.Subject = 'New hire has been added';
        tsk.WhatId = [select Id from Case Limit 1].Id;
        tsk.OwnerId = UserInfo.getUserId();
        tsk.Status = 'New';
        insert tsk; 
        
        Test.startTest();
        
        try{
            testCase.Status = 'closed';
            update testCase;
        }
        Catch(Exception ee){}
        
        system.assertNotEquals(tsk.Status = 'Closed', tsk.Status = 'New', 'Cannot close case since there are non closed tasks');
        
        test.stopTest();
    }
I am getting red code coverage on the if (caseId.IsClosed) {newlyClosedCaseIds.add(caseId), the Case openCase = (Case) aggResult.get('whatid') and the errorCase.addError. How do I account for these on a unit test? I am fairly new to unit testing and would love any tips/feedback. Thanks !