Posts

Use the Developer Console to force password resets in Salesforce

Image
When using the Developer Console to force password resets for newly created users, the setPassword method of System Class may redirect users to the "Change Your Password" page. Clicking on any text box allows the user to log in to the org without setting the security questions.   Note: If you have used setPassword() to configure a user's password and they have never set a security question, they will be redirected to the Change Your Password page upon login. Steps to set a password  Open Developer Console Open the Execute anonymous window > Write : system.setPassword('005xx0000000XXX', 'passwordText');  i.e System.setPassword(userid, password); Click Execute Click on the gear icon below the screenshot and select ‘ Developer Console’ A new window will open - You need to click on Debug → Open execute Anonymous Window A new window will open, add the below command, and click on execute.  System.setPassword(userid, password);

Send PDF as attachment using Visualforce Page

Image
Usecase- Email a list of Account details as a pdf. Visualforce Page - <apex:page Controller="pdfasattachment" renderAs="{!if($CurrentPage.parameters.p == null, null, 'pdf')}" > <apex:pageBlock title="Hello {!$User.FirstName}!"> You are displaying contacts from the account  . Click a contacts name to view his or her details. </apex:pageBlock> <apex:pageBlock title="Contacts"> <apex:form > <apex:dataTable value="{!accounts}" var="contact" cellPadding="4" border="1"> <apex:column > <apex:commandLink rerender="detail"> {!contact.Name} <apex:param name="cid" value="{!contact.id}"/> </apex:commandLink> </apex:column> < <apex:column > <apex:commandLink rerender="detail"> {!contact.id} <apex:param name="cid" value="{!contact.id}"/> </apex:commandLink> </...

Passing Parameters from Visualforce Page to Apex Method

To pass parameters from a Visualforce page to an Apex method, you can use the <apex:param> tag within the component that invokes the method. To pass parameters from a Visualforce page to an Apex method, you can use the <apex:param> tag. This tag needs to be included within an <apex:actionFunction>, <apex:commandButton>, or <apex:commandLink> tag. The <apex:param> tag works by specifying a name-value pair, which is then sent to the server when the parent tag triggers an action. Method 1 Visualforce Page <apex:page standardController="Account" Controller="AccountController">  <apex:outputPanel id="main">   <apex:form>     <apex:pageBlock title="Account Detail">       <apex:pageBlockSection title="Account">         <apex:outputField value="{!Account.Name}"/>         <apex:outputField value="{!Account.Description}"/>       ...

S-Controls in Salesforce

Image
Use s-controls to add your own functionality to your Salesforce organization. Whether you are integrating a hosted application of your own or are extending your current Salesforce user interface, use s-controls to store your code or refer to code elsewhere. Custom s-controls can contain any type of content that you can display in a browser, for example a Java applet, an Active-X control, an Excel file, or a custom HTML Web form. Here're the steps to create a new S- Control The custom s-control library is a place where you can store and upload content for use in many areas within Salesforce such as, custom links, Web tabs, custom buttons, and dashboards. From Setup, enter S-Controls in the Quick Find box, then select S-Controls. To create a new custom s-control, click New Custom S-Control. To change an existing custom s-control, click Edit. Enter s-control attributes. To validate all Salesforce merge fields and functions, click Check Syntax. Click Save when you finish or click Quick...

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}"/>       ...