Regarding the error starting at 23:28, the code change we made is actually irrelevant to this issue. I meant to clarify this point later on in the video but I forgot. If we had kept the code as is but instantiated the variables in the constructor, the page would've saved successfully but the contact would not be associated to the account. Everything I said regarding Salesforce assigning record after inserting the record is true. This "Attempt to de-reference a null object" error is exclusively because we had not instantiated the variables.
Yes. You can do something like: public class MyCustomController { // Make sure to define the type of custom object in the variable definition here public customObject customObject0__c customObject0 {get; set;} public List customObject1List {get; set;} public List customObject2List {get; set;} // Initialize variables in constructor public MyCustomController() { //Create new instance of a custom object customObject0 = new customObject0__c(); // Query custom object records customObject1List = [SELECT Id, Name, Field1__c FROM CustomObject1__c]; customObject2List = [SELECT Id, Name, Field2__c FROM CustomObject2__c]; } }
Actually good video, thank you
Regarding the error starting at 23:28, the code change we made is actually irrelevant to this issue. I meant to clarify this point later on in the video but I forgot. If we had kept the code as is but instantiated the variables in the constructor, the page would've saved successfully but the contact would not be associated to the account. Everything I said regarding Salesforce assigning record after inserting the record is true. This "Attempt to de-reference a null object" error is exclusively because we had not instantiated the variables.
make a playlist on lwc
Working on it!
Can I create controller which include more custom objects?
Yes. You can do something like:
public class MyCustomController {
// Make sure to define the type of custom object in the variable definition here
public customObject customObject0__c customObject0 {get; set;}
public List customObject1List {get; set;}
public List customObject2List {get; set;}
// Initialize variables in constructor
public MyCustomController() {
//Create new instance of a custom object
customObject0 = new customObject0__c();
// Query custom object records
customObject1List = [SELECT Id, Name, Field1__c FROM CustomObject1__c];
customObject2List = [SELECT Id, Name, Field2__c FROM CustomObject2__c];
}
}