-
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 4 years, 4 months ago by Pragya.
Log In to reply.
Popular Salesforce Blogs
Syncing Articles from Zendesk Knowledge Base to Salesforce Knowledge – A Success Story
Customers need excellent support with minimal human interaction. That’s why they prefer self-service. And to keep customers hooked to your product, you need to give…
Aura Component Framework and Attributes | All You Need to Know
What is the Lightning Component? A UI framework called component framework is used to create single page applications for desktop and mobile platforms. On the client…
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
Salesforce Pardot Basics - A Comprehensive Guide (2021)
In this short video, we will cover the basics of Salesforce Pardot Pardot by Salesforce is a demand generation and marketing management tool by Salesforce.…
The World of Salesforce Einstein
Salesforce Einstein is artificial intelligence (AI) technology that has been developed for the Salesforce Customer Success Platform. ... Upgrades include Einstein Vision, which brings image…
101 Guide to IBM Watson and Salesforce Einstein
In March 2017, IBM and Salesforce announced a global strategic partnership to seamlessly connect predictive insights found in unstructured data from IBM Watson APIs to…
Popular Salesforce Infographics
Unlock the Potential of Financial Services with Future Trends | Salesforce
The financial services industry is being transformed by emerging technologies like AI, Low-Code, No-Code Solutions, Adoption of the cloud. Discover the various future and trending…
How Your Business Can Leverage The Power of Salesforce Community Cloud?
Community Cloud is a cloud-based platform that enables businesses (small, medium, big) to build exceptional and interactive CRM-powered portals, forums, and sites that are faster…
Overview of Salesforce AppExchange Apps Market: Key Insights and Trends for 2024
The Salesforce AppExchange marketplace continues to expand, offering a diverse array of applications designed to enhance various business operations. Our 2024 analysis delves into the…