You need to sign in to do that
Don't have an account?
JCompliance
Attempt to de-reference a null object - HELP
Greetings All -
I am getting the above error when trying to run the following code utilizing a VF Page Buton.
VF Page Code:
<apex:page standardController="Protocol_Arm__c" extensions="ProtocolScheduleClone" action="{!cloneWithItems}"> <apex:pageMessages /> </apex:page>
Class Code:
public class ProtocolScheduleClone { //added an instance varaible for the standard controller private ApexPages.StandardController controller {get; set;} // add the instance for the variables being passed by id on the url private Protocol_Arm__c pa {get;set;} // set the id of the record that is created public ID newRecordId {get;set;} // initialize the controller public ProtocolScheduleClone(ApexPages.StandardController controller) { //initialize the stanrdard controller this.controller = controller; // load the current record pa = (Protocol_Arm__c)controller.getRecord(); } // method called from the VF's action attribute to clone the po public PageReference cloneWithItems() { // setup the save point for rollback Savepoint sp = Database.setSavepoint(); Protocol_Arm__c newPA; try { //copy the protocol arm pa = [select Id, Name, Description__c, Protocol__c, Start_Date__c from Protocol_Arm__c where id = :pa.id]; newPA = pa.clone(false); insert newPA; // set the id of the new pa created for testing newRecordId = newPA.id; // copy over the line items List<Arm_Activity__c> items = new List<Arm_Activity__c>(); for (Arm_Activity__c aa : [Select aa.Id, aa.Activity_Type__c, aa.Description__c, aa.Protocol_Arm__c, aa.Originally_Scheduled_Date_Time__c, aa.Title__c From Arm_Activity__c aa where Protocol_Arm__c = :pa.id]) { Arm_Activity__c newARA = aa.clone(false); newARA.RecordType.Name = 'Actual'; newARA.Protocol_Arm__c = newPA.id; items.add(newARA); } insert items; } catch (Exception e){ // roll everything back in case of error Database.rollback(sp); ApexPages.addMessages(e); return null; } return new PageReference('/'+newPA.id+'/e?retURL=%2F'+newPA.id); } }
Any Help would be appreciated.
As far as I know, you can't set it by name.
Here is an example (was working, but modified for your name):
After this code, you can use RecordTypeID.id to get the id like this:
Hope this helps ...
All Answers
From the log, please tell us what line in your code is throwing this error
or
post the log ...
How can I export the log to display it?
First you will need to capture the log:
Hope this helps.
Thank you for that direction. I did however figure out the issue. In the line where I am attempting to insert the RecordType name, there are some additional issues I am having there. Without that line th code is solid. I will reply with what I find out on the issue.
Reply with the offending line of code and I will look at it . . . .
It is in this line that I am setting the record type:
As far as I know, you can't set it by name.
Here is an example (was working, but modified for your name):
After this code, you can use RecordTypeID.id to get the id like this:
Hope this helps ...
I understand the above code and why to use it, but I am not sure where to put it. My assumption is that it will not go into the For loop correct?
Figured it out! Thank you so much for your hepl!
No problem.
If you get bored, please check out my salesforce blog here.
If you like it and/or my posts helped you, you can always nominate me for MVP here. :smileyvery-happy: