You need to sign in to do that
Don't have an account?
TC Admin
Apex Code to refresh child items error " Attempt to de-reference a null object An unexpected error has occurred. Your development organization has been notified."
Hi all. i'm trying to create a button that refreshes the child opportunity products when discounts are changed on a opportunity.
The Apex code ges a list of the child opportunity products and updates them.
The Visual Force button runs the method. howveer i get an error saying:
Attempt to de-reference a null object
An unexpected error has occurred. Your development organization has been notified.
Any idea what I am doing wrong?
Apex Class
VF Page
The Apex code ges a list of the child opportunity products and updates them.
The Visual Force button runs the method. howveer i get an error saying:
Attempt to de-reference a null object
An unexpected error has occurred. Your development organization has been notified.
Any idea what I am doing wrong?
Apex Class
PUBLIC CLASS OpportunityProductCostRefreshController { //add an instance variable for the standard controller private ApexPages.StandardController controller {get; set;} // add the instance for the variables being passed by id on the url public opportunity OP {get;set;} // set the id of the record that is created -- ONLY USED BY THE TEST CLASS public ID newRecordId {get;set;} //Add the variable for the list being queried PUBLIC LIST <OpportunityLineItem> GetItemsList {get;set;} // Initialize the controller PUBLIC OpportunityProductCostRefreshController(ApexPages.StandardController ctrl) { //initialize the standard controller this.controller = controller; // load the current record OP = (Opportunity)controller.getRecord(); } // method called from the VF's action attribute to refreshing the op lines public PageReference RefreshOpLines() { // setup the save point for rollback Savepoint sp = Database.setSavepoint(); TRY { // Get the list of opportunity line items we want to refresh costs for GetItemsList = [ SELECT Id,OpportunityId, productcode, Quantity, unitprice FROM OpportunityLineItem OPL WHERE Opportunityid= :OP.id ORDER BY productcode ASC ]; { UPDATE GetItemsList ; return null; } } catch (Exception e){ // roll everything back in case of error Database.rollback(sp); ApexPages.addMessages(e); } return new PageReference('/'+OP.id); } }
VF Page
<apex:page standardController="Opportunity" extensions="OpportunityProductCostRefreshController" action="{!RefreshOpLines}"> <apex:pageMessages /> </apex:page>
It should be this.controller = ctrl;
I have made the change below.
Now I just need to get the button to go back to the orginal page again.
Thank you.
I have commented it out below
That does not work. The whole method does not run if i remove that line.
You need to sort it out, use debug statements to verify which of those will actually run. My assumption looking at your code was that the return null would run after the update statement and if so then the final return statement would never get executed.
You only need 1 of those statements.
Any ideas how I can do both?