-
Attempt to de-reference a null object apex
Hi,
I am getting attempt to de-reference a null object apex error while trying to allocate the record to a particular record type.
Please help me out.
Requirement:
<div>As soon as the Return request record is created, automatically create "Voucher" record from the backend. For example - if Return request is approved for amount 5000, then there should be three Voucher records created automatically from backend (one record with record type 1000, two records with record type 2000)</div>
public class returnRequestTriggerHandler
{
public void createVouchers(List<return_request__c> reqList)</return_request__c>
{
List<voucher__c> vList = new List<voucher__c>();</voucher__c></voucher__c>
Decimal[] voucherNames=new Decimal[] {2000,1000,500,100,50,10,5,1};
for(Return_Request__c r:reqList){
Decimal price=r.Item_Original_Price__c;
integer n=0;
while(price>0)
{
Voucher__c newVoucher=new Voucher__c();
if(price-voucherNames[n]>=0)
{
newVoucher.Name=String.valueOf(voucherNames[n].format())+' Voucher';
newVoucher.Amount__c=voucherNames[n];
newVoucher.Return_Request__c=r.Id;
if(voucherNames[n]==2000){
newVoucher.RecordTypeId= Schema.SObjectType.Voucher__c.getRecordTypeInfosByName()
.get('X2000').getRecordTypeId();
}
else if(voucherNames[n]==1000){
newVoucher.RecordTypeId= Schema.SObjectType.Voucher__c.getRecordTypeInfosByName()
.get('X1000').getRecordTypeId();
}
else if(voucherNames[n]==500){
newVoucher.RecordTypeId= Schema.SObjectType.Voucher__c.getRecordTypeInfosByName()
.get('X500').getRecordTypeId();
}
else if(voucherNames[n]==100){
newVoucher.RecordTypeId= Schema.SObjectType.Voucher__c.getRecordTypeInfosByName()
.get('X100').getRecordTypeId();
}
else if(voucherNames[n]==50){
newVoucher.RecordTypeId= Schema.SObjectType.Voucher__c.getRecordTypeInfosByName()
.get('X50').getRecordTypeId();
}
else if(voucherNames[n]==10){
newVoucher.RecordTypeId= Schema.SObjectType.Voucher__c.getRecordTypeInfosByName()
.get('X10').getRecordTypeId();
}
else if(voucherNames[n]==5){
newVoucher.RecordTypeId= Schema.SObjectType.Voucher__c.getRecordTypeInfosByName()
.get('X5').getRecordTypeId();
}
else{
newVoucher.RecordTypeId= Schema.SObjectType.Voucher__c.getRecordTypeInfosByName()
.get('X1').getRecordTypeId();
}
vList.add(newVoucher);
price=price-voucherNames[n];
}
else{
n++;
}
}
}
insert vList;
}
}-
This discussion was modified 5 years, 4 months ago by
Pragya.
-
This discussion was modified 5 years, 4 months ago by
Log In to reply.
Popular Salesforce Blogs
How Trailhead Helps People to Learn Salesforce?
Trailhead is Salesforce's free web learning platform committed totally to teach individuals to utilize Salesforce. It provides the user with a guided, learning path with a set of…
What are External Data Sources? | All You Need to Know
Salesforce is a powerful CRM platform that allows businesses to manage customer relationships, sales, marketing, and customer service in one centralized platform. One of the…
Shrink Billing Cycles and Automate Invoices with DemandBlue’s Salesforce Billing Implementation
A simplified billing process elevates the buying experience, makes customers feel comfortable, and often turns them into repeat customers. At DemandBlue, our end-to-end Salesforce Billing…
Popular Salesforce Videos
Drive Adoption with In-App Guidance and our Prebuilt Salesforce Package!
With In-App Guidance generally available in the Winter ‘20 release, there’s no better time to start taking advantage of the easiest way to add informative…
Salesforce Training Videos - Discussion on Admin Concepts
A Salesforce Admin is a business leader, deeply knowledgeable about how their company operates, intertwined in making all departments successful through process automations, and thus,…
Guided Setup with Salesforce Field Service Administration - Webinar Recording
Salesforce Field Service is a complete, end-to-end solution for customer service in the field. Salesforce Field Service brings together customers, employees, and products on a…
Popular Salesforce Infographics
Boost Sales and Marketing with Salesforce Einstein 1
Salesforce Einstein 1 is a suite of artificial intelligence (AI) tools designed to enhance business efficiency and decision-making. Around 80% of customers expect companies to…
Salesforce Unveils Sales and Service Suites Aimed at Accelerating ROI for Businesses
Salesforce has recently unveiled fresh sets of product suites aimed at enhancing the sales and service teams' performance. By integrating top-notch solutions from the Customer…
Salesforce Admin Certification Path
The Salesforce Certified Administrator program is designed for individuals who have experience as a Salesforce administrator. The program encompasses the breadth of applications, the features…