+ Start a Discussion
sfdc@isha.ax1814sfdc@isha.ax1814 

Testclass Issue

test class:

/**********************************************************************************************
@author         Satmetrix
@date           20 Jan,2012
@description:   Test Class for SMXProcessCaseFaasATIBatch

Revision(s):
ToDo(s):        Usage of Asserts for functional coverage

VR,    
**********************************************************************************************/
@isTest
public class SMXProcessCaseFaasATIBatchTest {
    public static testMethod void testBatch() {
        //Create Test Account
        Map<String, Object>  accMap = new Map<String, Object> {
        };
        List<Account> lstAcc = (List<Account>) ShGl_TestFactory.createSObjectList(new Account(),3,accMap);
        insert lstAcc;
        //Create test contact and associate to Account
        Map<String, Object>  conMap = new Map<String, Object> {
        };
        List<Contact> conL = (List<Contact>) ShGl_TestFactory.createSObjectList(new Contact(),3,conMap);
        insert conL;
        for(integer i=0; i<conL.Size(); i++){
            conL[i].AccountId = lstAcc[i].Id;
        }
        Update conL;
        //Create test Case and associate to Contact
        Map<String, Object> caseMap = new Map<String, Object> {
            'RecordTypeId' => Schema.SObjectType.Case.getRecordTypeInfosByName().get('FaaS Compromise Report').getRecordTypeId()
        };
        List<Case> csL = (List<Case>) ShGl_TestFactory.createSObjectList(new Case(),3,caseMap);
        insert csL;
        for(integer i=0; i<conL.Size(); i++){
            csL[i].AccountId = lstAcc[i].Id;
            if(i==0){
                csL[i].Managed_Defense__c = 'CP';
            }else{
                csL[i].Managed_Defense__c = 'CM';
                csL[i].Status = 'Closed';
            }   
        }
        Update csL;
        //Create test for Custom Object(OCM_Agent__c) 
        List<OCM_Agent__c> ssConLst = new List<OCM_Agent__c>();
        for(integer i=0; i<conL.Size(); i++){
            OCM_Agent__c sscon = new OCM_Agent__c(Contact__c = conL[i].Id, CM_Threat_Contact__c = 'Primary');
            ssConLst.add(sscon);    
        }
        insert ssConLst;
        //Create test for Custom Object(Feedback__c)
        List<Feedback__c> fbkLst= new List<Feedback__c>();
        Integer i=2;
        Feedback__c fbk = new Feedback__c(Contact__c = conL[i].Id, Case__c= csL[i].id, Name = 'Test_Name', DataCollectionId__c = 'Test_SurveyId', DataCollectionName__c = 'Test_SurveyName',Status__c='Response Received');
        fbkLst.add(fbk ); 
        insert fbkLst;
        
        
        System.debug('ssConLst'+ssConLst);
        test.startTest(); 
        Database.executeBatch(new SMXProcessCaseFaasATIBatch(),50);
        test.stopTest();
    }
}

Apex class:

  //Determine Survey Name and Survey Id based on Managed Defence
            if(strManagedDefence.equalsignorecase('CP') || strManagedDefence.equalsignorecase('CV') || strManagedDefence.equalsignorecase('MD13')){
                strSurveyName = 'FaaS Compromise Survey';
                strSurveyId = 'FIREEYE_128387';
            }
            /*else if(strManagedDefence.equalsignorecase('ATI+') || strManagedDefence.equalsignorecase('CM')){
                strSurveyName = 'ATI+ Feedback Survey';
                strSurveyId = 'FIREEYE_132678';
            }
            */  
            
            //Retrieve the List of Contacts associated with the Account
            List<ID> lstContactIDs = mapAccountToContactList.get(csRecord.idAccountID);
            if(lstContactIDs!=null){
                for(ID idContact : lstContactIDs ){
                    Map<ID,ID> mapContactToFeedback = mapCaseToContactToFeedback.get(csRecord.idCaseID);
                    //lgSeed = lgSeed++;
                    System.Debug('lgSeed ==> '+lgSeed);
                    System.Debug('idContact==> '+idContact);
                    System.Debug('csRecord.idCaseID==> '+csRecord.idCaseID);
                    if(mapContactToFeedback == null || mapContactToFeedback.isEmpty()){ 
                          //Prepare Survey Record   
                          lgSeed = lgSeed+1;
                          Feedback__c feedback = new Feedback__c();  
                          feedback.Name = 'P_' + lgSeed;
                          feedback.Contact__c = idContact ; //ContactId to which survey have to be sent out
                          feedback.Case__c = csRecord.idCaseID; // CaseId processed
                          feedback.DataCollectionId__c = strSurveyId;
                          feedback.Status__c = 'Nominated';               
                          feedback.DataCollectionName__c = strSurveyName;
                          lstFeedback.add(feedback);
                    }else{
                        ID idFeedback = mapContactToFeedback.get(idContact);
                        if(idFeedback == null){
                            //Prepare Survey Record
                            lgSeed = lgSeed+1;
                            Feedback__c feedback = new Feedback__c();  
                            feedback.Name = 'P_' + lgSeed;
                            feedback.Contact__c = idContact; //ContactId to which survey have to be sent out
                            feedback.Case__c = csRecord.idCaseId; // CaseId processed
                            feedback.DataCollectionId__c = strSurveyId;
                            feedback.Status__c = 'Nominated';               
                            feedback.DataCollectionName__c = strSurveyName;
                            lstFeedback.add(feedback);  
                        }
                    }
                } // End of loop processing through list of valid contacts           
            }  
        } //End of loop processing through list of valid cases 
        insert lstFeedback; //

Error:

System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [DataCollectionId__c, DataCollectionName__c]: [DataCollectionId__c, DataCollectionName__c]

I already provided the values but still getting errors.

Please fix this error.


Regards,
 Isha
VinayVinay (Salesforce Developers) 
Hi Isha,

Can you check FLS for the above fields?

Also, check the data type of the above fields and insert data accordingly.

Thanks,
Vinay Kumar