-
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, 6 months ago by
Pragya.
-
This discussion was modified 5 years, 6 months ago by
Log In to reply.
Popular Salesforce Blogs
Salesforce Lightning Aura Components Core Concepts
Page & Bundle Visualforce pages (and Visualforce additives, but permits’s set those apart for now) are saved on Salesforce as a single entity, an ApexPage.…
Get Salesforce record data into your Google Sheet through G-Connector - Part 2
Hello All, In my last blog, I shared with you all the required steps to install and configure G-connector for Salesforce. Now I am going to…
A Nonprofit's Success with Salesforce
Case Study: Nonprofit Organization Leverages Salesforce for Growth Organization: The Community Foundation Challenge: The Community Foundation struggled to manage donor relationships, track donations effectively, and…
Popular Salesforce Videos
Financial Services Cloud – Release Readiness LIVE, Summer '19
Hear about some of the new and exciting features that you can expect from Financial Services Cloud in the Summer '19 Release. Highlights include: -…
Salesforce Video Wall
Salesforce approached Obscura with the opportunity to create imaginative media for the 107’ long LED video wall in the lobby of their flagship San Francisco…
What are Profiles and Permission Sets in Salesforce ? | Object Level Security in Salesforce
In this video, Shrey have explained complete Object Level Security in Salesforce which includes: 1. What is the significance of defining Object-level security in Salesforce?…
Popular Salesforce Infographics
5 Advantages of Using Salesforce for Your Business
Salesforce is a customer relationship management (CRM) platform that offers a wide range of features and benefits for businesses of all sizes. Here are five…
Average Salesforce Salaries in 2023-2024: What You Need to Know
Salesforce is a popular CRM platform that is used by businesses of all sizes. If you're considering a career in Salesforce, you may be wondering…
How to Create a Community of Trust and Gratitude with Salesforce
The businesses that will be remembered positively after COVID-19 are extending empathy and grace to their employees, customers, and communities. We’ve seen so many communities…