-
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
Why Flow with Salesforce Flow?
Earlier when you required a custom feature in your Salesforce installation to support your business process, the only available options were to create a brand…
Einstein Analytics: Data Sync Functionality Explained
Data Sync is a process that helps to ensure that the data in your Salesforce org is ready to be used in Einstein Analytics. This…
Salesforce Data Cloud: Unlocking the Power of Real-Time Customer Data for Smarter Sales
In today’s fast-paced digital landscape, businesses need real-time, actionable customer insights to stay connected and relevant to their customers. With Salesforce Data Cloud, TechForce Services…
Popular Salesforce Videos
Security Best Practices for Building Lightning Components
Lightning Component is a framework to build Salesforce applications faster. If you are using Salesforce1, you already experiencing the Lightning. It is based on an…
Salesforce & Google Analytics integration
Salesforce is one of the most popular CRMs available today. Many teams use Salesforce heavily for reporting and analysis. The ability to model the data…
Create a New Marker Layer in Maps | Salesforce Maps
Salesforce Maps is a location intelligence and map visualization tool that integrates with your Salesforce CRM, simplifying territory management. With Salesforce Maps you can create territories…
Popular Salesforce Infographics
Top Benefits of Integrating Salesforce and NetSuite
Salesforce, on the one hand, is the world’s number cloud-based CRM. NetSuite, on the other hand, is one of the best ERP systems. And when…
Explore The Salesforce Support Services Process Chart
This infographic helps you to explore the Salesforce Services process chart. Go through it and let me know in the comments in case of any…
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…