0

I have a VF page that allows child records to be updated , this is working well.EXCEPT for the following page I am trying to use ParentId=ApexPages.currentPage().getParameters().get('ParentId'); and Pagereference page=new pagereference('/'+parentId);

I can enter test data in successfully but the follow up page after clicking save throws URL No Longer Exists

This is the VF page

<apex:page controller="AddingChildController" >
    <apex:form >
        <apex:variable var="rowNum" value="{!0}" />
        <apex:pageBlock >
            <apex:variable var="rowNum" value="{!0}" />
            <apex:PageBlockTable value="{!childList}" var="int">
            <apex:facet name="footer">
                <apex:commandLink value="Add" action="{!insertRow}"/>
                </apex:facet>
                <apex:column headerValue="Lead Generator">
                    <apex:inputField value="{!int.Lead_Gen__c}"/>                                      
                </apex:column>

                <apex:column headerValue="Pay Run">
                    <apex:inputField value="{!int.Pay_Run__c}"/>                                      
                </apex:column>

                <apex:column headerValue="Monday">
                <apex:inputField value="{!int.Monday__c}"/>
                </apex:column>
                <apex:column headerValue="Tuesday">
                <apex:inputField value="{!int.Tuesday__c}"/>
                </apex:column>
                <apex:column headerValue="Wednesday">
                <apex:inputField value="{!int.Wednesday__c}"/>
                </apex:column>
                <apex:column headerValue="Thursday">
                <apex:inputField value="{!int.Thursday__c}"/>
                </apex:column>
                <apex:column headerValue="Friday">
                <apex:inputField value="{!int.Friday__c}"/>
                </apex:column>
                 <apex:column headerValue="Delete">
                <apex:commandLink style="font-size:15px; font-weight:bold; text-align:center;color:red;" value="X" action="{!delRow}">
                    <apex:param value="{!rowNum}" name="index"/>
                    </apex:commandLink>
                    <apex:variable var="rowNum" value="{!rowNum+1}"/>
                </apex:column>
            </apex:PageBlockTable>
        <apex:pageBlockButtons >
            <apex:commandButton value="Save" action="{!insertChild}"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>

      </apex:form>
</apex:page>

And this is the controller

public class AddingChildController {
    Id parentId;
    public List<Time_Sheets__c> childList {get;set;}
    public Integer rowNum{get;set;}


    public AddingChildController(){
        Id childId = ApexPages.currentPage().getParameters().get('childId');
        childList = new List<Time_Sheets__c>();
        childList.add(new Time_Sheets__c());
        ParentId=ApexPages.currentPage().getParameters().get('ParentId');   

    }

    public pagereference insertChild(){
        insert childList;
        Pagereference page=new pagereference('/'+parentId);
        Return page;

    }    

    public void insertRow(){
        childList.add(new Time_Sheets__c());


    }

    public void delRow(){
        rowNum = 
    Integer.valueof(apexpages.currentpage().getparameters().get('index'));

    childList.remove(rowNum);
    }
}

any ideas where I am going wrong ?

  • Are you sure that you're setting parentId=xyz in the query string when you're navigating to (or testing) this page/controller? – Derek F Sep 4 at 3:06
  • I have been testing form the VF preview page – derek dolan Sep 4 at 3:12
  • @DerekF I just create VF tab and test from there - same result – derek dolan Sep 4 at 3:17
  • what is the url when you're getting this error? – Nick Cook Sep 4 at 3:55
  • 1
    @derekdolan why don't you post the answer so anyone else that comes across this can see the problem? It will also close the question so it doesn't keep re-appearing on the home page. This is a general Q&A site for the whole world to use, not just a 'help derek dolan' site. – Nick Cook Sep 4 at 4:51
0

If you want to redirect to the parent's detail page, you can use the lookup field on child record and then navigate to that record.

So your code should be

public pagereference insertChild(){
    insert childList;

    Pagereference parentPage;
    if(!childList.isEmpty() && !string.isBlank(childList[0].Lead_Gen__c))
        parentPage=new pagereference('/'+childList[0].Lead_Gen__c);
    return parentPage;
} 

So the above code inserts the child records and navigates to the first child records parents detail page. Assumption here is that all child records would be having the same parent record.

  • Hi @derekdolan if this or any answer has solved your question please consider accepting it by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this. – Vijay Ganji Oct 3 at 10:33

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.