Friday, 8 December 2017

Lightning Notes

force:appHostable --> Custom Tab
flexipage:availableForAllPageTypes --> Makes your component available for record pages and any other type of page, including a Lightning app’s utility bar.
flexipage:availableForRecordHome --> If your component is designed for record pages only, implement this interface instead of flexipage:availableForAllPageTypes.
force:hasRecordId -->  Add the force:hasRecordId interface to a Lightning component to enable the component to be assigned the ID of the current record.
forceCommunity:availableForAllPageTypes --> To appear in the Community Builder, a component must implement the forceCommunity:availableForAllPageTypes interface.
force:lightningQuickAction --> to a Lightning component to enable it to be used as a custom action in Lightning Experience or the Salesforce mobile app.
--------------------------
access = "global" --> To use it outside of the component name space.
-------------------------------

There are three ways of inserting a style sheet:

Inline style --> not supported in lightning compnent
Internal style sheet --> style resource
External style sheet --> <ltng:require styles="{!$Resource.***resourceName***}" />

The element Selector
---------------------
p {
    text-align: center;
    color: red;
}

The id Selector
----------------
#para1 {
    text-align: center;
    color: red;
}

The class Selector
------------------
.center {
    text-align: center;
    color: red;
}

specify that only specific HTML elements should be affected by a class
---------------------------
p.center {
    text-align: center;
    color: red;
}

p.large {
    font-size: 300%;
}

<p class="center large">This paragraph will be red, center-aligned, and in a large font-size.</p>

Grouping Selectors
---------------------
h1, h2, p {
    text-align: center;
    color: red;
}

CSS Comments
----------------
p {
    color: red;
    /* This is a single-line comment */
    text-align: center;
}

/* This is
a multi-line
comment */


---------------

Difference between lightning:button & ui:button
-----------
If you go thru the Lightning base components release notes, you will notice that the Base components are more of an extended implementation of the existing UI components.

here's an extract of the related section

You can find base Lightning components in the lightning namespace to complement the existing ui namespace components. In instances where there are matching ui and lightning namespace components, we recommend that you use the lightning namespace component. The lightning namespace components are optimized for common use cases. Beyond being equipped with the Lightning Design System styling, they handle accessibility, real-time interaction, and enhanced error messages.

Over a period, the base components will have more features built into it which can be easily configured / controlled by additional attributes.

---------------------
JavaScript Basics
=================
<script>
var person = {
    firstName: "John",
    lastName : "Doe",
    id       : 5566,
    fullName : function() {
       return this.firstName + " " + this.lastName;
    }
};

document.getElementById("demo").innerHTML = person.fullName();
</script>

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.shift();            // Removes the first element "Banana" from fruits

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.pop();              // Removes the last element ("Mango") from fruits

Understanding JavaScript Controllers Versus Helpers In Lightning Components
https://developer.salesforce.com/blogs/developer-relations/2015/06/understanding-javascript-controllers-versus-helpers-lightning-components.html

https://developer.salesforce.com/blogs/author/rraodv


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

Loading External JavaScript And CSS Libraries To Lightning Components -
https://developer.salesforce.com/blogs/developer-relations/2015/05/loading-external-js-css-libraries-lightning-components.html

Friday, 9 June 2017

Displaying text in td cell in multiple lines Salesforce

TD text value in multiple lines -


<apex:page > <apex:form> <table> <tr><td>     <div id="myDiv"/>     </td></tr>     </table>        <apex:commandButton onclick="myFunction();" value="NextLine" reRender="dummy"/>     <apex:outputPanel id="dummy"/>     </apex:form>     <script>         function myFunction() {             document.getElementById('myDiv').innerHTML='<apex:outputText escape="false" value="{!$Label.sample}"/>';             //$Label.sample -->This is <strong><font color="#FF0000"></font></strong> Test Label111 <br/> second Line             alert('hi');         }     </script> </apex:page>

Result:

Saturday, 20 February 2016

Spring '16 Important Features


  1. 1.     Platform Security Health Check
    Spring ’16 provides an interesting new security Health Check feature that enables the current org configuration to be compared against a Salesforce recommended baseline. Any feature that highlights security risk or vulnerability is positive addition and should help mitigate against complacency.
    2.     Lightning Experience – Person Account Compatibility (Beta) enabled
    3.      List View filters can now be edited on-the-fly and record detail pages support inline editing. Both features providing enhancement to the general user experience.
    4.     Lightning Experience – Detect User Experience –
    Support is now provided for Apex script to reliably detect the current user experience, i.e. Salesforce1, Lightning Experience, Salesforce Classic. New Apex methods are available (User.UITheme and UserInfo.getUiTheme()) that provide a standardised approach that replaces the previous use of the sforce.one JavaScript global (and its unsupported approach caveat).
    5.     Apex Unit Tests
    New developers writing Apex Unit tests have suffered for years with the platform constraint that setup and non-setup objects can’t be created in the same Apex transaction (Mixed DML Operation Error). Typically this is problematic where User records are created in the test context alongside test records such as Accounts etc. With Spring ’16 it is now possible to create the setup object via @future method. A second improvement in context is the ability to change record creation date field values using the System.Test.setCreatedDate method. Where record processing logic is temporal in nature this ability will be helpful in writing tests that correctly validate the code logic.
    6.     Enterprise Edition customers now get access to 25 developer sandboxes instead of 1

Thursday, 11 February 2016

Moving pick-list values up and down (reordering) in javaScript (Works only chrome, not working for Firefox and IE)

<!-- To switch the picklist values -->
    function arraymove(direction) {
        var optionslist = document.getElementById('select-2').options;
        var selLst = [];
        var unselLst = [];
        var combLstVals = [];
        var combLstLabels = [];
        var combLstSel = [];
        var selStartIndex;
        var count = 0;
        for(i=0;i<optionslist.length;i++) {
            if(optionslist[i].selected) {
                if(count == 0)
                    selStartIndex = i;
                count++;
                selLst.push(optionslist[i]);
            }
            else {
                unselLst.push(optionslist[i]);
            }
        }
        var ovelAllLength = selStartIndex + selLst.length;
            var isApply = false;
            //Down Arrow Logic
            if(direction == 'down') {
                if(selStartIndex != null && (ovelAllLength < optionslist.length || selStartIndex == 0)) {
                    isApply = true;
                    if(selStartIndex != 0) {
                        for(i=0;i<unselLst.length;i++) {
                            if(i == selStartIndex) {
                                combLstVals.push(unselLst[i].value);
                                combLstLabels.push(unselLst[i].label);
                                combLstSel.push(false);
                                for(j=0;j<selLst.length;j++) {
                                    combLstVals.push(selLst[j].value);
                                    combLstLabels.push(selLst[j].label);
                                    combLstSel.push(true);        
                                }
                            }
                            else {
                                combLstVals.push(unselLst[i].value);
                                combLstLabels.push(unselLst[i].label);
                                combLstSel.push(false);
                            }
                        }
                    }
                    else {
                        combLstVals.push(unselLst[0].value);
                        combLstLabels.push(unselLst[0].label);
                        combLstSel.push(false);
                        for(j=0;j<selLst.length;j++) {
                            combLstVals.push(selLst[j].value);
                            combLstLabels.push(selLst[j].label);
                            combLstSel.push(true);        
                        }
                        for(i=1;i<unselLst.length;i++) {
                            combLstVals.push(unselLst[i].value);
                            combLstLabels.push(unselLst[i].label);
                            combLstSel.push(false);
                        }
                    }
                }                          
            }
            //Up Arrow Logic
            else if(direction == 'up') {
                if(selStartIndex != 0 && selStartIndex != null) {
                    isApply = true;
                    if(selStartIndex == 1) {
                        for(j=0;j<selLst.length;j++) {
                            combLstVals.push(selLst[j].value);
                            combLstLabels.push(selLst[j].label);
                            combLstSel.push(true);        
                        }
                        for(i=0;i<unselLst.length;i++) {
                            combLstVals.push(unselLst[i].value);
                            combLstLabels.push(unselLst[i].label);
                            combLstSel.push(false);
                        }
                    }
                    else {
                         for(i=0;i<unselLst.length;i++) {
                            if(i == selStartIndex - 1) {
                                for(j=0;j<selLst.length;j++) {
                                    combLstVals.push(selLst[j].value);
                                    combLstLabels.push(selLst[j].label);
                                    combLstSel.push(true);        
                                }
                                combLstVals.push(unselLst[i].value);
                                combLstLabels.push(unselLst[i].label);
                                combLstSel.push(false);                            
                            }
                            else {
                                combLstVals.push(unselLst[i].value);
                                combLstLabels.push(unselLst[i].label);
                                combLstSel.push(false);
                            }
                        }
                    }
                }
            }      
            if(isApply) {
                for(i=0;i<optionslist.length;i++) {
                    optionslist[i].value = combLstVals[i];
                    optionslist[i].label = combLstLabels[i];
                    optionslist[i].selected = combLstSel[i];
                }
            }
    }

Thursday, 4 February 2016

Multiplication pattern with Apex

Multiplication Pattern -

/*     10*2 =20     20*2 =40     40*2 =80     80*2 =160     160*2 =320 */ public class Apptitude {     public static void multiplicationPattern1(Integer num) {         Integer n = num;         for(Integer i=0;i<n;i++) {             system.debug(Integer.valueOf((math.pow(2, i)*10))+'*2 ='+Integer.valueOf((math.pow(2, i)*20))+'\n');         }     } }

Saturday, 4 July 2015

Summer 15 Release Notes

Summer 15 Release Notes

1.       'Setup Assistant' in 'Setup' menu for the newly activated organizations which provides helpful videos and documentation for the basic configurations for the administrators.
2.       Data Loader is available for Mac.
3.       Login Access Policy changed , (To login as any user by clicking on ‘Login’ button/link)–
a.       Previously, Salesforce had to be contacted to enable the Administrator can Login as any user Setting.
b.      Starting from Summer ’15, this setting is enabled by default.
c.       Permission needed to login as any user includes –
                                                                i.      The “Modify All Data” permission enabled  for administrators, and
                                                               ii.      The “View Setup and Configuration” permission enabled for delegated administrators.               
4.       Edit Feed Posts and Comments –
a.       SF introduces option to edit posts and comments.
b.      The Chatter Settings option Allow Users to edit posts and comments is enabled by default for all the organizations.
c.       The user permission Edit My Own Posts:
                                                                i.      Is available by default for the users with standard profiles.
                                                               ii.      Can be enabled in the profile for the users with custom profiles.
                                                             iii.      Is not available to Chatter Free, Chatter External, and Customer Portal profiles.
d.      The user permission Edit Posts on Records I Own can be enabled in the profile for users with standard or custom profiles.
e.      Chatter Moderators, community moderators, and users with “Modify All Data” permission can always edit all posts and comments.
5.       Share any file with a library –
a.       The ability to share files with libraries is turned off by default.
b.      Can be enabled by navigating to Setup > Customize > Salesforce Files > Settings > Salesforce CRM Content > Files user interface allows sharing files with library.
6.       Salesforce Files Sync software can be installed so that we sync files from local system to a folder in salesforce server.
7.       Previous all the custom object records could be added to chatter groups but now sf introduced an option called “Allow in Chatter Groups” permission on the object edit page.
8.       Customizing Actions in the Salesforce1 Action Bar –
a.       Developers can choose to override the predefined actions and specify separate set of actions to appear in Salesforce1 and the Web Interface.
b.      To support this new feature:
                                                                i.      Actions category in palette has been removed to Quick Actions.
                                                               ii.      A new category, Salesforce1 Actions, has been added.
                                                             iii.      The Actions in the Publisher section in the page layout                has been renamed to Quick Actions in the Publisher.
                                                             iv.      A new section named Actions in the Salesforce1 Action Bar has been added to the page layout.
9.       Enhancements to Macros –
a.       Using macros, Support Agents can now:
                                                                i.      Run bulk macros on multiple records at the same time.
                                                               ii.      Search and attach articles to macros.
                                                             iii.      Post to social networks.
                                                             iv.      Replace field values in a case.

                                                              v.      Insert field values into a case.

Saturday, 30 November 2013

Roll Up Summary Fields using Trigger After events

Roll Up Summary Fields using Trigger After events :

trigger My_MonthsRollUp_US on THD_Sales__c (after insert, after update, after delete, after undelete) {
    Map<Id,Account> updateAccounts = new Map<Id,Account>();
    Set<Id> updateAccountIds = new Set<Id>();    
  // If we are inserting, updating, or undeleting, use the new ID values
  if(Trigger.isInsert || Trigger.isUpdate || Trigger.isUndelete) {
    if(trigger.new != null)
        for(THD_Sales__c thdsales:Trigger.new)
            if(thdsales.SFDC_Account_ID__c != '0017000000ZWk80AAD')
              updateAccounts.put(thdsales.SFDC_Account_ID__c,null);
  }
  // If we are updating, some accounts might change, so include that as well as deletes
  if(Trigger.isUpdate || Trigger.isDelete) {
    if(trigger.old != null)
        for(THD_Sales__c thdsales:Trigger.old)
            if(thdsales.SFDC_Account_ID__c != '0017000000ZWk80AAD')
              updateAccounts.put(thdsales.SFDC_Account_ID__c,null);
  }
  // Do not create a record for null field
  updateAccounts.remove(null);  
  // Create in-memory copies for all accounts that will be affected
  for(Id accountId:updateAccounts.keyset()) 
    updateAccounts.put(accountId,new Account(id=accountId,
    Total_My_SO_Sales_January__c=0, Total_My_SO_Sales_February__c=0,Total_My_SO_Sales_March__c=0,
    Total_My_SO_Sales_April__c=0,Total_My_SO_Sales_May__c=0,Total_My_SO_Sales_June__c=0,
    Total_My_SO_Sales_July__c=0,Total_My_SO_Sales_August__c=0,Total_My_SO_Sales_September__c=0,
    Total_My_SO_Sales_October__c=0,Total_My_SO_Sales_November__c=0,Total_My_SO_Sales_December__c=0,
    Total_Cash_Carry_Sales_January__c=0, Total_Cash_Carry_Sales_February__c=0,Total_Cash_Carry_Sales_March__c=0,
    Total_Cash_Carry_Sales_April__c=0,Total_Cash_Carry_Sales_May__c=0,Total_Cash_Carry_Sales_June__c=0,
    Total_Cash_Carry_Sales_July__c=0,Total_Cash_Carry_Sales_August__c=0,Total_Cash_Carry_Sales_September__c=0,
    Total_Cash_Carry_Sales_October__c=0,Total_Cash_Carry_Sales_November__c=0,Total_Cash_Carry_Sales_December__c=0
    ));
    
    // Run an optimized query that looks for all accounts that meet the if/then criteria
    map< string, list< schema.sobjectfield > > fieldMap =
        new map< string, list< schema.sobjectfield > > {
            'Special Order' =>
                new list< schema.sobjectfield > {
                    null,
                    Account.Total_My_SO_Sales_January__c,
                    Account.Total_My_SO_Sales_February__c,
                    Account.Total_My_SO_Sales_March__c,
                    Account.Total_My_SO_Sales_April__c,
                    Account.Total_My_SO_Sales_May__c,
                    Account.Total_My_SO_Sales_June__c,
                    Account.Total_My_SO_Sales_July__c,
                    Account.Total_My_SO_Sales_August__c,
                    Account.Total_My_SO_Sales_September__c,
                    Account.Total_My_SO_Sales_October__c,
                    Account.Total_My_SO_Sales_November__c,
                    Account.Total_My_SO_Sales_December__c
                },
           'Cash & Carry' =>
                new list< schema.sobjectfield > {
                    null,
                    Account.Total_Cash_Carry_Sales_January__c,
                    Account.Total_Cash_Carry_Sales_February__c,
                    Account.Total_Cash_Carry_Sales_March__c,
                    Account.Total_Cash_Carry_Sales_April__c,
                    Account.Total_Cash_Carry_Sales_May__c,
                    Account.Total_Cash_Carry_Sales_June__c,
                    Account.Total_Cash_Carry_Sales_July__c,
                    Account.Total_Cash_Carry_Sales_August__c,
                    Account.Total_Cash_Carry_Sales_September__c,
                    Account.Total_Cash_Carry_Sales_October__c,
                    Account.Total_Cash_Carry_Sales_November__c,
                    Account.Total_Cash_Carry_Sales_December__c
                } 
        };     

   for(THD_Sales__c thdsales : [SELECT Id, Month_Year__c, POS_Order_Type__c, Amount__c, SFDC_Account_ID__c
   FROM  THD_Sales__c WHERE SFDC_Account_ID__c IN :updateAccounts.keySet( ) AND 
   POS_ORDER_TYPE__C IN ('Special Order','Cash & Carry') AND Month_Year__c != null]){ 
                            
        updateAccounts.get( thdsales.sfdc_account_id__c ).put(fieldmap.get( thdsales.pos_order_type__c )[thdsales.month_year__c.month()],
            ( Decimal )( updateAccounts.get( thdsales.sfdc_account_id__c ).get( fieldmap.get( thdsales.pos_order_type__c )[thdsales.month_year__c.month()]))+thdsales.Amount__c );
    }
  // Update all the accounts with new values.
  Database.update(updateAccounts.values());
}

Labels