Wednesday, June 28, 2017

Tuesday, June 27, 2017

Links: Salesforce Developers Blog

Lightning

Building a Lightning Connect Proof of Concept
Communicating between Lightning Components and Visualforce Pages
Create your own Lightning Progress Bar
Create a Lightning Component for Drag-and-Drop Profile Pictures
Creating a Lightning Weather Component
Creating a Salesforce Lightning Map Component
Creating Lightning Components: Events and Messaging
Creating Loosely Coupled Components with the Lightning Component Framework and App Builder
danpeter's Blog Posts
Debugging Lightning Components
Extending Lightning Components by Example
Introducing the Salesforce Lightning Inspector
JavaScript Buttons, Lightning, and You: A Blog Series
Lightning Components Best Practices: Caching Data with Storable Actions
Lightning Inter-Component Communication Patterns
Loading External JavaScript And CSS Libraries To Lightning Components
LockerService and Lightning Container Component: Securely Using Third-Party Libraries in Lightning Components
Mass Update Leads Using the Lightning Component Framework
Mastering Salesforce Lightning Design System Grids and Lightning Layouts
Modularizing Code in Lightning Components
New Version of DreamHouse Packed with New Lightning Features
Salesforce Lightning inputLookup: the missing component
Summer ’17 Highlight: Diving Into Lightning Data Service
Understanding System Events In Lightning Components – Part 1
Understanding System Events In Lightning Components – Part 2


Data Model

Simplify Your Salesforce Data with Custom Metadata Type Relationships
Salesforce Data Security Model — Explained Visually
Introducing custom metadata types: the app configuration engine for Force.com
Integrating Multiple Orgs using the OAuth 2.0 SAML Bearer Assertion Flow


SOQL

SOQL for the SQL Developer
Basic SOQL Relationship Queries


Declarative Tools

Enhancing Workflows with The Weather Company Data service
Lightning Process Builder: Taking Point-and-Click Development to a New Level
Cross-Object Owner Fields: A Powerful New Formula Option
Lightning Process Builder Hot Topics: Q&A with Product Manager, Shelly Erceg


Lightning Training

https://www.salesforce.com/services-training/learnlightning.jsp
Creating Lightning Components: Single Page Applications


Apex

Trust, but Verify: Apex Metadata API and Security
Introducing the Apex Metadata API
Machine-to-Machine Salesforce Integrations in Java with REST and SOAP
Integrating With Salesforce Using Apex
Testing Apex Callouts using HttpCalloutMock
Force.com SOAP API Sample WSDL Structures
Avoiding Apex Speeding Tickets (Concurrent Request Limits via Synchronous Callouts)
Introducing Lightning Connect Custom Adapters
Queueable Apex: More Than an @future


Share This:    Facebook Twitter

Monday, June 19, 2017

Understanding __c and __r


I will use the Property__c and Broker__c sobjects. When a relationship is created between these two sobjects, the following fields are created in salesforce schema of these objects.

Property__c (child):
global Id Broker__c;
global Broker__c Broker__r;

Broker__c (parent):
global List<Property__c> Properties__r;

Upward traversal: get fields of parent object for a given child object


Downward traversal: get fields of child object for given parent object


Reference: http://11concepts.com/sfdc/blog/understanding-__c-and-__r/
Share This:    Facebook Twitter

Saturday, June 17, 2017

SOAP UI - TLS 1.0 has been disabled in this organization.Please use TLS 1.1 or higher when connecting to Salesforce using https

Solution:
Step 1: Navigate to C:\Program Files\SmartBear\SoapUI-5.3.0\bin folder.
Step 2: Edit SoapUI-5.2.1.vmoptions file with System admin permission in any text editor.
Step 3: Add following entry and save the file. It will only enable TLS 1.2 protocol.
-Dsoapui.https.protocols=TLSv1.2
Step 4: Close and Re-launch the Soap UI.
Share This:    Facebook Twitter

Creating SOAP Web Service in Apex

Create the apex class and generate its wsdl. Download Partner wsdl as well.
global class MathOperations
{
    webservice static Integer getSum (Integer a, Integer b)
    {
        return a + b;
    }
}

Convert the wsdl files that you have downloaded to jar files using the command below:
java -classpath force-wsc-40.1.1.jar;rhino-1.7.7.1.jar;ST-4.0.8.jar;C:\Java\jdk1.8.0_121\lib\tools.jar com.sforce.ws.tools.wsdlc partner.wsdl partner_stub.jar

Using SoapUI, get the sessionId from partner wsdl:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:partner.soap.sforce.com">
   <soapenv:Header>
   </soapenv:Header>
   <soapenv:Body>
      <urn:login>
         <urn:username>username</urn:username>
         <urn:password>password</urn:password>
      </urn:login>
   </soapenv:Body>
</soapenv:Envelope>


Enter the sessionId value in custom apex class wsdl. Check the below request and response:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mat="http://soap.sforce.com/schemas/class/MathOperations">
   <soapenv:Header>
      <mat:SessionHeader>
         <mat:sessionId>00D6A000001Vait!ARwAQPfREKhyBFwVu3F.vFEXYDvLIiR3w8K5hlZvemfv_vFPGECj.QLj3HXsOVFQzVb7OQAG.T9QFWqUzh5P0PP0rPhASOdo</mat:sessionId>
      </mat:SessionHeader>
   </soapenv:Header>
   <soapenv:Body>
      <mat:getSum>
         <mat:a>5</mat:a>
         <mat:b>8</mat:b>
      </mat:getSum>
   </soapenv:Body>
</soapenv:Envelope>




<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://soap.sforce.com/schemas/class/MathOperations">
   <soapenv:Body>
      <getSumResponse>
         <result>13</result>
      </getSumResponse>
   </soapenv:Body>
</soapenv:Envelope>



You can call this web service using Java like below:
package wsc;

import com.sforce.soap.MathOperations.Connector;
import com.sforce.soap.MathOperations.SoapConnection;
import com.sforce.soap.partner.PartnerConnection;
import com.sforce.ws.ConnectionException;
import com.sforce.ws.ConnectorConfig;

public class SalesforceSoapStarter {

    private static final String AUTH_ENDPOINT =  "https://login.salesforce.com/services/Soap/u/40.0";
    private static final String USERNAME = "username";
    private static final String PASSWORD = "password";

    public static void main(String[] args) throws ConnectionException {

     ConnectorConfig config = new ConnectorConfig();
        config.setUsername(USERNAME);
        config.setPassword(PASSWORD);
        config.setAuthEndpoint(AUTH_ENDPOINT);
        
        PartnerConnection connection = new PartnerConnection(config);

        String sessionId = config.getSessionId();
        
        SoapConnection soap = Connector.newConnection("","");
        soap.setSessionHeader(sessionId);
        System.out.println(soap.getSum(4, 9));
    }

}

Refer this link to set up Java developer environment:
https://developer.salesforce.com/docs/atlas.en-us.salesforce_developer_environment_tipsheet.meta/salesforce_developer_environment_tipsheet/salesforce_developer_environment_overview.htm
Share This:    Facebook Twitter

Tuesday, June 6, 2017

Foreground, setBackground, setStorable, setAbortable


There are some properties that you can set on a server-side action to influence how the framework manages the action while it’s in the queue waiting to be sent to the server.

Foreground and Background Actions

Foreground actions are the default. Multiple queued foreground actions are batched in a single request (XHR) to minimize network traffic. The batching of actions is also known as boxcar’ing, similar to a train that couples boxcars together. The server sends the XHR response to the client when all actions have been processed on the server. If a long-running action is in the boxcar, the XHR response is held until that long-running action completes. Marking an action as background results in that action being sent separately, which avoids it impacting the response time of the other actions.

To set an action as a background action, call the setBackground() method on the action object in JavaScript.

Storable Actions

Enhance your component’s performance by marking actions as storable to quickly show cached data from client-side storage without waiting for a server trip. If the cached data is stale, the framework retrieves the latest data from the server.
  • A storable action might result in no call to the server. Never mark as storable an action that updates or deletes data.
  • For storable actions in the cache, the framework returns the cached response immediately and also refreshes the data if it’s stale. Therefore, storable actions might have their callbacks invoked more than once: first with cached data, then with updated data from the server.
To mark a server-side action as storable, call setStorable() on the action in JavaScript code.

Abortable Actions

An abortable action in the queue is not sent to the server if the component that created the action is no longer valid, that is cmp.isValid() == false. A component is automatically destroyed and marked invalid by the framework when it is unrendered. Mark a server-side action as abortable by using the setAbortable() method on the Action object in JavaScript.

Mark a server-side action as abortable by using the setAbortable() method on the Action object in JavaScript.


Let's understand the scenarios using a sample application. Pressing the button under Foreground Action results in 1 batched action from 2 different actions (the 3rd entry), and is then sent to the server; while pressing the button under Background Action results in the action being sent separately (the 1st and 2nd entry) to the server.



Pressing the button under Storable Action for the first time results in one server trip (foreground action). Pressing the button again for couple of times doesn't result in any more server trips, displaying the same cached data from client-side storage as shown below.


Code for this application is provided below.

Share This:    Facebook Twitter

Monday, June 5, 2017

AuraHandledException

From Apex class:
    @AuraEnabled
    public static List<Account> fetchAccount() {
        throw new AuraHandledException('User-defined error');
    }

From client-side controller:
    doInit: function(component, event, helper) {
        var action = component.get('c.fetchAccount');
        action.setParams({ firstName : cmp.get("v.firstName") });
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                component.set('v.Accounts', response.getReturnValue());
            }
            else if (component.isValid() && state === "ERROR") {
                console.log("Error Message: ", response.getError()[0].message);
            }
        });
        $A.enqueueAction(action);
    }

Share This:    Facebook Twitter

Lightning Component Rendering LifeCycle

Rendering LifeCycle

1. The init event is fired by the component service that constructs the components to signal that initialization has completed.

2. For each component in the tree, the base implementation of render() or your custom renderer is called to start component rendering.

3. Once your components are rendered to the DOM, afterRender() is called to signal that rendering is completed for each of these component definitions.

4. To indicate that the client is done waiting for a response to the server request XHR, the aura:doneWaiting event is fired.

5. The framework fires a render event, enabling you to interact with the DOM tree after the framework’s rendering service has inserted DOM elements. Handling the render event is preferred to creating a custom renderer and overriding afterRender().

6. Finally, the aura:doneRendering event is fired at the end of the rendering lifecycle.

Salesforce doesn't recommend using the legacy aura:waiting, aura:doneWaiting, and aura:doneRendering application events except as a last resort. The aura:waiting and aura:doneWaiting application events are fired for every batched server request, even for requests from other components in your app.

References:
https://developer.salesforce.com/blogs/developer-relations/2015/06/understanding-system-events-lightning-components-part-1.html
https://developer.salesforce.com/blogs/developer-relations/2015/06/understanding-system-events-lightning-components-part-2.html

Share This:    Facebook Twitter

Sunday, June 4, 2017

Access SOQL data in Lightning component

public class AccountContactController {
    @AuraEnabled
    public static List<Account> fetchAccount() {
        List<Account> listOfAccounts = [SELECT Name, AnnualRevenue, BillingState, (SELECT LastName FROM contacts) FROM Account LIMIT 10];
        return listOfAccounts;
    }
}

<aura:component controller="AccountContactController">
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:attribute name="Accounts" type="Account[]"/>
    <ul>
        <aura:iteration items="{!v.Accounts}" var="account">
            <li>AccountName: {!account.Name}</li>
            <ul>
                <aura:iteration items="{!account.Contacts}" var="contact" indexVar="index">
                    <li>Contact {!index + 1} : {!contact.LastName}</li>
                </aura:iteration>
            </ul>
            <hr/>
        </aura:iteration>
    </ul>
</aura:component>

({
    doInit: function(component, event, helper) {
        var action = component.get('c.fetchAccount');
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                component.set('v.Accounts', response.getReturnValue());
            }
        });
        $A.enqueueAction(action);
    }
})

Share This:    Facebook Twitter

Access apex class properties in Lightning component

public class PersonController {
    @AuraEnabled public String Name {get;set;}
    @AuraEnabled public integer Age {get;set;}
    @auraEnabled public List<Account> ListOfAccounts {get;set;}
    
    @AuraEnabled
    public static PersonController initMethod(){
        PersonController person = new PersonController();
        person.Name = 'John Doe';
        person.Age = 30 ;
        person.ListOfAccounts = [SELECT Id, Name FROM Account LIMIT 10];
        return person ;
    }
}

Note the attribute personController of type PersonController.
<aura:component controller="PersonController">
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:attribute name="personController" type="PersonController"/>
    
    <div>
        Name: {!v.personController.Name}<br />
        Age: {!v.personController.Age}<br />
    </div>
    <div>
        List of Accounts:
        <aura:iteration items="{!v.personController.ListOfAccounts}" var="account">
            <li>{!account.Name}</li>
        </aura:iteration>
    </div>
</aura:component>

({
    doInit : function(component, event, helper) {
        var action = component.get('c.initMethod');
        action.setCallback(this,function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                component.set('v.personController', response.getReturnValue());
            }
        });
        $A.enqueueAction(action);
    },
})

Share This:    Facebook Twitter

Total Pageviews

My Social Profiles

View Sonal's profile on LinkedIn

Tags

__proto__ $Browser Access Grants Accessor properties Admin Ajax AllowsCallouts Apex Apex Map Apex Sharing AssignmentRuleHeader AsyncApexJob Asynchronous Auth Provider AWS Callbacks Connected app constructor Cookie CPU Time CSP Trusted Sites CSS Custom settings CustomLabels Data properties Database.Batchable Database.BatchableContext Database.query Describe Result Destructuring Dynamic Apex Dynamic SOQL Einstein Analytics enqueueJob Enterprise Territory Management Enumeration escapeSingleQuotes featured Flows geolocation getGlobalDescribe getOrgDefaults() getPicklistValues getRecordTypeId() getRecordTypeInfosByName() getURLParameters Google Maps Governor Limits hasOwnProperty() Heap Heap Size IIFE Immediately Invoked Function Expression Interview questions isCustom() Javascript Javascript Array jsForce Lightning Lightning Components Lightning Events lightning-record-edit-form lightning:combobox lightning:icon lightning:input lightning:select LockerService Lookup LWC Manual Sharing Map Modal Module Pattern Named Credentials NodeJS OAuth Object.freeze() Object.keys() Object.preventExtensions() Object.seal() Organization Wide Defaults Override PDF Reader Performance performance.now() Permission Sets Picklist Platform events Popup Postman Primitive Types Profiles Promise propertyIsEnumerable() prototype Query Selectivity Queueable Record types Reference Types Regex Regular Expressions Relationships Rest API Rest Operator Revealing Module Pattern Role Hierarchy Salesforce Salesforce Security Schema.DescribeFieldResult Schema.DescribeSObjectResult Schema.PicklistEntry Schema.SObjectField Schema.SObjectType Security Service Components Shadow DOM Sharing Sharing Rules Singleton Slots SOAP API SOAP Web Services SOQL SOQL injection Spread Operator Star Rating stripInaccessible svg svgIcon Synchronous this Token Triggers uiObjectInfoApi Upload Files VSCode Web Services XHR
Scroll To Top