• more marta
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
if(requestId != null) {
        
               List<GLOBAL_Request__c> requestObj = [select id, business_unit__c, recordtype.developername from GLOBAL_Request__c where id=:requestId AND recordtype.developername = 'Send_Survey' Limit 1];
            if (requestObj != null && !requestObj.isEmpty()){        
            List<User> usrRec =[select id, NT_Login_Name__c from User where id=:UserInfo.getUserId() And NT_Login_Name__c != null Limit 1];
                    if(usrRec != null && !usrRec.isEmpty()){
                    List<Contact> contactRec = [select id, NT_Login_Name__c from contact where NT_Login_Name__c=:usrRec[0].NT_Login_Name__c ORDER by LastModifiedDate DESC Limit 1];         
                        if (contactRec != null && !contactRec.isEmpty()){
                          List<Participant__c> participantRec = [select Id, Name,Survey_Taken_Date__c from Participant__c where Participant__c=:contactRec[0].Id AND Request__c=:requestObj[0].Id ORDER by CreatedDate DESC LIMIT 1];
                            if(participantRec != null && !participantRec.isEmpty()){
                                if(participantRec[0].Survey_Taken_Date__c == null)
                                { 
                                ParticipantId = participantRec[0].Id;
                                contactId = contactRec[0].Id;
                                requestId = requestObj[0].Id;
                                Participant__c updateSurveyTakenDate = new Participant__c(id = ParticipantId, Survey_Taken_Date__c = System.now());            
                                       upsert updateSurveyTakenDate;  
                                }
                             else{
                              
                            if(caseId==null){
                                caseId = 'none'; 
                            }   
                            if(contactId==null)
                                contactId =   'none';
                            if(requestId==null) 
                                requestId =   'none';   
                            
                            if(ParticipantId==null){            
                                ParticipantId ='none';
                            }

                           Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, System.Label.LABS_SF_You_have_already_taken_this_survey));
                                return false;
                            }
                            } else {
                            if(caseId==null){
                                caseId = 'none'; 
                            }   
                            if(contactId==null)
                                contactId =   'none';
                            if(requestId==null) 
                                requestId =   'none';   
                            
                            if(ParticipantId==null){            
                                ParticipantId ='none';
                            }
                                Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, System.Label.LABS_SF_Participant_Not_Part_Of_This_Pool));                    
                                 return false;
                            }
                        }
                    }
            }
        }
          
Below is the existing test class
==
@istest
private class ViewSurveyController_Test{
    //------------------------------------------------------------------------------//
    //------------------------------------------------------------------------------//
    private static Testmethod void testViewSurveyController() {
        SurveyTestingUtil tu = new SurveyTestingUtil();
        Apexpages.currentPage().getParameters().put('id',tu.surveyId);
        Apexpages.Standardcontroller stc;
        ViewSurveyController vsc = new ViewSurveyController(stc); 
        vsc.init();
        System.assert(vsc.allQuestionsSize == 4);
        System.assert(tu.surveyId != null);


        vsc.submitResults();
        for (SFQuestion q : vsc.allQuestions)
        {
            q.selectedOption = String.valueof(2);
            q.choices = String.valueof(2);
            q.selectedOptions = new List<String>();
            q.selectedOptions.add(String.valueof(2));
            vsc.submitResults();
        }
        System.assertEquals(true, vsc.thankYouRendered);


        //test something
    }


    private static Testmethod void testUpdateSurveyName() {
        SurveyTestingUtil tu = new SurveyTestingUtil();
        Apexpages.currentPage().getParameters().put('id',tu.surveyId);
        Apexpages.Standardcontroller stc;
        ViewSurveyController vsc = new ViewSurveyController(stc);
        vsc.surveyName = 'new name';
        system.assert(vsc.updateSurveyName() == null);

    }


    private static Testmethod void testupdateSurveyThankYouAndLink() {
        SurveyTestingUtil tu = new SurveyTestingUtil();
        Apexpages.currentPage().getParameters().put('id',tu.surveyId);
        Apexpages.Standardcontroller stc;
        ViewSurveyController vsc = new ViewSurveyController(stc);
        vsc.surveyThankYouText = 'new stuff';
        vsc.surveyThankYouURL = 'more new stff';
        system.assert(vsc.updateSurveyThankYouAndLink()==null);
    }

    
    private static Testmethod void testrefreshQuestionList() {
        SurveyTestingUtil tu = new SurveyTestingUtil();
        Apexpages.currentPage().getParameters().put('id',tu.surveyId);
        Apexpages.Standardcontroller stc;
        ViewSurveyController vsc = new ViewSurveyController(stc);
        system.assert(vsc.refreshQuestionList() == null);
    }

}

how should I go about updating it to get at least 75% coverage ?

Thanks,
TM


 
I see Lightning inputField for Lookup does not support any custom object. Like if Case is haveing a lookup to Project and refer that field inside "lightning:recordForm" It does not search the Projects automatically and the input Field does not support the onchange function as well. Any thoughts?