Tuesday 17 June 2014

How to access List,Set and Map in Salesforce


Here is the sample code to access Set and List values via loop salesforce,

Accessing List 

To access List of values through for loop it’s simple, the below examples show access list of element via loop.
  1. List<Integer> myList = new List<Integer>{1,2,3};
  2. for(integer i=0;i<myList.size();i++)
  3. {
  4.     System.debug(myList[i]);
  5. }

Accessing Set

To access Set values through for loop it’s different than accessing List, the below examples show access set of element via loop.
Set<integer> mySet = new Set<integer>{1, 2, 3};
   

  1. for(integer i=0;i<mySet.size();i++)
  2. {
  3.     System.debug((new list<Integer>(mySet))[i]);
  4. }

Accessing Map

To access Map values it’s similar to set.

Accessing Key

The below examples show access KeySet of Map via loop. 

  1. Map<string, string> colorCodes = new Map<String, String>();
  2. colorCodes.put('Red''FF0000');
  3. colorCodes.put('Blue''0000A0');
  4. for(integer i=0;i<colorCodes.size();i++)
  5. {
  6.     System.debug((new list<String>(colorCodes.keySet())[i]));
  7. }
Accessing Values

The below examples shows access Values of Map via loop. 

  1. Map<string, string> colorCodes = new Map<String, String>();
  2. colorCodes.put('Red''FF0000');
  3. colorCodes.put('Blue''0000A0');
  4. for(integer i=0;i<colorCodes.size();i++)
  5. {
  6.     System.debug((new list<String>(colorCodes.keySet())[i]));
  7. }

Thursday 5 June 2014

How to Show IP Address in Visualforce Page Salesforce


      In some of point of requirement you may need to show the IP address in visualforce page. The following is the way to show IP address in salesforce.

Apex Class
  1. public class IPAddress
  2. {
  3. public string myIPAddress{get;set;}
  4.    public IPAddress()
  5.    {
  6.       myIPAddress = ApexPages.currentPage().getHeaders().get('X-Salesforce-SIP');
  7.    }
  8. }
Visualforce page
  1. <apex:page controller="IPAddress" >
  2. Your Login IP Address : {!myIPAddress}
  3. </apex:page>

Here is the IP Address


Activities: Assign Tasks to a Queue Salesforce Lightning

Salesforce announced to assign Tasks to a Queue beginning from Spring'20 release. How does it work? In Setup, enter Queues in th...