Practice Exams:

CRT-450 Salesforce Certified Platform Developer – User Interface – 25% Part 3

  1. 3.17- Standard vs Custom Controller vs Controller Extension

Hey, guys. This is section three, logic and Process Automation. And this is lecture number 17, standard versus Custom Controller versus Controller Extension. And this lecture will talk about the use case of each one of these. First of all, as opposed to a static page, a controller is required to show your data on a Salesforce page. So we cannot show any data, any salesforce data on the page without using a controller. All controllers are Apex classes. They can be either standard Apex classes that come with the system, or they can also be custom Apex classes that are made by you. You can also extend the functionality of any one of these using an extension class. So we have three types of controllers. We have the standard controllers which use standard Apex classes.

We have custom controllers which use custom Apex classes, and then we have control extensions which are just extensions of the standard or of the custom controllers. First of all, let’s start with standard controllers. These are mainly used on the standard pages of Salesforce. So let’s say when you click on an opportunity, on an account, on a custom object and so on, you are mainly using the standard controller. These are mainly used for a page that is accessing standard data and using standard behavior. Standard data means either a single record or a multiple records of the same object. And standard behavior means the same buttons that are used in the system, the same action buttons edit, save, cancel, and so on. How to create them? We cannot do that as they are provided by default by the system. How we can reference them? We can do so on the VF page by using an attribute and the Apex page component. Do we need to write any Apex code? We don’t need to do anything because these are provided by default by Salesforce. Our button actions defined all buttons.

Actions are defined and we cannot change them. And finally, are they available for both standard and custom objects? Yes, indeed. They are available whenever you create a custom object and for all standard objects. Now, what’s the use case of standard controllers? We use these in a page with a single record using standard action buttons. We use these in a page with multiple records of the same objects using the standard action buttons. We use these when we only require standard behavior action buttons as opposed to custom ones. And finally, standard controllers run in user mode, so the user who runs a VF page with a standard controller can only see his own records. Now, let’s talk about custom controllers. These are used in a page that is accessing custom data and possibly using custom behaviors. Custom data means any data from any Salesforce object in your Salesforce. org. It can be any object. It should not be even related. And custom behavior means that you can create any button that you want, you can create any action that you want and you are not limited to the standard ones.

Now, how we can create these? We have to create a new Apex class with the same name as the custom controller name. How we can reference them? We can do so on the Apex page component by using an attribute. Do we need to use Apex here? Yes, absolutely. We need to code everything, absolutely everything from scratch, every get method, every set method, every action method and so on. And we cannot use any standard data and behavior method. Our button action defined nothing is defined by default in the custom controller. So we need to code everything, including the action button code. And finally, are they available for standard and for custom objects? Well, custom controls are not related to any object. Now, what’s the use case of a custom controller? We use custom controllers whenever we require nonstandard behavior in our pages. For example, when we need multiple unrelated object records on the same page, when we need custom buttons, behavior on the page and so on, we have to use custom controllers.

And finally we’ll talk about controller extensions. These are just extensions for either standard or for custom controllers. So they extend the behavior and the functionality of either a standard controller or a custom controller. We use these when we need more custom data on top of the data that is provided by the main controller. And we also use these when we need more custom behavior on top of the behavior that is provided by the main controller. How do we create these? We create a new Apex class that contains a constructor that takes a single argument of type Apex Pages standard controller or of type custom controller name. So it can be either one of these two types. How we can reference them? We can reference them in the Apex page component by using the extension attribute. Do we need to use Apex here a little bit? Yes. Not as much as a custom controller. We just need to code the extra things that we need in the extension. Our button action defined, it depends on the main controller. So if the main controller defines button actions, they will be defined. If not, we need to provide these in the controller extension. And finally, can we use these in standard and custom objects while custom controllers are not related to any object?

Now, what’s the use case of a controller extension? Well, if you want to keep the use of a specific controller, be it standard or custom controller, but you want to extend it, you have to use a controller extension. Controller extensions can be used with either a standard or a custom controller. You can use more than one extension on a single standard or custom controller. And note that controller extension security depends on the extending controller, which is the main controller. So if the main controller is a standard controller, the extension will run in user mode. If it is a custom controller, the extension will run in system mode. And you can change this behavior by specifying the with sharing or the without sharing keywords and the class definition of the extension. So that’s it for this lecture. And this lecture we have learned what’s the use case of a standard controller, of a custom controller and of a controller extension. And finally, as usual, thanks for watching.

  1. 4.2- Web Content in Visualforce

Hey guys, this is section four user interface and this is lecture number two web content and VisualForce. And this lecture will talk about web contents. What web contents can we add to a VisualForce page? How we can do that? And finally we’ll jump into salesforce and we will show you that in action different contents can be added to a visual force post page. So as we have seen in the previous lecture we can add data from our salesforce. org but on top of that we can also add web contents. To upload contents to a VisualForce page we have to use static resources. Static resources allow you to upload content and that you can reference in a VisualForce page. These contents include archives like zip files, like jar files, images, CSS files and JavaScript files. Static resources are the means in which web contents can be added to a VisualForce page. Static resources are referenced using the dollar resource global variable and to reference the static resources and a VisualForce page we have to use these tags.

To reference an image file we have to use the image component with the URL attribute that points to the static resource itself. To reference a JavaScript file we have to use the include script component with the value attribute. To reference an image file in an archive we have to use the same image component with the same attribute. But we have to change the value of this. And to reference sess file in an archive we use the style sheet component with the value attribute. To be able to use the static resources in VisualForce we have to first upload them into salesforce.

To upload them we have to go to the static page and then we have to go to the static resources link and there we can choose the file that we want and the name of the static resource. What’s really nice is that you can edit the static resource and you can update it from the setup page without having to change and to touch anything on the VisualForce page because the static resource reference will handle this. And the VisualForce page, we have a reference to the static resource.

And this reference should not change. What can change? As the content of the static resource? Let’s now jump into salesforce and let me show you some static resources and let me use these and some VisualForce pages. So we will go to salesforce, we’ll go to the setup menu and first let’s upload a static resource. We have to go to the static resources link and let’s upload an image. To do so we’ll click on you and let me call this ACC image. I will also choose a file and I will make this public and save. Now I can reference this static resource ATC image in my VisualForce page and let’s say if I need to change this in the future I need to change the image.

I don’t touch anything on the VisualForce page. I just come here and I change this. Let’s now reference this on the VisualForce page. I will first copy this and we will go to the page. So this is the page. Let’s add an image before the block itself. So we will add it here, and for that we’ll use the component image and we will specify the attribute URL. And this will link to the static resource. So I will use the curly brackets and explanation mark. And then I will use the variable dollar resource. And then I will specify the name of the static resource. Now let’s save this and let’s see what will happen. There you go. So now we have an image on the page. I can also add more. I can add JavaScript, I can add CSS files and so on. And of course I can change this. I can put this in the middle. I can put it anywhere that I want on the VisualForce page. So that’s it for this lecture. In this lecture you have learned what are web contents, what are static resources, and how we can upload static resources into salesforce. And finally, how we can reference these static resources into our VisualForce pages. And finally, as usual, thanks for watching.

  1. 4.3- Incorporate Visualforce Pages into Lightning Platform applications

Hey guys. This is section four user interface. And this is a lecture number three incorporated VisualForce pages into force. Up until now, we have created some VisualForce pages or some VF pages. And this lecture will talk about how we can use these pages into Salesforce, where we can have them, where we can display them and how we can access them. The first place days where we can access a VF page is from a tab. We can add a custom tab to our and Salesforce and then when we click on this tab, the VF page will display. We can also access a VF page within a standard page layout. This will extend the page layout by displaying completely custom content on the standard page. As we can see here, we have an account page. This is the standard page layout of the account. We can have a section that will display a VF page. And to embed a VF page into a page layout, the VF page should be using the same standard controller as the page itself. So if this is an account a page, the VF page in this page that is embedded in this page should be using the account standard controller. And we have to modify the page layout, we have to add a section and then we have to choose the VF page to be displayed in this section. This is the way how we can access a VF page within a standard page layout. We can also access a VF page by clicking on a button or on a link.

The first way is to override the standard buttons or links in a page. So if you have, let’s say, an account page, the account page has many buttons and it has many links. We can edit these and instead of showing the normal content, it will show the VF page. The second way is to use the new custom buttons or new custom links. So instead of overriding the standard features of your salesforce page, let’s say, of the account page, we can add the new features to them. We can add the new buttons, we can add a new links, and then we can specify that by clicking this button or by clicking on that link, the VF page will display. And finally, we can link directly to a VF page. Every VisualForce page has a unique URL. We can take this, we can copy this and we can use it in other applications, in emails, we can embed it in documents and so on.

Let me now go to Salesforce and let me show you these in action. We will go to the setup page and then we will search for VisualForce pages. And up until now, we have four pages. Let me show them to you. So first we have this page that we have made in the previous lecture. This page uses a standard list controller and then offline I did this. This page uses a standard controller on the Account object. So what we’ll do, the first step, I will create a tab and then I will access a VF page. From this tab, I will go to the tab link and then I will go to the VisualForce tabs and click on you. So the VF page will be this one. The tab label will be let’s call this list of accounts.

And then this is the API name. And you would choose a tab style. Let me choose anyone. Now, just for the sake of showing you this. And next I will allow this on each one of the profiles. And then I will only include this in the, let’s say, Sales cloud app and Save. So this is the first way to display AVF page. We have created the tab and this tab contains AVF page. Now let me show you this tab. I’m now in the sales application and this is the list of Account tab. So if I click on this, let me first add it to my main page and I will have it next to Account. So now if I click on Save, it will show here. So there you go. Let me click on this. And there you go. We have the VF page displaying.

So this is the first way that we can use to display a VF page into our salesforce. org. And now let me add a new custom button or link on the Account object. To do that we will go to the setup page and then I will go to the Account object and I will go to the buttons, links and actions. I can edit any one of that. So if let’s say you want to edit this button, I can edit it and instead of showing the standard view, I will make it show the VF page. I will not do that. I will add a new button. Let me call this ACC account name and type. And this it will do what? It will be a button and it will display a VF page. And this VF page is VF page two. Now I will click on save. Now I will go to the page layout of the Account object and I will edit the default one. So I will go to the button sections. And as you can see here, I have the display name, a type button, and it’s being used by the layout.

I will go down to check this. There you go. I have it already under Account detail. Let me Save and I will go to the Account page to check this button. I will open any account and as you can see, I have the button. If I click on this button, the VF page two will display. There you go. Of course this is just an example. It’s just a simple example. You can have other VF pages displayed. Now, I can also have a VF page that displays within this standard account page. So instead of clicking on this link, I want the content of this VF page to be displayed inside this standard account page. Let’s do that. For that I will go to the setup page and I will go to the account object and then to the page layouts I will add the same one. And now I will create a new section. So let’s add this section at the end. Let me call this VF page section. And now inside this section I can add a VF page. How to do that we have to go to the VF page components here and I will add this guy.

So I will drag and drop this into this section, or I can also add it in any one of the other sections save. And now let me go back to an account record and I will scroll down and see I have the VF page section and it is displaying the content of the VF page itself. So now I have here a button that will display this content and also I can do the same, but this time it will be inside the VF page. And finally I can use the VF page URL directly into any application. So let’s say this is the VF page. I can copy the link and I can use this link. Let me cut this and let me open a new tab and I will paste and there you go. So now by using this URL, I have direct access to the VF page. I can use this URL in any application and emails and documents and so on.

So this is also a way to access a VF page in salesforce. I will go back to the slides. These are the different ways we can access and we can display our VisualForce pages. First of all, we can do so from a tab. We can create a tab and then when we click on this app, the VF page will display. We can do so within a standard page layout. So we can add a section inside a standard page layout where it will show a visual force page. We can edit standard buttons or standard links to point to visual force pages, or we can make new custom buttons or new custom links to point to visual force pages. And finally we can link directly to a visual force page by using S URL. So we can use this URL and different applications and email and documents and so on. And finally, as usual, thanks for watching.