• Manohar Yenugula
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
Geeting error at winter 19 Platfrom Developer 1 maintenance Certification:

Challenge not yet complete in My Trailhead Playground 1
Ensure sharing rules from the calling class are enforced for the the 'UtilityClass' Apex class.

Can you please help?
Hi All,
i have a batch given below:-
public class BatchZendeskToSalesforceCases implements Database.Batchable<String>,Database.AllowsCallouts, Database.Stateful {
    public Iterable<String> start(Database.BatchableContext BC){
        List<Case> caseList = new List<Case>();
        List<String> endPoints = new List<String>();
        ZendeskApis.CaseJSON2Apex firstRecords =  ZendeskApis.ZendeskCasesApi();
        caseList.addAll(insertCaseData(firstRecords));
        if(caseList.size() >0){
          Database.insert(caseList, false);
        }
        
        Integer totalRecords = firstRecords.count;
        if(totalRecords > 100 && 
           firstRecords.next_page != null && 
           firstRecords.next_page != ''){
               totalRecords = totalRecords / 100;
               for(Integer i= 2; i< totalRecords+2; i++){
                   String currentEndPoints = firstRecords.next_page;
                   currentEndPoints = currentEndPoints.substringBefore('?');
                   currentEndPoints = currentEndPoints + '?page='+i;
                   endPoints.add(currentEndPoints);
               }
           }
        return endPoints;
        
    }
    public void execute( Database.BatchableContext BC, List<String> endPoints){
        List<Case> caseList = new List<Case>();
        ZendeskApis.CaseJSON2Apex ajNextRecords =  ZendeskApis.ZendeskCasesNextApi(endPoints[0]);
        caseList.addAll(insertCaseData(ajNextRecords));
        if(caseList.size() > 0){
            Database.insert(caseList, false);
        }    
        
    }
    
    public void finish(Database.BatchableContext BC){
         Map<Double, Id> mapzendeskIdToAccountId = new Map<Double, Id>();
       List<Case> caseListToUpdate = new List<Case>();
       for(Account acc : [Select id, Zendesk_Id__c 
                          from account 
                          where Zendesk_Id__c != null]){
           mapzendeskIdToAccountId.put(Double.valueOf(acc.Zendesk_Id__c), acc.Id);                      
       }
        if(mapzendeskIdToAccountId.size() > 0){
            for(Case caseObj : [Select id, Zd_organization_id__c, 
                               accountId 
                               from Case
                               where Zd_organization_id__c IN: mapzendeskIdToAccountId.keySet()]){
                if(mapzendeskIdToAccountId.containsKey(caseObj.Zd_organization_id__c) ){
                    caseObj.AccountId = mapzendeskIdToAccountId.get(caseObj.Zd_organization_id__c);
                    caseListToUpdate.add(caseObj);                       
                }
               
            }
        }
        Database.update(caseListToUpdate, false); 
    }  
    
    public static List<Case> insertCaseData(ZendeskApis.CaseJSON2Apex caseData){
        List<Case> caseList = new List<Case>();
        for(ZendeskApis.CaseTickets caseWrapData :  caseData.tickets){
            Case caseObj = new Case();
            caseObj.Zd_url__c = caseWrapData.url;
            if(caseWrapData.id != null){
                caseObj.Zd_Zendesk_Id__c = String.valueOf(caseWrapData.id); 
            }
            if(caseWrapData.external_id != null){
                caseObj.Zd_external_id__c = String.valueOf(caseWrapData.external_id); 
            }
            //caseObj.Zd_via_followup_source_id__c = caseWrapData.via; 
            if(caseWrapData.created_at != null){
                caseObj.Zd_Created_at__c = Date.valueOf(caseWrapData.created_at); 
            }
            if(caseWrapData.updated_at != null){
                caseObj.Zd_Updated_at__c = Date.valueOf(caseWrapData.updated_at); 
            }
            if(caseWrapData.type_Z != null){
                caseObj.Type = String.valueOf(caseWrapData.type_Z); // in json: type
            }
            if(caseWrapData.subject != null){
                caseObj.Subject = caseWrapData.subject; 
            }
            if(caseWrapData.raw_subject != null){
                caseObj.Zd_raw_subject__c = caseWrapData.raw_subject; 
            } 
            if(caseWrapData.description != null){
                caseObj.Description = caseWrapData.description; 
            }
            if(caseWrapData.priority != null){
                caseObj.Priority = caseWrapData.priority; 
            }
            if(caseWrapData.status != null){
                caseObj.Status = caseWrapData.status; 
            }
            if(caseWrapData.recipient != null){
                caseObj.Zd_recipient__c = String.valueOf(caseWrapData.recipient); 
            }
            if(caseWrapData.requester_id != null){
                caseObj.Zd_requester_id__c = caseWrapData.requester_id; 
            }
            if(caseWrapData.submitter_id != null){
                caseObj.Zd_submitter_id__c = caseWrapData.submitter_id; 
            }
            if(caseWrapData.assignee_id != null){
                caseObj.assignee_id__c = caseWrapData.assignee_id; 
            }
            if(caseWrapData.organization_id != null){
                caseObj.Zd_organization_id__c = caseWrapData.organization_id; 
            }
            if(caseWrapData.group_id != null){
                caseObj.Zd_group_id__c = caseWrapData.group_id; 
            }
            if(caseWrapData.collaborator_ids != null){
                caseObj.Zd_collaborator_ids__c = String.valueOf(caseWrapData.collaborator_ids); 
            }
            if(caseWrapData.follower_ids != null){
                caseObj.Zd_follower_ids__c = String.valueOf(caseWrapData.follower_ids); 
            }
            if(caseWrapData.email_cc_ids != null){
                caseObj.Zd_email_cc_ids__c = String.valueOf(caseWrapData.email_cc_ids); 
            }
            if(caseWrapData.forum_topic_id!= null){
                caseObj.Zd_forum_topic_id__c = caseWrapData.forum_topic_id; 
            }
            if(caseWrapData.problem_id != null){
                caseObj.Zd_problem_id__c = caseWrapData.problem_id; 
            }
            if(caseWrapData.has_incidents != null){
                caseObj.Zd_has_incidents__c = caseWrapData.has_incidents; 
            }
            if(caseWrapData.is_public != null){
                caseObj.Zd_is_public__c = caseWrapData.is_public; 
            }
            if(caseWrapData.due_at != null){
                caseObj.Zd_due_at__c = Date.valueOf(caseWrapData.due_at); 
            }
            if(caseWrapData.tags != null){
                caseObj.Zd_tags__c = String.valueOf(caseWrapData.tags); 
            }
            if(caseWrapData.custom_fields!= null){
                caseObj.Zd_CustomFields__c = String.valueOf(caseWrapData.custom_fields); 
            }
            if(caseWrapData.satisfaction_rating != null){
                caseObj.Zd_Satisfaction_Rating__c = String.valueOf(caseWrapData.satisfaction_rating); 
            }
            if(caseWrapData.sharing_agreement_ids != null){
                caseObj.Zd_sharing_agreement_ids__c = String.valueOf(caseWrapData.sharing_agreement_ids);
            }
            if(caseWrapData.fields != null){
                caseObj.Zd_Fields__c = String.valueOf(caseWrapData.fields); 
            }
            if(caseWrapData.followup_ids != null){
                caseObj.Zd_followup_ids__c = String.valueOf(caseWrapData.followup_ids); 
            }
            if(caseWrapData.brand_id != null){
                caseObj.Zd_brand_id__c = caseWrapData.brand_id; 
            }
            if( caseWrapData.allow_channelback != null){
                caseObj.Zd_allow_channelback__c = caseWrapData.allow_channelback; 
            }
            if(caseWrapData.allow_attachments != null){
                caseObj.Zd_allow_attachments__c = caseWrapData.allow_attachments;
            }
            caseList.add(caseObj);
            
        }
        return caseList;
    }
    
}
 test class is given below:-
@isTest
private class BatchZendeskToSalesforceCasesTest {
    Static testmethod void ZendeskCasesTest(){
        Test.setMock(HttpCalloutMock.class, new BatchZendeskToSalesforceCasesMock());
         
         List<Case> lstCase = new List<Case>();
        for(integer i=0; i<5; i++)
        {
            Case caseObj = new Case(Subject='Test', Status = 'New');
            lstCase.add(caseObj);
        }
        insert lstCase;
        test.startTest();
        BatchZendeskToSalesforceCases obj = new BatchZendeskToSalesforceCases();
        database.executeBatch(obj);
        test.stopTest();
        
    }
}
User-added imageHow to cover this?