Posts

Showing posts with the label Controller

Example of an Aura component in Salesforce

Here's an example to display a list of contacts related to an account and add new contacts and update existing ones. <!-- ContactList.cmp --> <aura:component controller="ContactController">     <aura:attribute name="accountId" type="String" />     <aura:attribute name="contacts" type="List" />     <aura:handler name="init" value="{!this}" action="{!c.init}" />     <ul>         <aura:iteration items="{!v.contacts}" var="contact">             <li>{!contact.Name}</li>         </aura:iteration>     </ul> </aura:component> ========================================================================== // ContactController.cls public with sharing class ContactController {     @AuraEnabled     public static List<Contact> getContacts(String accountId) {         retu...

Aura components in Salesforce

Aura Components  Aura components are the self-contained and reusable units of an app. They represent a reusable section of the UI, and can range in granularity from a single line of text to an entire app. The framework includes a set of prebuilt components. For example, components that come with the Lightning Design System styling are available in the lightning namespace. These components are also known as the base Lightning components. You can assemble and configure components to form new components in an app. Components are rendered to produce HTML DOM elements within the browser. A component can contain other components, as well as HTML, CSS, JavaScript, or any other Web-enabled code. This enables you to build apps with sophisticated UIs. The details of a component's implementation are encapsulated. This allows the consumer of a component to focus on building their app, while the component author can innovate and make changes without breaking consumers. You configure components ...

Display error messages with different severity levels in a Visualforce page

Image
To display error messages with different severity levels in a Visualforce page using ApexPages.addMessage, you can follow the same approach as before but with different severity levels. Here's how you can add messages with different severity levels and display them in a Visualforce page: Add Messages with Different Severities in Apex Controller: In your Apex controller, add error messages with different severity levels using ApexPages.addMessage. public class MyController {     public void someAction() {         try {             // Perform some action             if (someCondition) {                 // Add error message with severity                 ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'An error occurred: Some error message'));             } else if (another...

Working with Large Sets of Data

Visualforce custom controllers and controller extensions are subject to Apex governor limits. For more information about governor limits, see Execution Governors and Limits . Additionally, Visualforce iteration components, such as <apex:pageBlockTable> and <apex:repeat>, are limited to a maximum of 1,000 items in the collection they iterate over. Sometimes your Visualforce pages may need to work with or display larger sets of data, but not need to make modifications to that data; for example, if you are providing custom reporting and analytics. Visualforce offers developers a “read-only mode”, which relaxes the limit on the number of rows which can be queried in one request, and increases the limit on the number of collection items which can be iterated over within the page. You can specify read-only mode either for an entire page or, with certain limitations, on individual components or methods. Note - You can only iterate over large sets of data if you specify read-only ...

Rendering PDF Files Using Visualforce Page

Rendering PDF files using a Visualforce page in Salesforce is a common requirement, especially when you need to generate printable documents such as reports, invoices, or statements. Salesforce provides a way to generate PDF files directly from Visualforce pages using the renderAs attribute.    Visualforce <apex:page controller="PDFRenderingController" renderAs="pdf">   <apex:form >     <apex:pageBlock >         <apex:pageBlockTable value="{!accList}" var="acc" border="2">            <apex:column value="{!acc.Name}"/>            <apex:column value="{!acc.AnnualRevenue}"/>            <apex:column value="{!acc.Type}"/>            <apex:column value="{!acc.AccountNumber}"/>            <apex:column value="{!acc.Rating}"/>       ...

Wrapper Class in Apex Salesforce

A wrapper class in Salesforce Apex is a custom class that allows you to combine different types of data into a single object. It's particularly useful when you need to work with complex data structures or display multiple pieces of information in a Visualforce page.  Wrapper classes are commonly used in scenarios like: Visualforce Pages : You can use wrapper classes to display data from multiple related objects in a single table or form on a Visualforce page. Apex Controllers : Wrapper classes can be used to pass complex data structures between Apex controllers and Visualforce pages. Lightning Components : In Lightning development, wrapper classes are often used to format data for display in Lightning components or to simplify the structure of data passed between components. Integration : When working with external systems or APIs, wrapper classes can help structure data in a way that's easier to work with in Apex code. Here's an example of how you can use a wrapper class w...

Dynamic Menu Using JDock

Image
Show Sleek and Dynamic Menu on the Visualforce Page. jqdock is a jQuery plugin inspired by Mac .jqdock is a jQuery plugin inspired by Mac Dock Menu. jqDock   Visualforce Page <apex:page sidebar="false" showHeader="false" controller="JqueryController">  <head>    <style> bPageHeader{       display:none;   }   .heading{       background-color:#ccc;       text-align:center;   }   .data table,td,th {       border:1px solid #000;   }   </style>  <apex:includeScript value="{!$Resource.jquery}"/>  <apex:includeScript value="{!$Resource.jqDock}"/>   <style type='text/css'>  /*position and hide the menu initially - leave room for menu items to expand...*/ #page {padding-top:150px; padding-bottom:20px; width:100%;} #menu {position:absolute; top:0; left:0; width:100%; display:none;} /*dock styling...*/ /*...centre the dock...*/ ...

Floating Menu on Visualforce Page

Image
Here's an example to create a floating menu. <apex:page > <html> <body> <style> div.floating-menu {position:fixed;background:#fff4c8;border:1px solid #ffcc00;width:150px;z-index:100;} div.floating-menu a, div.floating-menu h3 {display:block;margin:0 0.5em;} </style> <div class="floating-menu"> <h3>Floating Menu</h3> <a href="http://www.quackit.com/css/">CSS</a> <a href="http://www.quackit.com/html/">HTML</a> <a href="http://www.quackit.com/javascript/">JavaScript</a> <a href="http://www.quackit.com/coldfusion/">ColdFusion</a> <a href="http://www.quackit.com/myspace/codes/">MySpace Codes</a> </div> </body> </html> </apex:page> 

What Is Standard Controller In Visualforce?

In Visualforce, a standard controller is a pre-built Apex controller provided by Salesforce that allows developers to work with standard database objects (such as records from Salesforce objects like Account, Contact, Opportunity, etc.) without having to write custom Apex code. Standard controllers provide basic CRUD (Create, Read, Update, Delete) operations and other standard functionality for interacting with these objects in Visualforce pages. When using a standard controller in Visualforce, you can directly reference fields and perform operations like saving records without explicitly writing Apex code. Standard controllers also handle security and access permissions automatically, ensuring that users only have access to the records they are authorized to view or modify. Here's a basic example of using a standard controller in Visualforce: <apex:page standardController="Account">     <apex:form>         <apex:inputField value="{!Account.N...

What Is Standard List Controllers In Visualforce?

Standard List Controllers in Visualforce provide developers with a way to display lists of records from standard or custom Salesforce objects without the need for writing Apex code explicitly. These controllers come pre-built with basic functionality for navigating, filtering, and working with collections of records. Here are some key points about Standard List Controllers: Built-in CRUD Operations: Standard List Controllers provide basic CRUD operations (Create, Read, Update, Delete) out-of-the-box, allowing users to view, edit, and delete records directly from Visualforce pages without writing custom Apex code. Automatic Pagination: When displaying a large set of records, Standard List Controllers automatically handle pagination, splitting the records into manageable chunks and providing navigation controls for users to navigate between pages. Sorting and Filtering: Standard List Controllers offer built-in support for sorting and filtering records based on various criteria, such as f...

What is Visualforce Controllers ?

A Visualforce controller is a set of instructions for what happens when a user interacts with components specified in associated Visualforce markup. One type of interaction is when a user clicks a button or link. Controllers also provide access to the data displayed in a page, and can modify component behavior. A developer can either use a standard controller provided by Lightning Platform, or add custom controller logic with a class written in Apex: A standard controller consists of the same functionality and logic that is used for a standard Salesforce page. For example, if you use the standard Accounts controller, clicking a Save button in a Visualforce page results in the same behavior as clicking Save on a standard Account edit page. If you use a standard controller on a page and the user doesn't have access to the object, the page displays an insufficient privileges error message. Resolve this error by checking the user's accessibility for an object and displaying compo...