function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Chitral ChaddaChitral Chadda 

insert a new case vf page

i have  created a vf  page which picks up account fields like email , contact information , mailing city,street , state etc and  edit the required field.
and wen user  clicks create case button a new case shud b created and those field should be populated inside case object (like email.mailing street et)


<apex:commandButton value="Create Case" action="{!createCase}"  rendered="{!showButton}" style="margin-left: 69%;margin-right: 22.2%;"/>

</div>

and here is one example of a field
 <apex:inputfield value="{!account.Email__c}" style="margin-left: 30%"  rendered="{!!showField}"></apex:inputfield>
and many more are there for city ,state.

class:

public account acc{get;set;}

public void createCase()    
{  case c = new case();
  
   c.Phone_Type_1__c=acc.Phone_Type_1__c; //************line 47
   c.Phone_Type_2__c=acc.Phone_Type_2__c;
   c.Phone_Type_3__c=acc.Phone_Type_3__c;
   
   
   c.Phone_1__c=acc.Phone_1__c;
   c.Phone_2__c=acc.Phone_2__c;
   c.Phone_3__c=acc.Phone_3__c;
   
   c.Mailing_Address__c=acc.Mailing_Address__c;   
   c.Mailing_City__c=acc.Mailing_City__c;   
   c.Mailing_State__c=acc.Mailing_State__c;
   c.Mailing_Zip__c=acc.Mailing_Zip__c;
   
   c.Email__c=acc.Email__c;
   
   

}

after making the changes wen i click create a case i get this error

System.NullPointerException: Attempt to de-reference a null object
Error is in expression '{!createCase}' in component <apex:commandButton> in page editaccountpage: Class.EditaccountPage.createCase: line 47, column 1 //( i hv marked this line in code )
 
Best Answer chosen by Chitral Chadda
Ravikant kediaRavikant kedia
To resolve your problem you have to make a constructor and write one line inside it.
acc = new Account(); and check it your problem will solve and other reason may be acc.Phone_Type_1__c (null value in it).

All Answers

Ravikant kediaRavikant kedia
To resolve your problem you have to make a constructor and write one line inside it.
acc = new Account(); and check it your problem will solve and other reason may be acc.Phone_Type_1__c (null value in it).
This was selected as the best answer
Chitral ChaddaChitral Chadda
Thnku But can u explain me reason pls
Ravikant kediaRavikant kedia
Hi Chitral Chadda,
                             According to me if you assign any thing in object variable  then you have to make object for it else in object variable null may be assign and sorry i don't know paricular reason for it . If my answer solve your problem then select this as a best answer please.