-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
1Questions
-
5Replies
Error while clicking custom button:System.NullPointerException: Attempt to dereference a null object
1.Create quote button from opportunity page (detail page) is giving the below error when clicked.
This custom button is calling URL /apex/ManageQuote/ apex code but its giving error
Error
--System.NullPointerException: Attempt to dereference a null object line 31 column 1 which is under public PageReference createQuote() of ManageQuoteController code.
can let us know what is the issue?Thanks in advance for help
Code snippet:
---ManageQuoteController code:
public with sharing class ManageQuoteController {
//Opportunity Reference
public Opportunity opportunityRef {get; set;}
//Quote Creation Error
public Boolean quoteCreationError {get; set;}
//Quote created indicator
public Boolean quoteCreated {get; set;}
//Error Message
public String errorMessage {get; set;}
//Quote URL
public String quoteUrl {get; set;}
//Default Controller
public ManageQuoteController() {
quoteCreated = false;
quoteCreationError = false;
Id opptyId = ApexPages.currentPage().getParameters().get('opportunity.id');
try{
opportunityRef = [select Id, Name from Opportunity where Id = :opptyId];
}
catch (System.QueryException e) {
System.debug('caught ya!');
}
}
public PageReference goback() {
return new Apexpages.Standardcontroller(opportunityRef).view();
}
public PageReference createQuote() {
Opportunity oppty = [select Id, Name, StageName, CloseDate, Owner.Name, AccountId, Account.Name,
Account.Sic, Account.Industry, Account.BillingStreet, Account.BillingCity, Account.BillingState,
Account.BillingPostalCode, Account.BillingCountry from Opportunity where Id = :opportunityRef.Id];
OpportunityContactRole ocr = [select Contact.FirstName, Contact.LastName, Contact.EMail, Contact.Phone, Contact.Fax
from OpportunityContactRole where opportunityId = :opportunityRef.Id and IsPrimary = true];
QuoteResponse response = QuoteServiceDelegate.createQuote(oppty, ocr.Contact);
if (response.stausCode != 200) {
quoteCreationError = true;
errorMessage = response.message;
} else {
quoteCreated = true;
quoteUrl = response.quoteUrl;
}
return null;
}
}
---Manage Quote code
<apex:page name="ManageQuote" controller="ManageQuoteController" id="thisPage" tabStyle="Opportunity">
<script type="text/javascript">
function init() {
if ('{!quoteCreationError}' == 'false' && '{!quoteCreated}' == 'false')
createQuote();
}
window.onload = init;
</script>
<apex:form >
<apex:actionFunction name="createQuote" action="{!createQuote}" rerender="outputBlock, quoteBlock" status="createStatus" />
<apex:sectionHeader title="Manage Quote" subtitle="{!opportunityRef.Name}"/>
<apex:outputPanel id="outputBlock">
<apex:actionStatus id="createStatus">
<apex:facet name="start">
<apex:pageBlock >
<apex:outputText >Creating quote. Please wait...</apex:outputText>
</apex:pageBlock>
</apex:facet>
</apex:actionStatus>
</apex:outputPanel>
<apex:outputPanel id="quoteBlock">
<apex:pageBlock id="errorBlock" title="Error" rendered="{!quoteCreationError}">
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Go Back" action="{!goback}" />
</apex:pageBlockButtons>
<apex:pageBlockSection columns="1">
<apex:outputText value="{!errorMessage}"/>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:iframe src="{!quoteUrl}" scrolling="true" id="quoteFrame" rendered="{!quoteCreated}"/>
</apex:outputPanel>
</apex:form>
</apex:page>
-
- kumark
- August 30, 2012
- Like
- 0
- Continue reading or reply
Error while clicking custom button:System.NullPointerException: Attempt to dereference a null object
1.Create quote button from opportunity page (detail page) is giving the below error when clicked.
This custom button is calling URL /apex/ManageQuote/ apex code but its giving error
Error
--System.NullPointerException: Attempt to dereference a null object line 31 column 1 which is under public PageReference createQuote() of ManageQuoteController code.
can let us know what is the issue?Thanks in advance for help
Code snippet:
---ManageQuoteController code:
public with sharing class ManageQuoteController {
//Opportunity Reference
public Opportunity opportunityRef {get; set;}
//Quote Creation Error
public Boolean quoteCreationError {get; set;}
//Quote created indicator
public Boolean quoteCreated {get; set;}
//Error Message
public String errorMessage {get; set;}
//Quote URL
public String quoteUrl {get; set;}
//Default Controller
public ManageQuoteController() {
quoteCreated = false;
quoteCreationError = false;
Id opptyId = ApexPages.currentPage().getParameters().get('opportunity.id');
try{
opportunityRef = [select Id, Name from Opportunity where Id = :opptyId];
}
catch (System.QueryException e) {
System.debug('caught ya!');
}
}
public PageReference goback() {
return new Apexpages.Standardcontroller(opportunityRef).view();
}
public PageReference createQuote() {
Opportunity oppty = [select Id, Name, StageName, CloseDate, Owner.Name, AccountId, Account.Name,
Account.Sic, Account.Industry, Account.BillingStreet, Account.BillingCity, Account.BillingState,
Account.BillingPostalCode, Account.BillingCountry from Opportunity where Id = :opportunityRef.Id];
OpportunityContactRole ocr = [select Contact.FirstName, Contact.LastName, Contact.EMail, Contact.Phone, Contact.Fax
from OpportunityContactRole where opportunityId = :opportunityRef.Id and IsPrimary = true];
QuoteResponse response = QuoteServiceDelegate.createQuote(oppty, ocr.Contact);
if (response.stausCode != 200) {
quoteCreationError = true;
errorMessage = response.message;
} else {
quoteCreated = true;
quoteUrl = response.quoteUrl;
}
return null;
}
}
---Manage Quote code
<apex:page name="ManageQuote" controller="ManageQuoteController" id="thisPage" tabStyle="Opportunity">
<script type="text/javascript">
function init() {
if ('{!quoteCreationError}' == 'false' && '{!quoteCreated}' == 'false')
createQuote();
}
window.onload = init;
</script>
<apex:form >
<apex:actionFunction name="createQuote" action="{!createQuote}" rerender="outputBlock, quoteBlock" status="createStatus" />
<apex:sectionHeader title="Manage Quote" subtitle="{!opportunityRef.Name}"/>
<apex:outputPanel id="outputBlock">
<apex:actionStatus id="createStatus">
<apex:facet name="start">
<apex:pageBlock >
<apex:outputText >Creating quote. Please wait...</apex:outputText>
</apex:pageBlock>
</apex:facet>
</apex:actionStatus>
</apex:outputPanel>
<apex:outputPanel id="quoteBlock">
<apex:pageBlock id="errorBlock" title="Error" rendered="{!quoteCreationError}">
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Go Back" action="{!goback}" />
</apex:pageBlockButtons>
<apex:pageBlockSection columns="1">
<apex:outputText value="{!errorMessage}"/>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:iframe src="{!quoteUrl}" scrolling="true" id="quoteFrame" rendered="{!quoteCreated}"/>
</apex:outputPanel>
</apex:form>
</apex:page>
- kumark
- August 30, 2012
- Like
- 0
- Continue reading or reply