Skip to main content
I have an aura component used in a screenflow that takes user created records of questions, and child records of picklist options.  it asks the questions on the screenflow but one functionality that i have not yet been able to build in is the ability to make some picklist options dependent. 

i have related the questions to eachother for dependency, and on the picklist option record added what parent values they should appear on, but how do i make a aura component in screenflow respond and to the prior inputted value

i have no idea how to get the answer from the prior question in order to alter the available picklist values for the next question, please advise

public without sharing class EventFormLCController {

    

    //Description:

    //Use to Return the Events all questions with there value

    //type.

    //Input : Event Id.

    //Output : EventFormWrapper instance

    @AuraEnabled

    public static List<EventFormWrapper> getEventQuestions(String recordId) {

        try

        {

            String sObjName = Id.valueof(recordId).getSObjectType().getDescribe().getName();

            system.debug('sObjName--'+sObjName);

            List<Id> eventQuestionIds = new List<Id>();

            List<WHEH_Question_Picklist__c> theWrapQuesPickList;

            List<EventFormWrapper> theWrapList = new List<EventFormWrapper>();

            

            List<WHEH_Event_Question__c> theWEventAllQusList = new List <WHEH_Event_Question__c>();

            if(sObjName == 'WHEH_Question_Picklist__c'){

                List <WHEH_Question_Picklist__c> questPicklist = new List <WHEH_Question_Picklist__c>();            

                questPicklist = [select WHEH_Event_Question__r.WHEH_Event__c from  WHEH_Question_Picklist__c where id =: recordId ORDER BY Sort__c ASC];

                recordId = questPicklist[0].WHEH_Event_Question__r.WHEH_Event__c;

            }

            

            theWEventAllQusList = [SELECT Id, Name, WHEH_Type__c, WHEH_Required__c,  WHEH_Note__c,Sort__c, WHEH_Dependent_Event_Question__c FROM WHEH_Event_Question__c WHERE WHEH_Event__c  =: recordId  ORDER BY Sort__c ASC];

            

            List<WHEH_Event_Question__c> thewEventQusNullList=new List<WHEH_Event_Question__c>();

            

            List<WHEH_Event_Question__c> theWEventQusList=new List<WHEH_Event_Question__c>();

            

            for(WHEH_Event_Question__c theWEventQus : theWEventAllQusList) {

                eventQuestionIds.add(theWEventQus.Id);

                

                if(theWEventQus.Sort__c==null) {

                    thewEventQusNullList.add(theWEventQus);

                  }

                else {

                    theWEventQusList.add(theWEventQus);

                }

                

            }

            

            theWEventQusList.addAll(thewEventQusNullList);

            System.debug('theWEventQusList---->'+theWEventQusList);

            

            

            List<WHEH_Question_Picklist__c> theQusPickList = [SELECT Id, WHEH_Event_Question__c, WHEH_Value__c, WHEH_Event_Question__r.WHEH_Dependent_Event_Question__c, WHEH_Dependent_Values__c FROM WHEH_Question_Picklist__c WHERE WHEH_Event_Question__c IN : eventQuestionIds ORDER BY Sort__c ASC];

            System.debug('theQusPickList---->'+theQusPickList);

            

            for(WHEH_Event_Question__c theWEventQus : theWEventQusList) {

                theWrapQuesPickList = new  List<WHEH_Question_Picklist__c>();

                

                for(WHEH_Question_Picklist__c pickListValue : theQusPickList) {

                    if(pickListValue.WHEH_Event_Question__c == theWEventQus.Id)

                        theWrapQuesPickList.add(pickListValue);

                }

                

                //checking that the Question is of what type

                

                if(theWEventQus.WHEH_Type__c=='Picklist') {

                    String defaultPickListValue='';

                    if(theWrapQuesPickList.size()>0) {

                        defaultPickListValue=theWrapQuesPickList[0].WHEH_Value__c;

                    }

                    

                    theWrapList.add(new EventFormWrapper(theWEventQus,theWrapQuesPickList,defaultPickListValue));

                }

                else if(theWEventQus.WHEH_Type__c=='Note') {

                    String defaultValue=theWEventQus.WHEH_Note__c;

                    theWrapList.add(new EventFormWrapper(theWEventQus,theWrapQuesPickList,defaultValue));

                }

                else if(theWEventQus.WHEH_Type__c=='Multi-line Text' || theWEventQus.WHEH_Type__c=='Text') {

                    theWrapList.add(new EventFormWrapper(theWEventQus,theWrapQuesPickList,''));

                }

                else if(theWEventQus.WHEH_Type__c=='Checkbox') {

                    theWrapList.add(new EventFormWrapper(theWEventQus,theWrapQuesPickList,'false'));

                }

                

            }

            System.debug('theWrapList-------->'+theWrapList);

            return theWrapList;

        }

        catch(Exception e) {

            System.debug('Error in::'+e.getLineNumber()+' and Error is:::'+e.getMessage());

            return null;

        }

    }

    

    

    //Description:

    //Use to save the response of the Events all

    //questions and create the resg response for the

    //questions.

    //

    //Input : EventFormWrapper instance.

    //Output : NONE

    @AuraEnabled

    public static List<WHEH_Reg_Response__c> createRegistrationResponseForQuestion(String responseWrapper, String eventId ,String registrationId) {

        try

        {

            

            List<EventFormWrapper> questionWrapperList=(List<EventFormWrapper>) JSON.deserialize(responseWrapper, List<EventFormWrapper>.Class);

            

            //storing the response for all the Event_Questions

            List<WHEH_Reg_Response__c> questionResponseList=new List<WHEH_Reg_Response__c>();

            

            

            for(EventFormWrapper question:questionWrapperList) {

                System.debug('responseWrapper::'+question);

                

                //Creating the response

                WHEH_Reg_Response__c response=new WHEH_Reg_Response__c();

                response.Registration__c=registrationId;

                response.WHEH_Question__c=question.theWEventQuestion.Name;

                response.WHEH_Event_Question__c=question.theWEventQuestion.Id;

                

                if(question.theWEventQuestion.WHEH_Type__c!='Checkbox')

                {

                    String answer=question.theAnswer;

                    if(question.theWEventQuestion.WHEH_Type__c=='Multi-line Text'){

                        response.WHEH_Multi_line_Value__c=answer;

                        response.Question_Value__c=answer;

                    }

                    else if(question.theWEventQuestion.WHEH_Type__c=='Text') {

                        response.Question_Value__c=answer;

                        

                    }

                    else if(question.theWEventQuestion.WHEH_Type__c=='Note') {

                        response.WHEH_Multi_line_Value__c=answer;

                        response.Question_Value__c=answer;

                    }

                    else if(question.theWEventQuestion.WHEH_Type__c=='Picklist') {

                        response.Question_Value__c=answer;

                    }

                     

                }

                else

                {

                    response.Question_Value__c=String.valueOf(question.theAnswerForCheckbox);

                }

                

                questionResponseList.add(response);

            }

            

            System.debug('questionResponseList size::'+questionResponseList.size());

            /*if(questionResponseList.size()>0)

            {

                insert questionResponseList;

            }

            System.debug('questionResponseList insert::'+questionResponseList);*/

            

            return questionResponseList;

        }

        catch(Exception e)

        {

            System.debug('Error in:::'+e.getLineNumber()+' and Error is::'+e.getLineNumber()+' and inside create Reg Reponse');

            return null;

        }

        

    }

    

    //Description:

    //Use to updated the Questions order 

    //when user drag and drop the questions.

    //

    //Input : questionList 

    //Output : Boolean

    @AuraEnabled

    public static boolean updateQuestionOrder(List<WHEH_Event_Question__c> questionList){

        System.debug('****updateQuestionOrder******updateQuestionOrder*********');

        return UpateQuestionOrder_apex.updateQuestionOrder(questionList);

    }

    

    //Description:

    //Wrapper class that use to store the Questions

    //of the event with there following answer.

    

    public class EventFormWrapper {

        @AuraEnabled

        public WHEH_Event_Question__c theWEventQuestion;

        @AuraEnabled

        public List<WHEH_Question_Picklist__c> theQuesPickList; 

        @AuraEnabled 

        public String theAnswer; 

        @AuraEnabled

        public Boolean theAnswerForCheckbox;

        

        public EventFormWrapper(WHEH_Event_Question__c wEventsQues, List<WHEH_Question_Picklist__c> questionPickList,String defaultAnswer) {

            theWEventQuestion = wEventsQues;

            theQuesPickList = questionPickList;

            theAnswer = defaultAnswer;

            theAnswerForCheckbox = false;

        }

        public EventFormWrapper() {

            

        }

    }

    

    

}

1 answer
  1. Sep 1, 2023, 12:45 PM
    Hi, 

    Can narrow down the scenario and explain to me what exactly you want to achieve?

    Thanks
0/9000