function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sushmaiyer2@gmail.comsushmaiyer2@gmail.com 

Records Not Getting Saved

Hi All,

 

I am creating a Survey Force App from App Exchange but i dont hav much hands on in VF and Apex.

 

I have a requirement to pass a Survey link to Users and their responses should get saved when they click the Submit Button.

The issue i am facing is when they click the Submit button,their responses do not get saved.

Please help...!

 

Also within the Application i am able to save the prob is outside the App,when i share it with others.

 

Below is the Link for my Survey :-

 

http://lntinfotechlimited-developer-edition.ap1.force.com/lnt1

 

Part of My Extension for the TakeSurvey VF Page with submitResults(); :-

 

//TestViewSurveyController
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 (question 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
}

//Submit Results
public void submitResults()
{
List <SurveyQuestionResponse__c> sqrList = new List<SurveyQuestionResponse__c>();
for (question q : allQuestions)
{
SurveyQuestionResponse__c sqr = new SurveyQuestionResponse__c();
if (q.renderSelectRadio == 'true')
{
if (q.required && (q.selectedOption == null || q.selectedOption == ''))
{
Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please fill out all required fields'));
return;
}
if (q.selectedOption == null || q.selectedOption == '')
{
sqr.Response__c = '';
}
else
{
sqr.Response__c = q.singleOptions.get(Integer.valueOf(q.selectedOption)).getLabel();
}
sqr.Survey_Question__c = q.Id;
sqrList.add(sqr);
}
else if (q.renderFreeText == 'true')
{
if (q.required && q.choices == '')
{
Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please fill out all required fields'));
return;
}
System.debug('*****Select Radio ' + q.choices);

sqr.Response__c = q.choices;
sqr.Survey_Question__c = q.Id;
sqrList.add(sqr);
}
else if (q.renderSelectCheckboxes == 'true')
{
if (q.required && (q.selectedOptions == null || q.selectedOptions.size() == 0))
{
Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please fill out all required fields'));
return;
}
for (String opt : q.selectedOptions)
{
sqr = new SurveyQuestionResponse__c();
if (opt == '' || opt == null)
{
sqr.Response__c = '';
}
else
{
sqr.Response__c = q.multiOptions.get(Integer.valueOf(opt)).getLabel();
}
sqr.Survey_Question__c = q.Id;
sqrList.add(sqr);
}
}
else if (q.renderSelectRow == 'true')
{
if (q.required && (q.selectedOption == null || q.selectedOption == ''))
{
Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please fill out all required fields'));
return;
}
if (q.selectedOption == null || q.selectedOption == '')
{
sqr.Response__c = '';
}
else
{
sqr.Response__c = q.rowOptions.get(Integer.valueOf(q.selectedOption)).getLabel();
}
sqr.Survey_Question__c = q.Id;
sqrList.add(sqr);
}
}
if(AddSurveyTaker())
{
for (SurveyQuestionResponse__c sqr : sqrList)
{
sqr.SurveyTaker__c = surveyTakerId;
}
insert sqrList;
thankYouRendered=true;
}
}