You need to sign in to do that
Don't have an account?
Peter Guzman Garcia 22
System.NullPointerException: Attempt to de-reference a null object Trigger.NumberofUnitsPerTypeSelected: line 7, column 1
Hi;
I am hoping to get some help on this trigger. I am new to Apex programming. I have a custom object called Dues Calculator. For which I have a picklist depency, when the user selects one option "Unit Type" two additional picklist fields that need to be filled out are pre-populated with the correct options. Since I need to use those fields in formula. I created addtional fields that end in "selected". The purpose of my trigger is to automatically populate the "selected" fields with the options from the picklist depencies.
This is my trigger:
trigger NumberofUnitsPerTypeSelected on Dues_Calculator__c (before insert) {
for(Dues_Calculator__c dues : Trigger.New){
// Converting and Assigning the Picklist Value to the Selected Field to be used in a formula
Decimal numberUnitTypeSelected = Dues.Number_of_Units_Per_Type_Selected__c;
String numberUnitType = Dues.Number__c;
numberUnitType = numberUnitTypeSelected.format();
// Converting and Assigning the Picklist Value to the Selected Field to be used in a formula
Decimal percentageSelected = Dues.Percentage_of_Ownership_Type_Selected__c;
String percentageOwnershipShare = Dues.Percentage_of_Ownership_Share__c;
percentageOwnershipShare = percentageSelected.format();
insert dues;
}
}
I get a Null Pointer Exception error, I tried to add the option to create a list. I am stuck here.
Any help is greatly appreciated;
Peter
I am hoping to get some help on this trigger. I am new to Apex programming. I have a custom object called Dues Calculator. For which I have a picklist depency, when the user selects one option "Unit Type" two additional picklist fields that need to be filled out are pre-populated with the correct options. Since I need to use those fields in formula. I created addtional fields that end in "selected". The purpose of my trigger is to automatically populate the "selected" fields with the options from the picklist depencies.
This is my trigger:
trigger NumberofUnitsPerTypeSelected on Dues_Calculator__c (before insert) {
for(Dues_Calculator__c dues : Trigger.New){
// Converting and Assigning the Picklist Value to the Selected Field to be used in a formula
Decimal numberUnitTypeSelected = Dues.Number_of_Units_Per_Type_Selected__c;
String numberUnitType = Dues.Number__c;
numberUnitType = numberUnitTypeSelected.format();
// Converting and Assigning the Picklist Value to the Selected Field to be used in a formula
Decimal percentageSelected = Dues.Percentage_of_Ownership_Type_Selected__c;
String percentageOwnershipShare = Dues.Percentage_of_Ownership_Share__c;
percentageOwnershipShare = percentageSelected.format();
insert dues;
}
}
I get a Null Pointer Exception error, I tried to add the option to create a list. I am stuck here.
Any help is greatly appreciated;
Peter
Attempt to de-reference a null object” normally occurs when you try to reference an object which has not been initialized or has null values. To avoid this you need to make sure that all the sObjects in your class are initialized, preferably in the constructor. Hope this helps.
For sone other information please visit: ( https://printerloop.com/ ).
Thank you.
All Answers
Can you please clarify the below points.
which field you are selecting & what is the value?
In which field you need auto populate the two picklist values and what is the data type of that field?
Thanks!!
I need to autopopulate the value of: "Number_of_Units_Per_Type_Selected__c" this field is a decimal.
from the selected value of: "Number__c" this field is a Picklist Value String.
I need to autopopulate the value of: "Percentage_of_Ownership_Type_Selected__c" this field is a percent.
from the selected value of: "Percentage_of_Ownership_Share__c" this is a Picklist Value String.
The API name for my custom object is: Dues_Calculator__c
It would be nice if it was a before insert trigger, an after insert works too.
Thank you;
Peter
Attempt to de-reference a null object” normally occurs when you try to reference an object which has not been initialized or has null values. To avoid this you need to make sure that all the sObjects in your class are initialized, preferably in the constructor. Hope this helps.
For sone other information please visit: ( https://printerloop.com/ ).
Thank you.
Thanks for sharing this informative and amazing post here. I found it very interesting and enjoy reading this blog. Will wait for more posts.
https://anhuijiuxinltd.com/product/disposable-tableware/
What are all the picklist values in Number__c & Percentage_of_Ownership_Share__c??
Thanks!!
wordle unlimited (https://wordleunlimited.io/)
Birthday Decoration (https://www.7eventzz.com/service/category/birthday/birthday-decorations)
Balloon Decoration (https://www.7eventzz.com/balloon-decorations)
Anniversary Decoration (https://www.7eventzz.com/anniversary-decorations)
Baby Shower Decoration (https://www.7eventzz.com/baby-shower-decorations)
Baby Welcome Decoration (https://www.7eventzz.com/service/category/kids/welcome-baby)
Balloon Decoration in Delhi (https://cherishx.com/experiences/delhi-ncr/balloon-room-decorations)
Baby Shower Decorations in Delhi (https://cherishx.com/experiences/delhi-ncr/baby-shower)
Anniversary Decorations in Delhi (https://cherishx.com/experiences/delhi-ncr/anniversary-decoration)
Baby Welcome Decorations in Delhi (https://cherishx.com/experiences/delhi-ncr/welcome-baby-decoration)
Canopy Decorations in Delhi (https://cherishx.com/experiences/delhi-ncr/canopy-decorations)
Kids Birthday Decorations in Delhi (https://cherishx.com/experiences/delhi-ncr/kids-theme-decoration)
Bachelor Party Decorations in Delhi (https://cherishx.com/experiences/delhi-ncr/bachelorette-theme-decorations)
No doubt, birthdays are special for everyone especially for kids. Additionally, their birthday party is more important for them than any other thing. Birthday World, being best birthday organizer company have a variety of new themes for birthdays.
Games on rent in Gurgaon
Birthday Party Organisers in Gurgaon | Birthday Decorators in Gurgaon | Birthday Planner in Gurgaon | Birthday Event Planners in Gurgaon
Artists for birthday party in Gurgaon
Ankara eşya depolama
Antalya Boya Ustası