0

Thanks David for replying.
I am launching a Survey Child Record from a Student Master Record Page. After saving the Survey Child Record I want to be redirected to Student Master Record Page.

Below is the Code:

Controller:

public with sharing class StudentSurveyCtrlr {       
    public nav1__Survey__c nSurvey {get; set;}      
    public List<SelectOption> ratings {get;set;}
    string cid;       
    public StudentSurveyCtrlr() {
        nSurvey = new nav1__Survey__c ();
        ratings = new list <SelectOption> ();
        ratings.add(new SelectOption('','--None--'));
        ratings.add(new SelectOption('1','1'));
        ratings.add(new SelectOption('2','2'));        
    }

    public pagereference SaveSurvey() {       
        insert nSurvey;
        cid = nSurvey.nav1__StudentID__r.Id;
        system.debug('Parent Record ID' + cid);
        PageReference pg = new PageReference('/'+ 
        nSurvey.nav1__StudentID__r.Id);
        pg.setRedirect(true);
        return pg; 
    }
}

The below Code is the VF Page which will be called by a Custom button on the New Student Master Record Page.

VF Page

                                                                             <apex:page controller="StudentSurveyCtrlr" title="Survey Questionaire" label="Survey Questionaire">
<apex:form >
<apex:pageBlock title="Survey Questionaire"> 
  Question 1. Satisfied  <apex:inputCheckbox value="{!nSurvey.Satisfaction__c}"/>  
  Question 2. Rating       
      <apex:selectList size="1" value="{!nSurvey.Rating__c}">
      <apex:selectOptions value="{!ratings }"/>
    </apex:selectList> <br/>    
  Question 3. Comments  <apex:inputTextarea value="{!nSurvey.Comments__c}"/>
<apex:commandButton value="Save Survey" action="{!SaveSurvey}"/>
</apex:pageBlock>
</apex:form>
</apex:page>

On the press of the custom button, I will be redirected to VF page which will have Survey Questions and Save button. After I press Save button on the VF page, I want to be redirected to the New Student Master Record Page.

I am seeing that the Survey child record is being saved but I am not redirected to New Student Master Record page. Can you please guide me on this?

  • You added new code, but I am not sure why. Are you indicating that you have a different issue, or that the answer below did not hit the mark? Can you help clarify what support you need? – David Reed Dec 21 '18 at 16:19
1

Based on the code you're showing here, that System.debug() statement should be demonstrating that nSurvey.nav1__StudentID__r.Id is null. As a result, your redirect goes nowhere and the page simply reloads.

If you are populating that lookup field somewhere else in your code, refer to it directly as nSurvey.nav1__StudentID__c. It's unlikely that nav1__StudentID__r is a non-null sObject here.

  • @NaveenMittapalli, if the answer worked for you, then please go ahead and accept this (you will find a tick mark besides the answer to accept it), so that this is marked as resolved and helps anyone facing similar issue. – Jayant Das Dec 20 '18 at 17:03
0

nSurvey.nav1__StudentID__r.Id will be null as it is a related field and those fields will be available only when you explicitly query on those fields. And as the value would be null, your page would not redirect.

Replace the below code

PageReference pg = new PageReference('/'+ nSurvey.nav1__StudentID__r.Id);  

With

PageReference pg = new PageReference('/'+ nSurvey.nav1__StudentID__c);  

as the value of the lookup field will still be an Id which you might be populating somewhere in your code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.