-
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, 5 months ago by Pragya.
Log In to reply.
Popular Salesforce Blogs
Update Records Using Salesforce Flow | Salesforce Developer Guide
Go to Setup, enter flow in Quick Find then select Flows. Click on New Flow. From the template, select Screen Flow. Let's update the Annual…
Salesforce Customization vs. Configuration: Choosing the Right Approach
Unlocking the full potential of Salesforce can be a game-changer for your business. According to the Salesforce Relationship Survey, implementing Salesforce can supercharge your deal…
Popular Salesforce Videos
Accenture Salesforce Training 2022
This video is about -Accenture Salesforce Training 2022 Orientation session and ASE SFDC Salesforce Certification. As the trusted leader in Salesforce implementation and transformation, Accenture can…
How to Connect Salesforce Billing Payment Gateways (COMPILATION)
In this compilation, we’ll show you what you need to know about using your preferred payment gateway with Salesforce Billing + CPQ - like how…
Salesforce Summer 20 Dynamic Forms
Salesforce’s Summer ’20 Release Notes have now been published, we can now dive under the hood to see what the top features are! Historically, Summer…
Popular Salesforce Infographics
Take a look at the future of CPQ with this infographic!
Business-to-business sales, often referred to as simply B2B, used to be much less complex. But now, there is a lot that goes into these quotes…
9 Steps for Building a Useful Price Quote Template
Price quotes are among the most fundamental components of a sales unit’s library, yet too many sales managers treat quotes as a perfunctory measure that…
Top 10 Salesforce Consulting Companies in India
Salesforce is the leading cloud-based Customer Relationship Management (CRM) platform. It facilitates improving customer relationships by streamlining sales, marketing, and support processes for your business.…