+ Start a Discussion

Save and New Button

Hi Friends,

I am unable to write code for save and new button on VF page. When I tried saving a record I got Error Message as follows

Visualforce Error

System.NullPointerException: Attempt to de-reference a null object

Error is in expression '{!saveandnew}' in component <apex:page> in page familybankingnewpage



Class.familyController.saveandnew: line 18, column 1



Please help me

The controller I tried is as follows:


public with sharing class familyController {

public familyController(ApexPages.StandardController controller) {


public Family__c family{get;set;}
List<Family__c> rec;
public familyController(){
rec = new List<Family__c>();
public PageReference save(){
return null;
public PageReference saveandnew(){
//family = new Family__c();
update family;
} catch(System.DMLException e) {
return null;

return (new ApexPages.StandardController(new Family__c())).edit();
/* public PageReference cancel(){
return null;
} */



Thanks In advance    -----



Praful GadgePraful Gadge
if(family != null)

Put this null check before following DML Update operation and check if it works?

update family;