You need to sign in to do that
Don't have an account?
❤Code
getting null pointer exxception
Hi All,
I am getting NPE error in line no 55. Can anybody help me out in this how to resolve this .
Apex Class -
public with sharing class soption1
{
public soption1() {
}
SLA__c account;
SOC__c contact;
MSA__c opportunity;
public List<MSA__C> records{get;set;}
public MSA__c objAct{get;set;}
public List<MSAWrapper> MSAWrapperList {get; set;}
public soption1(ApexPages.StandardController controller)
{
objAct = new MSA__C();
MSAWrapperList = new List<MSAWrapper>();
}
public SLA__c getAccount() {
if(account == null) account = new SLA__c();
return account;
}
public SOC__c getContact() {
if(contact == null) contact = new SOC__c();
return contact;
}
public PageReference step1() {
return Page.newOpptyStep11;
}
public PageReference step2() {
return Page.testmulti1;
}
public pagereference search()
{
MSAWrapperList.clear();
records=[Select ID,Name,Coe__c,Dept__c,OpCo__c from MSA__C where Coe__c=: objAct.Coe__c and Dept__c=: objAct.Dept__c];
for(MSA__C obj : records)
{
MSAWrapperList.add( new MSAWrapper(obj) );
}
return null;
}
public PageReference processSelected()
{
account.Name = contact.Name; /// errror here
insert account;
List<MSA__C> selectedMSA = new List<MSA__C>();
for(MSAWrapper cCon: MSAWrapperList )
{
if(cCon.selected == true)
{
selectedMSA.add(cCon.msaObj);
}
}
for(MSA__C msa: selectedMSA)
{
system.debug(msa);
SOC__c so = new SOC__c();
so.Name = msa.Name;
so.SLA__c = account.id;
insert so;
// Please add your login here
}
return null;
}
public class MSAWrapper
{
public MSA__C msaObj {get; set;}
public Boolean selected {get; set;}
public MSAWrapper(MSA__C c) {
msaObj = c;
selected = false;
}
}
}
Regards
I am getting NPE error in line no 55. Can anybody help me out in this how to resolve this .
Apex Class -
public with sharing class soption1
{
public soption1() {
}
SLA__c account;
SOC__c contact;
MSA__c opportunity;
public List<MSA__C> records{get;set;}
public MSA__c objAct{get;set;}
public List<MSAWrapper> MSAWrapperList {get; set;}
public soption1(ApexPages.StandardController controller)
{
objAct = new MSA__C();
MSAWrapperList = new List<MSAWrapper>();
}
public SLA__c getAccount() {
if(account == null) account = new SLA__c();
return account;
}
public SOC__c getContact() {
if(contact == null) contact = new SOC__c();
return contact;
}
public PageReference step1() {
return Page.newOpptyStep11;
}
public PageReference step2() {
return Page.testmulti1;
}
public pagereference search()
{
MSAWrapperList.clear();
records=[Select ID,Name,Coe__c,Dept__c,OpCo__c from MSA__C where Coe__c=: objAct.Coe__c and Dept__c=: objAct.Dept__c];
for(MSA__C obj : records)
{
MSAWrapperList.add( new MSAWrapper(obj) );
}
return null;
}
public PageReference processSelected()
{
account.Name = contact.Name; /// errror here
insert account;
List<MSA__C> selectedMSA = new List<MSA__C>();
for(MSAWrapper cCon: MSAWrapperList )
{
if(cCon.selected == true)
{
selectedMSA.add(cCon.msaObj);
}
}
for(MSA__C msa: selectedMSA)
{
system.debug(msa);
SOC__c so = new SOC__c();
so.Name = msa.Name;
so.SLA__c = account.id;
insert so;
// Please add your login here
}
return null;
}
public class MSAWrapper
{
public MSA__C msaObj {get; set;}
public Boolean selected {get; set;}
public MSAWrapper(MSA__C c) {
msaObj = c;
selected = false;
}
}
}
Regards
public with sharing class soption1
{
public soption1() {
account=new SLA__c();
contact=new SOC__c();
opportunity=new MSA__c();
records=new List<MSA__C>();
objAct=new MSA__c();
msawrapperlist=new List<MSAWrapper>();
}
public SLA__c account{set;get;};
public SOC__c contact{set;get;};
public MSA__c opportunity{set;get;};
public List<MSA__C> records{get;set;}
public MSA__c objAct{get;set;}
public List<MSAWrapper> MSAWrapperList {get; set;}
public soption1(ApexPages.StandardController controller)
{
objAct = new MSA__C();
MSAWrapperList = new List<MSAWrapper>();
}
public SLA__c getAccount() {
if(account == null) account = new SLA__c();
return account;
}
public SOC__c getContact() {
if(contact == null) contact = new SOC__c();
return contact;
}
public PageReference step1() {
return Page.newOpptyStep11;
}
public PageReference step2() {
return Page.testmulti1;
}
public pagereference search()
{
MSAWrapperList.clear();
records=[Select ID,Name,Coe__c,Dept__c,OpCo__c from MSA__C where Coe__c=: objAct.Coe__c and Dept__c=: objAct.Dept__c];
for(MSA__C obj : records)
{
MSAWrapperList.add( new MSAWrapper(obj) );
}
return null;
}
public PageReference processSelected()
{
account.Name = contact.Name;
insert account;
List<MSA__C> selectedMSA = new List<MSA__C>();
for(MSAWrapper cCon: MSAWrapperList )
{
if(cCon.selected == true)
{
selectedMSA.add(cCon.msaObj);
}
}
for(MSA__C msa: selectedMSA)
{
system.debug(msa);
SOC__c so = new SOC__c();
so.Name = msa.Name;
so.SLA__c = account.id;
insert so;
// Please add your login here
}
return null;
}
public class MSAWrapper
{
public MSA__C msaObj {get; set;}
public Boolean selected {get; set;}
public MSAWrapper(MSA__C c) {
msaObj = c;
selected = false;
}
}
}
Hope this helps! Mark it as solution if this solves your problem.
Regards
Eswar Prasad.
All Answers
NOTE: This code has not been tested and may contain typographical or logical errors.
I am trying to create a wizard kind of functionality. I am still getting the NPE error . Below is my vf pages and apex classess. Kindly check and help me to know where to modify.
Apex Class -
public with sharing class soption1
{
public soption1() {
}
SLA__c account;
SOC__c contact;
MSA__c opportunity;
public List<MSA__C> records{get;set;}
public MSA__c objAct{get;set;}
public List<MSAWrapper> MSAWrapperList {get; set;}
public soption1(ApexPages.StandardController controller)
{
objAct = new MSA__C();
MSAWrapperList = new List<MSAWrapper>();
}
public SLA__c getAccount() {
if(account == null) account = new SLA__c();
return account;
}
public SOC__c getContact() {
if(contact == null) contact = new SOC__c();
return contact;
}
public PageReference step1() {
return Page.newOpptyStep11;
}
public PageReference step2() {
return Page.testmulti1;
}
public pagereference search()
{
MSAWrapperList.clear();
records=[Select ID,Name,Coe__c,Dept__c,OpCo__c from MSA__C where Coe__c=: objAct.Coe__c and Dept__c=: objAct.Dept__c];
for(MSA__C obj : records)
{
MSAWrapperList.add( new MSAWrapper(obj) );
}
return null;
}
public PageReference processSelected()
{
account.Name = contact.Name;
insert account;
List<MSA__C> selectedMSA = new List<MSA__C>();
for(MSAWrapper cCon: MSAWrapperList )
{
if(cCon.selected == true)
{
selectedMSA.add(cCon.msaObj);
}
}
for(MSA__C msa: selectedMSA)
{
system.debug(msa);
SOC__c so = new SOC__c();
so.Name = msa.Name;
so.SLA__c = account.id;
insert so;
// Please add your login here
}
return null;
}
public class MSAWrapper
{
public MSA__C msaObj {get; set;}
public Boolean selected {get; set;}
public MSAWrapper(MSA__C c) {
msaObj = c;
selected = false;
}
}
}
Vf Page 1 -
<apex:page controller="soption1"
tabStyle="Opportunity">
<apex:sectionHeader title="New Customer Opportunity"
subtitle="Step 1 of 3"/>
<apex:form >
<apex:pageBlock title="Customer Information">
<!-- This facet tag defines the "Next" button that appears
in the footer of the pageBlock. It calls the step2()
controller method, which returns a pageReference to
the next step of the wizard. -->
<apex:facet name="footer">
<apex:commandButton action="{!step2}" value="Next"
styleClass="btn"/>
</apex:facet>
<apex:pageBlockSection title="Account Information">
<!-- <apex:panelGrid> tags organize data in the same way as
a table. It places all child elements in successive cells,
in left-to-right, top-to-bottom order -->
<!-- <apex:outputLabel > and <apex:inputField > tags can be
bound together with the for and id attribute values,
respectively. -->
<apex:panelGrid columns="2">
<apex:outputLabel value="Account Name" for="accountName"/>
<apex:inputField id="accountName" value="{!account.name}"/>
</apex:panelGrid>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Vf Page 2 -
<apex:page standardController="MSA__c" extensions="soption1" sidebar="false">
<apex:messages style="color:red"></apex:messages>
<apex:form id="theform">
<apex:pageblock mode="edit">
<apex:pageblockSection >
<apex:inputfield value="{!objAct.Coe__c}" />
<apex:inputfield value="{!objAct.Dept__c}" />
<apex:inputfield value="{!objAct.OpCo__c }" />
</apex:pageblockSection>
<apex:pageBlockButtons >
<apex:commandButton value="Search" action="{!search}" />
</apex:pageBlockButtons>
</apex:pageblock>
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Process Selected" action="{!processSelected}" rerender="table"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!MSAWrapperList}" var="obj" id="table">
<apex:column >
<apex:inputCheckbox value="{!obj.selected}"/>
</apex:column>
<apex:column value="{!obj.msaObj.Name}" />
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Regards
Hope this helps! Mark it as solution if this solves your problem.
public with sharing class soption1
{
public soption1() {
account=new SLA__c();
contact=new SOC__c();
opportunity=new MSA__c();
records=new List<MSA__C>();
objAct=new MSA__c();
msawrapperlist=new List<MSAWrapper>();
}
public SLA__c account{set;get;};
public SOC__c contact{set;get;};
public MSA__c opportunity{set;get;};
public List<MSA__C> records{get;set;}
public MSA__c objAct{get;set;}
public List<MSAWrapper> MSAWrapperList {get; set;}
public soption1(ApexPages.StandardController controller)
{
objAct = new MSA__C();
MSAWrapperList = new List<MSAWrapper>();
}
public SLA__c getAccount() {
if(account == null) account = new SLA__c();
return account;
}
public SOC__c getContact() {
if(contact == null) contact = new SOC__c();
return contact;
}
public PageReference step1() {
return Page.newOpptyStep11;
}
public PageReference step2() {
return Page.testmulti1;
}
public pagereference search()
{
MSAWrapperList.clear();
records=[Select ID,Name,Coe__c,Dept__c,OpCo__c from MSA__C where Coe__c=: objAct.Coe__c and Dept__c=: objAct.Dept__c];
for(MSA__C obj : records)
{
MSAWrapperList.add( new MSAWrapper(obj) );
}
return null;
}
public PageReference processSelected()
{
account.Name = contact.Name;
insert account;
List<MSA__C> selectedMSA = new List<MSA__C>();
for(MSAWrapper cCon: MSAWrapperList )
{
if(cCon.selected == true)
{
selectedMSA.add(cCon.msaObj);
}
}
for(MSA__C msa: selectedMSA)
{
system.debug(msa);
SOC__c so = new SOC__c();
so.Name = msa.Name;
so.SLA__c = account.id;
insert so;
// Please add your login here
}
return null;
}
public class MSAWrapper
{
public MSA__C msaObj {get; set;}
public Boolean selected {get; set;}
public MSAWrapper(MSA__C c) {
msaObj = c;
selected = false;
}
}
}
Hope this helps! Mark it as solution if this solves your problem.
Regards
Eswar Prasad.