Monday, February 18, 2013

Data Import Help and Training:


Data Import Help and Training:
Data Import: This video series covers the essentials of importing data into Salesforce.
Data Import Overview
Preparing Your Data for Import
Cleaning and Preparing Your Data Using Excel
Should I Use Data Loader
Importing Your Data in the Right Order
Best Practices for Importing Data
Learn how to view your sync direction settings in Salesforce for Outlook, and find out whether you have permissions to change them.
Learning about Sync Directions

Learn how to find Data.com accounts and contacts and add them to Salesforce. Check out the Account Card.
Finding Data.com Accounts and Contacts and Adding Them to Salesforce

Wednesday, February 13, 2013

Sharing Records using Trigger:

Sharing Records using Trigger:
This example shows how to share records after inserting depends on user you selected before creating the record.The trigger looks like this
trigger Hiring_Manager_Position_Share on Position__c (after insert) {
    if(trigger.isInsert){
        List<Position__Share> posShare = new List<Position__Share>();
        for(Position__c pos : trigger.new){
            Position__Share hiringManagerShare = new Position__Share();
            hiringManagerShare.ParentId = pos.Id;
            hiringManagerShare.UserOrGroupId = pos.Hiring_Manager__c;
            hiringManagerShare.AccessLevel = 'edit';
            hiringManagerShare.RowCause = Schema.Position__Share.RowCause.Hiring_Manager__c;
            posShare.add(hiringManagerShare);
        }
        Database.SaveResult[] posShareInsertResult = Database.insert(posShare, false);  
    }
}



Monday, February 11, 2013

Dynamic Approval:

Dynamic Approval:
We can achieve dynamic approval by creating a custom object and upload all the approve rs  related to your  business logic. In this example first create a custom object Position Approval Matrix and create list of records related to each department.The class and trigger looks like this

public class PositionApproval {
// Author: Mike Dannenfeldt, Etherios

static final Map<String,Position_Approval_Matrix__c> APPROVAL_MAP_CONST;

static {
APPROVAL_MAP_CONST = getPositionApprovalMap();
}

private static Map<String,Position_Approval_Matrix__c> getPositionApprovalMap(){
// build a Map from Department --> Approval Matrix record
Map<String,Position_Approval_Matrix__c> results = new Map<String,Position_Approval_Matrix__c>();
List<Position_Approval_Matrix__c> records = [select id,name,department__c,approver_1__c,approver_2__c,approver_3__c from Position_Approval_Matrix__c];
for(Position_Approval_Matrix__c record : records){
if (!results.containsKey(record.department__c)) results.put(record.department__c, record);
}
return results;
}

public static void setPositionApprovers(Position__c[] positions){
for (Position__c p:positions){
if (p.Department__c != null) {
if (APPROVAL_MAP_CONST.containsKey(p.Department__c)){
p.approver_1__c = APPROVAL_MAP_CONST.get(p.Department__c).approver_1__c;
p.approver_2__c = APPROVAL_MAP_CONST.get(p.Department__c).approver_2__c;
p.approver_3__c = APPROVAL_MAP_CONST.get(p.Department__c).approver_3__c;
} else {
p.approver_1__c = null;
p.approver_2__c = null;
p.approver_3__c = null;
}
}
}
}
}


trigger PositionApprovalTrigger on Position__c (before insert, before update) {
    PositionApproval.setPositionApprovers(Trigger.new);
}

Position record after insert looks like this





Sunday, February 10, 2013

Fibonacci Sequence:

Fibonacci Sequence:This example shows how to generate Fibonacci series.Please check the Execute logs how it executes .

/* Fibonacci Sequence: The first two Fibonacci numbers are 0 and 1 and then the next Fibonacci number is found by adding the previous two together  */

// Setup the initial variables to hold the old number, current number, and fibonacci number
Integer oldNumber = 0;
Integer currentNumber = 1;
Integer fibonacciNumber = 0;

// use a loop to output all the fibonacci numbers between 0 and 100
while (fibonacciNumber < 100) {
     
      System.Debug(fibonacciNumber);  // output the Fibonacci number

      // calculate the next fibonacci number by adding the
      // current number to the old number
      fibonacciNumber= currentNumber + oldNumber;
     
      // now set the new values of the old and current numbers
      oldNumber = currentNumber;
      currentNumber = fibonacciNumber;
}