function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
phantom1982phantom1982 

System.NullPointerException

The below code runs fine in testing environment, it's actually generating a PDF document.

 

 

public with sharing class PDFTransactionSlip {
public PDFTransactionSlip() {
}

public PDFTransactionSlip(ApexPages.StandardController controller) {
}

private String getXmlString(pb__Agreement__c c)
{
//datetime todayis = system.now();

double skcomdue = c.Buyer_Agency_Fee__c + c.Seller_Agency_Fee__c;
double premiumseller = c.pb__PurchaseListPrice__c - c.Inventory_Original_Price__c;
String s = '<?xml version="1.0" encoding="UTF-8"?>' +
'<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">' +
'<f href="https://na*.salesforce.com/resource/1298882850000/Transaction_Slip"/>' +
'<fields>' +
'<field name="Transaction_Type"><value>' + c.pb__AgreementType__c + '</value></field>' +
'<field name="Buyer_Type"><value>' + c.Buyer_Type__c + '</value></field>' +
'<field name="Buyer_Name"><value>' +c.Buyer_Name__c + '</value></field>' +
'<field name="Buyer_No"><value>' + c.Buyer_Phone_No__c + '</value></field>' +
'<field name="Buyer_Address"><value>' + c.Buyer_Address__c + '</value></field>' +
'<field name="Buyer_Pasport"><value>' + c.Buyer_Passport_No__c+ '</value></field>' +
'<field name="Buyer_Nationality"><value>' + c.pb__AccountRegistrationCountry__c + '</value></field>' +
'<field name="Seller_Type"><value>' + c.Seller_Type__c + '</value></field>' +
'<field name="Seller_Name"><value>' + c.pb__SellerFullName__c + '</value></field>' +
'<field name="Seller_No"><value>' + c.seller_Phone_no__c + '</value></field>' +
'<field name="Seller_Address"><value>' + c.Seller_Address__c + '</value></field>' +
'<field name="Seller_Pasport"><value>' + c.Seller_Passport_No__c + '</value></field>' +
'<field name="Seller_Nationality"><value>' + c.Seller_Country__c + '</value></field>' +
'<field name="Developer"><value>' + c.pb__DeveloperRegistrationNumber__c + '</value></field>' +
'<field name="PSA Date"><value>' + c.pb__AgreementDate__c + '</value></field>' +
'<field name="Unit_Details"><value>' + c.pb__UnitName__c + '</value></field>' +
'<field name="No_Of_Bedrooms"><value>' + c.pb__UnitBedrooms__c + '</value></field>' +
'<field name="Sqft"><value>' + c.pb__TotalAreaSqft__c + '</value></field>' +
'<field name="Built_Up"><value>' + c.pb__TotalAreaSqft__c + '</value></field>' +
'<field name="Original_Price"><value>' + c.Inventory_Original_Price__c + '</value></field>' +
'<field name="Net_Purchase_Price"><value>' + c.pb__PurchaseListPrice__c + '</value></field>' +
'<field name="Amount_Paid"><value>' + c.Amount_Paid_on_Property__c + '</value></field>' +
'<field name="Premium_Seller"><value>' + premiumseller + '</value></field>' +
'<field name="Deposit Amount"><value>' + c.Deposit_Amount__c + '</value></field>' +
'<field name="Transfer_Fee"><value>' + c.Transfer_Fee__c + '</value></field>' +
'<field name="Total_Purchase"><value>' + c.Total_Purchase_Price_AED__c + '</value></field>' +
'<field name="Buyer_Agency"><value>' + c.Buyer_Agency_Fee__c + '</value></field>' +
'<field name="Seller_Agency"><value>' + c.Seller_Agency_Fee__c + '</value></field>' +
'<field name="Conveyance_Fees"><value>' + c.Conveyance_Fees__c + '</value></field>' +
'<field name="SK_Commission_Due"><value>' + skcomdue + '</value></field>' +
'<field name="Total_Commission"><value>' + skcomdue+ '</value></field>' +
'</fields><ids original="6CF3C495DE77414F85BC24E6CFC3F692" modified="EF5CB2FB7A5BAA4FB634933ADC944031"/>' +
'</xfdf>';

return s;
}

public PageReference XFDFInit()
{
LIST<pb__Agreement__c> c = [Select Agreed_Price__c,pb__AgreementType__c,
pb__AccountRegistrationCountry__c , Amount_Paid_on_Property__c, Buyer_Agency_Fee__c,
Buyer_Conveyance_Fee__c,Buyer_Phone_No__c, Buyer_Address__c, Buyer_Passport_No__c,
Buyer_Type__c, Cheque_Data__c, Conveyance_Fees__c,
Deposit_Amount__c,Buyer_Name__c, Deposit_Status__c, Id, Initial_Term_SKadded__c,
Inventor_Title_No__c, Inventory_Completion_Status__c, Inventory_Original_Price__c,
Landlord_Commision__c, Mortgage_Discharge_Fee__c, Mortgage_Registration_Fee__c,
Name, Net_Achievable_Price_to_Seller1__c, NOC_Fee_to_Developer__c,
Number_of_Cheques_Required__c, pb__AccountId__c, pb__DeveloperId__c,
pb__DeveloperRegistrationNumber__c, pb__DownPaymentsComplete__c,
pb__FeesComplete__c, pb__InventoryId__c, pb__ItemCompletionStatus__c,
pb__OfferId__c,seller_phone_no__c, pb__PurchaseListPrice__c, pb__PurchasePrice__c,
pb__SellerFullName__c, pb__SellerId__c, pb__Status__c, pb__TotalAmount__c,
pb__TotalAreaSqft__c, pb__TotalAreaSqm__c, pb__UnitBedrooms__c,
pb__UnitFloorNumber__c, pb__UnitName__c, pb__UnitType__c,
Seller_Address__c, Seller_Agency_Fee__c, Seller_Conveyance_Fee__c,
Seller_Country__c, pb__AgreementDate__c , Seller_Passport_No__c, Seller_Type__c,
Service_Maintenance_Fee_Pro_rata__c, Tenant_Commission__c,
Title_Deed__c, Total_Purchase_Price_AED__c, Transfer_Date__c,
Transfer_Fee__c, Unit_Number__c from pb__Agreement__c
WHERE id = :ApexPages.currentPage().getParameters().get('id') limit 1];





if(c.size() > 0){
pb__Agreement__c nc = c[0];
String xmlContent = getXmlString(nc);
Attachment attachment = new Attachment();
attachment.Body = Blob.valueOf(xmlContent);
attachment.Name = 'Transaction_Slip_' + c[0].Name + '_' + System.now() + '.XFDF';
attachment.ParentId = c[0].Id;
insert attachment;
PageReference contactPage = new PageReference('/' + c[0].id);
contactPage.setRedirect(true);
return contactPage;
}
PageReference contactPage = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
contactPage.setRedirect(true);
return contactPage;
}
}

 

Problem is when try to execute it in production, it gives the following exception:

 


System.NullPointerException: Attempt to de-reference a null object

Class.PDFTransactionSlip.getXmlString: line 12, column 26 Class.PDFTransactionSlip.XFDFInit: line 85, column 29 External entry point

 

 

Best Answer chosen by Admin (Salesforce Developers) 
phantom1982phantom1982

Resolved. the value was missing for the variable at line 12.