Salesforce Visualforce Tutorial: Custom Controllers
HTML-код
- Опубликовано: 6 дек 2024
- In this video, we go over Custom Controllers.
Video on Visual Studio Code Dev Setup: • Salesforce Setup Visua...
Feel free to leave a comment if you have any questions and/or make a suggestion on what kind of video you would like to see next.
Subscribe and hit the notification bell if you find these videos useful.
Documentation: developer.sale...
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.
Actually good video, thank you
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];
}
}