-
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
How to Boost Your Business with a Salesforce Partner Company?
Are you looking to take your business to the next level? If so, consider leveraging the power of Salesforce, one of the world's leading customer…
Web to Lead Guide: All you Need to Know | Salesforce Guide
Are you still updating the new leads manually on Salesforce or your CRM? Is your Sales team occupied with tasks that are not that fruitful? Stop…
Top Secrets to Master Salesforce to Increase Business Growth
There are various advantages of using Salesforce for your business. It helps you grow significantly; for desired output, we suggest you take help from certified…
Popular Salesforce Videos
EPC and CPQ in Salesforce Industries (Vlocity)
Enterprise Product Catalog (EPC) to configure and manage CPQ in one place. It's a guided selling experience for users to build an order. While CPQ…
What is External ID and Why it is used in Salesforce?
This video has been divided into following points: What is an External ID in Salesforce? What is the use of External ID in Salesforce? How…
Getting to Know Einstein Analytics
Einstein Analytics is an app used to visualize the activity occurring in your Salesforce environment. Whether you use Salesforce for Sales, Marketing, or Service, this…
Popular Salesforce Infographics
The Best Salesforce Certifications to Look for in 2020
There is a whole bunch of salesforce certifications that are available for the professionals. These are administrators, developers, architects, marketers, app builders, consultants, etc. https://www.janbasktraining.com/blog/best-salesforce-certifications/
Welcome to the Internet of Customers | Salesforce Infographic
You’ve heard this age-old adage a thousand times: “The customer is always right.” Today more than ever, the customer has countless technologies and practices in…
Enhance Business Capabilities With Expert Salesforce AppExchange Development Services
Unlock the true potential of Salesforce AppExchange by hiring Concretio's expert and experienced team of developers. Leverage the power of AppExchange to empower your business.