I need to create Multiple Child Records from Parent Related List but i get the Error: "URL No Longer Exists" but the data saved in the database. Also, it seem that the Parent Id does not populate autonmatically so, i have to add it manually. I want to notice that I add the child page as a related list of the parent. The Parent Obejct is Devery__c, the child is Item_Distributed__c Here is my code:
public class AddOrderItem {
public String Delivery { get; set; }
Id DeliveryId;
public List<Item_Distributed__c> listOrderItem {get;set;}
public Integer rowNum{get;set;}
public AddOrderItem(ApexPages.StandardController controller){
Id OrderItemId = ApexPages.currentPage().getParameters().get('OrderItemId');
DeliveryId=ApexPages.currentPage().getParameters().get('DeliveryId');
listOrderItem = new List<Item_Distributed__c>();
listOrderItem.add(new Item_Distributed__c());
}
public pagereference insertOrderItem(){
insert listOrderItem;
Pagereference page=new pagereference('/'+DeliveryId);
Return page;
}
public void insertRow(){
listOrderItem.add(new Item_Distributed__c());
}
public void delRow(){
rowNum =
Integer.valueof(apexpages.currentpage().getparameters().get('index'));
listOrderItem.remove(rowNum);
}
}
VF Page
<apex:page StandardController="Delivery__c" Extensions="AddOrderItem" showHeader="false" sidebar="false" >
<apex:form >
<apex:variable var="rowNum" value="{!0}" />
<apex:pageBlock >
<apex:variable var="rowNum" value="{!0}" />
<apex:PageBlockTable value="{!listOrderItem}" var="int">
<apex:facet name="footer">
<apex:commandLink value="Add" action="{!insertRow}"/>
</apex:facet>
<apex:column headerValue="Quantity">
<apex:inputField value="{!int.Quantity__c}"/>
</apex:column>
<apex:column headerValue="Product">
<apex:inputField value="{!int.Product__c}"/>
</apex:column>
<apex:column headerValue="Product">
<apex:inputField value="{!int.Delivery__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="{!insertOrderItem}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>