Posts

Overview of Salesforce Apex REST and SOAP APIs:

Salesforce provides two primary mechanisms for integrating with external systems: REST (Representational State Transfer) and SOAP (Simple Object Access Protocol) APIs. Both REST and SOAP APIs allow you to interact with Salesforce data and metadata programmatically, including querying, creating, updating, and deleting records. Here's an overview of Salesforce Apex REST and SOAP APIs: Apex REST (RESTful Web Services): Description: Apex REST allows you to expose custom RESTful web services within Salesforce. You can define custom REST endpoints using Apex classes and methods, which can then be invoked by external systems using HTTP requests. Usage: Apex REST is well-suited for building lightweight, stateless APIs that adhere to RESTful principles. It's commonly used for integrating with mobile applications, external web services, and other systems that communicate over HTTP. Authentication: Apex REST supports various authentication mechanisms, including OAuth 2.0, Session ID, and ...

Validate Salesforce User

Image
 Here's a piece of code to verify the password of a user.            HttpRequest request = new HttpRequest();         request.setEndpoint('https://login.salesforce.com/services/Soap/u/22.0');         request.setMethod('POST');         request.setHeader('Content-Type', 'text/xml;charset=UTF-8');         request.setHeader('SOAPAction', '""');         request.setBody( prepareSoapLoginRequest ('me_raja1@test.com','QW@232323'));         ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Info, String.valueOf(new Http().send(request).getBody())));  public static String  prepareSoapLoginRequest (String username, String password){         XmlStreamWriter w = new XmlStreamWriter();         w.writeStartElement('', 'login', 'urn:partner.soap.sforce.com');         w.w...

Salesforce Workflow Rules vs Process Builder

Process Builder and Workflow Rules are automation tools in Salesforce that allow users to automate business processes without writing code. While they serve similar purposes, there are differences in their capabilities and use cases.  Workflow Rules: Purpose: Workflow Rules are used to automate standard business processes in Salesforce. They allow you to define criteria and actions to be executed when records meet specified conditions. Capabilities: Criteria: You can define entry criteria based on record field values or related objects. Immediate Actions: Actions such as field updates, email alerts, outbound messages, task creation, and posting to Chatter can be triggered immediately when the criteria are met. Time-Dependent Actions: You can schedule time-dependent actions, such as email alerts or task creation, to occur after a specified period. No Rollbacks: Workflow Rules do not support record rollbacks if an error occurs during execution. Usage: Workflow Rules are suitable for ...

Pass by Value or Pass by Reference in Salesforce

Pass by Value: When you pass a primitive data type (such as Integer, Boolean, String) as an argument to a method, a copy of the value is passed to the method. Any changes made to the parameter within the method do not affect the original value of the variable passed in. This behavior is consistent with most programming languages and is commonly referred to as pass-by value. Example: public void incrementValue(Integer x) {     x++; // Changes made to 'x' do not affect the original value of the variable passed in } Integer value = 10; incrementValue(value); System.debug(value); // Output: 10 (unchanged) Pass by Reference (for non-primitive data types): When you pass a non-primitive data type (such as List, Map, Set, or custom objects) as an argument to a method, a reference to the original variable is passed to the method. This means that changes made to the parameter within the method can affect the original value of the variable passed in. However, assigning a new value to the...

Importing a CSV file using Apex and Visualforce

Here is an example of importing a CSV file using Apex and Visualforce. Depending on your requirements, you may need to enhance this solution with additional error handling, validation, and business logic. Visualforce Page- <apex:page controller="demoImportDataFromCSV">     <apex:form >         <apex:pagemessages />         <apex:pageBlock >             <apex:pageBlockSection columns="2">                    <apex:inputFile value="{!csvFileBody}"  filename="{!csvAsString}"/>                   <apex:commandButton value="Import Product" action="{!importCSVFile}"/>             </apex:pageBlockSection>         </apex:pageBlock>         <apex:pageBlock >           ...

Visualforce View State

Image
In Visualforce, view state refers to the state of the page, including the state of its form data, component values, and controller state, that is transmitted to and from the server with each request. View state enables Visualforce pages to maintain stateful behavior similar to traditional web applications, where user inputs and interactions are preserved across multiple requests. Optimize the View State View State Tab Steps to reduce the View State Use filters and pagination to reduce data that requires state. Declare an instance variable with a transient keyword if the variable is only useful for the current request. A transient variable isn’t included in the view state. Refine your SOQL calls to return only data that's relevant to the Visualforce page. Reduce the number of components that your page depends on. Make data read-only. Use the <apex:outputText> component instead of the <apex:inputField> component. Use JavaScript remoting. Unlike the <apex:actionFunction...

Retrieve current record id in salesforce

To get the current record ID in Salesforce Visualforce, you can use the Id parameter in the URL or leverage standard controllers. Here are two common methods to accomplish this: Using the Id Parameter in the URL: In Visualforce, you can access the current record's ID using the Id parameter in the URL. This method is commonly used when creating custom pages or links. <apex:page standardController="Account">     <h1> Account Record ID: {!$CurrentPage.parameters.Id}</h1> </apex:page> In this example, {!$CurrentPage.parameters.Id} retrieves the ID from the URL. Using Standard Controllers : If you're using a standard controller in your Visualforce page, you can directly reference the record ID using the Id property of the standard controller. <apex:page standardController="Account">     <h1>Record ID: {! Account.Id}</h1> </apex:page> In this example, {! Account.Id} retrieves the ID of the current record from the st...