-
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 6 years, 2 months ago by
Pragya.
-
This discussion was modified 6 years, 2 months ago by
Log In to reply.
Popular Salesforce Blogs
No Code Tableau and Salesforce Integration
No Code Salesforce integrations are the best way to seamlessly integrate various software and platforms to boost productivity and enhance overall performance. With the new…
5 Exclusive Reason of Hiring Salesforce Consulting Services to Get Instant Popularity Among Enterprises
Cloud computing systems that have a major influence on the field of online business have dominated the recent period. And Salesforce makes good use of…
360 SMS App vs. Twilio: Salesforce Integration Showdown
Companies encounter a major trade-off whenever deciding to incorporate texting into Salesforce: they need to either opt to use a native texting program, such as…
Popular Salesforce Videos
Is Salesforce A Good Career Path?
Join this useful group for Salesforce job & career info: https://tinyurl.com/TelegramIntelogik Contact us for any Salesforce career guidance. Watch this video and learn. do let…
How to Reference Custom Metadata Types to Optimize Salesforce Account Records Using Salesforce Flow
Salesforce Account Region Allocation using Custom Metadata Types and Salesforce Flow This video walks through an example of how you can reference Custom metadata Types…
Accenture + Salesforce: Making an Impact
Our people and communities are important connection points for support. Hear more from our Salesforce professionals. Check out this video to learn everything you need…
Popular Salesforce Infographics
Salesforce Field Service: Power Up Your Field Operations
Salesforce Field Service, commonly known as Field Service Lightning (FSL), is the extension of Service Cloud that provides a unified view of workforce management. In…
How to Navigate a Successful Salesforce Implementation
There are many ways to navigate a Salesforce implementation. Check out this infographic to learn how to do it successfully.
How Artificial Intelligence Helps Sales Teams
AI is built into many different CRM software and platforms including Salesforce. In particular, Salesforce uses its proprietary Einstein AI. It helps companies find unexpected…