And this is the controller<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="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>
​​​​​​Could someone assist with what I am missingcheerspublic class AddingChildController {
Id parentId;
public List<Time_Sheets__c> childList {get;set;}
public Integer rowNum{get;set;}
public Lead_Gen__c Parent {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;
Parent.Id=parentId;
update Parent;
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);
}
}
Hi Derek,Greetings to you!This error occurs when your variable (sObject, List, Set or any other data type) is not initialized (allocated memory). In order to use the non-primitive data type in the code, we need to initialize the memory first. If we don’t do that it may result in Attempt to de-reference a null object error. For Example, if you use like this:
It will result in attempt to de-reference a null object error.Account acc;
acc.Name = 'Khan';
We should use it like this:
Reference: http://www.sfdcpoint.com/salesforce/system-nullpointerexception-attempt-to-de-reference-a-null-object/In your code, you need to initialize the Parent in the constructor:Parent = new Account();Account acc = new Account();
acc.Name = 'Khan';
Please try below code:
I hope it helps you.Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.public class AddingChildController {
Id parentId;
public List<Time_Sheets__c> childList {get;set;}
public Integer rowNum{get;set;}
public Lead_Gen__c Parent {get;set;}
public AddingChildController(){
Parent = new Account();
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;
Parent.Id=parentId;
update Parent;
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);
}
}
Thanks and Regards,
Khan Anas
Derek, I request you to be more clear on your requirement so that we can understand better and can help you accordingly. Please add additional details to highlight exactly what you need. Hi Derek,As you are inserting multiple records in visualforce page it's not possible to open a detail page. You can display the recently inserted records in a table.Visualforce: <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="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:pageBlock>
<apex:pageBlockTable value="{!insertedRecords}" var="rec">
<apex:column value="{!rec.Lead_Gen__c}" />
<apex:column value="{!rec.Monday__c}" />
<apex:column value="{!rec.Tuesday__c}" />
<apex:column value="{!rec.Wednesday__c}" />
<apex:column value="{!rec.Thursday__c}" />
<apex:column value="{!rec.Friday__c}" />
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
I hope it helps you!Regards,Khan Anaspublic class AddingChildController {
public List<Time_Sheets__c> childList {get;set;}
public Integer rowNum{get;set;}
public List<Time_Sheets__c> insertedRecords {get;set;}
public AddingChildController(){
insertedRecords = new List<Time_Sheets__c>();
childList = new List<Time_Sheets__c>();
childList.add(new Time_Sheets__c());
}
public void insertChild(){
insert childList;
insertedRecords = [SELECT Id, Lead_Gen__c, Monday__c, Tuesday__c, Wednesday__c, Thursday__c, Friday__c FROM Time_Sheets__c ORDER BY CreatedDate DESC LIMIT 10];
childList.clear();
childList.add(new Time_Sheets__c());
}
public void insertRow(){
childList.add(new Time_Sheets__c());
}
public void delRow(){
rowNum =
Integer.valueof(apexpages.currentpage().getparameters().get('index'));
childList.remove(rowNum);
}
}
The idea is that users can enter values into the VF page and they will be able to creaet many child records agains the parent with the most recent control this works well . But there was no follow up page after the users hit save, that is why I was addingpublic pagereference insertChild(){ insert childList; Parent.Id=parentId; update Parent; Pagereference page=new pagereference('/'+parentId); Return page;which is where thinge fell apart for me let me knwo if still not clear ? This controller will create the records into the system Succsfully
I only added the parent.id to use with pagerefernce because I need to display the updated records to the user once they hit the save button. With the above controller i just get "URL No Longer ExistsYou have attempted to reach a URL that no longer exists on salesforce.com."So then my question is what do I need to add to the above controller to simply display the updated records to the user ?thankspublic 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());
}
public void insertChild(){
insert childList;
}
public void insertRow(){
childList.add(new Time_Sheets__c());
}
public void delRow(){
rowNum =
Integer.valueof(apexpages.currentpage().getparameters().get('index'));
childList.remove(rowNum);
}
}
@khanthanks for thisI am not getting ​​​​​​Visualforce ErrorHelp for this PageSystem.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []Error is in expression '{!insertChild}' in component <apex:commandButton> in page updatechild: Class.AddingChildController.insertChild: line 25, column 1Class.AddingChildController.insertChild: line 25, column 1When I hit save any ideas please ?Cheers Hi Derek, When we use list or set then also we need to allocate memory to list or set like this
List<Account> accList = new List<Account>();
Set<String> strSet= new Set<String>();
Please allocate memory to ParentId line no: 2 in controller.
Thank Youwww.nubeselite.com
Developement | Training | ConsultingPlease Mark this as solution if your problem resolved.