Friday, October 18, 2013

Document Library

Document Library:
Imagine that you have one location to store all of your important files,such as Documents, Sales Presentations, and price lists .The Documents tab in Salesforce gives you just that.

The documents library is a place to stores files without attaching them to accounts, contacts, opportunities, or other records.Each document in the document library resides in a folder.The folders attributes determine the accessibility of the folder and the documents within it.In many organizations there are corporate folder or folders.Each can store things like price lists, company logos, and other files that could be used by any employee.







Contacts

Contacts:
Contacts are all of individuals the individuals associated with your business accounts that you need to track in Salesforce. When you convert a lead , the lead automatically becomes a  contact related to the account created for the lead. A contact can be associated to only one account, but we can associate many contacts with a single account.



There may be accounts that you work over a period of months or even years.Over the life of an account, you will likely enter a good number of contacts.One challenge is to ensure a contact you store in Salesforce stays up-to-date over the life of account .An easy and efficient way to do this is to use the Stay-in-Touch email feature. Personal-Setup-Email-My Stay-In-Touch Settings.





Track your interactions and communications with your contacts using the Activity and Activity History related list.


You can sent an email to contact






Thursday, October 17, 2013

Create or Update Contact When User Created or Updated

Create or Update Contact When User Created or Updated:
This example examples how to create a non related object records depends on dml action.

public class CONCreate

{
   @future
  public static void myMethod(Set<ID> usrids) 
  {
  
       User[] candsFromTrigger = [Select ID,Division,FirstName,LastName,Email,Department,Title,
                     Phone,MobilePhone,Street,City,State,Country,PostalCode,IsActive From User Where ID IN:usrids];
                     
        List<Contact> conList = new List<Contact>();
     
        
        
      
  
    ///candsFromTrigger = [Select ID,Division,FirstName,LastName,Email,Department,Title,
    //Phone,MobilePhone,Street,City,State,Country,PostalCode From User Where ID IN:uids];
    //TODO: Select the Recruiting record from the database and assign to an object called candAcct from the sObject Account class
     

    //Instantiate a Contact list object from the List class called conList

    
    
    //Declare a For list loop to loop through the input parameter list candsFromTrigger with an iterationvariable called currentCandidate
   
    
    
     for(User currentCandidate: candsFromTrigger){
    
    Account candAcct = [SELECT a.Id FROM Account a 
                        WHERE a.Name =:currentCandidate.Division];
      //Instantiate an object called con from the sObject class contact
      Contact con = new Contact();
      //con = [select id,FirstName,LastName,contact_status__c,Email from contact where email  =: currentCandidate.email  limit 1]; 
      //TODO: Set the attribute AccountID of the con object to the value of the Id attribute of the candAcct object
      con.AccountId = candAcct.Id;

      //Set the attribute Firstname of the con object to the value of the First_Name__c attribute of the currentCandidate object

      con.FirstName = currentCandidate.FirstName; 

      //Set the attribute Lastname of the con object to the value of the Last_Name__c attribute of the currentCandidate object

      con.LastName = currentCandidate.LastName;

      //Set the attribute Email of the con object to the value of the Email__c attribute of the currentCandidate object

      con.Email = currentCandidate.Email;
      
      con.Department = currentCandidate.Department;
      
      con.Title = currentCandidate.Title;
      
      con.Phone = currentCandidate.Phone;
      
      con.MobilePhone = currentCandidate.MobilePhone;
      
      con.MailingStreet = currentCandidate.Street;
      
      con.MailingCity = currentCandidate.City;
      
      con.MailingState = currentCandidate.State;
      
      con.MailingCountry = currentCandidate.Country;
      
      con.MailingPostalCode = currentCandidate.PostalCode;
      
      con.Contact_Type__c = 'SFC User';
      
      
      con.Contact_Status__c = 'Active';
      
      
      

      //Add the con object to the conList

      conList.add(con);    
      
       }
       insert conList;   

  }

}


public class CONUpdate { @future public static void myMethod(Set<ID> usrids) { User[] candsFromTrigger = [Select ID,Division,FirstName,LastName,Email,Department,Title, Phone,MobilePhone,Street,City,State,Country,PostalCode,IsActive From User Where ID IN:usrids]; List<Contact> conList = new List<Contact>(); List<Contact> conList1 = new List<Contact>(); ///candsFromTrigger = [Select ID,Division,FirstName,LastName,Email,Department,Title, //Phone,MobilePhone,Street,City,State,Country,PostalCode From User Where ID IN:uids]; //TODO: Select the Recruiting record from the database and assign to an object called candAcct from the sObject Account class //Instantiate a Contact list object from the List class called conList //Declare a For list loop to loop through the input parameter list candsFromTrigger with an iterationvariable called currentCandidate Contact con1; for(User currentCandidate:candsFromTrigger){ Account candAcct = [SELECT a.Id FROM Account a WHERE a.Name =:currentCandidate.Division]; //Instantiate an object called con from the sObject class contact con1 = [select id,FirstName,LastName,contact_status__c,Email from contact where email =: currentCandidate.email limit 1]; If(currentCandidate.IsActive==TRUE){ //TODO: Set the attribute AccountID of the con object to the value of the Id attribute of the candAcct object con1.AccountId = candAcct.Id; //Set the attribute Firstname of the con object to the value of the First_Name__c attribute of the currentCandidate object con1.FirstName = currentCandidate.FirstName; //Set the attribute Lastname of the con object to the value of the Last_Name__c attribute of the currentCandidate object con1.LastName = currentCandidate.LastName; con1.Department = currentCandidate.Department; con1.Title = currentCandidate.Title; con1.Phone = currentCandidate.Phone; con1.MobilePhone = currentCandidate.MobilePhone; con1.MailingStreet = currentCandidate.Street; con1.MailingCity = currentCandidate.City; con1.MailingState = currentCandidate.State; con1.MailingCountry = currentCandidate.Country; con1.MailingPostalCode = currentCandidate.PostalCode; //Set the attribute Email of the con object to the value of the Email__c attribute of the currentCandidate object // con1.Email = currentCandidate.Email; //con1.Contact_Type__c = 'SFC User'; con1.Contact_Status__c = 'Active'; //Add the con object to the conList // if(currentCandidate.IsActive==TRUE){ // con1.Contact_Status__c = 'Active';}else // If(currentCandidate.IsActive==FALSE){ // con1.Contact_Status__c='Inactive';} conList1.add(con1); System.Debug('After ADDED TO LEAD LIST VALUES *** : '+ conList1); } else if(currentCandidate.IsActive==FALSE) { con1.AccountId = candAcct.Id; //Set the attribute Firstname of the con object to the value of the First_Name__c attribute of the currentCandidate object con1.FirstName = currentCandidate.FirstName; //Set the attribute Lastname of the con object to the value of the Last_Name__c attribute of the currentCandidate object con1.LastName = currentCandidate.LastName; con1.Department = currentCandidate.Department; con1.Title = currentCandidate.Title; con1.Phone = currentCandidate.Phone; con1.MobilePhone = currentCandidate.MobilePhone; con1.MailingStreet = currentCandidate.Street; con1.MailingCity = currentCandidate.City; con1.MailingState = currentCandidate.State; con1.MailingCountry = currentCandidate.Country; con1.MailingPostalCode = currentCandidate.PostalCode; con1.Contact_Status__c='Inactive'; conList1.add(con1); System.Debug('After ADDED TO LEAD LIST VALUES *** : '+ conList1); } } //MyFutureClass.myMethod(conList1.Keyset()); update conList1; //Persist the conList to the database } }


Finally trigger looks like this

trigger CreateContact1 on User (after insert,after update) { Set<ID> uids = new Set<ID>(); for(User U : Trigger.New) { uids.add(U.ID); } if(Trigger.IsInsert) { CONCreate.myMethod(uids); } else if(Trigger.IsUpdate) { CONUpdate.myMethod(uids); } //TODO: Instantiate an object called cc from the class CreateContactFromCan //CreateContactFromCan1 cc = new CreateContactFromCan1(); //TODO: Inovke the method createContact and send a List of Candidates as an input parameter //cc.createContact1(uids); //CreateContactFromCan1.createContact1(uids); }

and test class is

@isTest private class TestTriggersCreateContactFromCan1 { static testMethod void TestCreateContactFromCan1() { account acc=new account(Name='CCS',Region__c='10',Industry='Aero'); insert acc; User u =new User(FirstName = 'TestFirstName' , TimeZoneSidKey='America/Los_Angeles',LocaleSidKey='en_US', EmailEncodingKey='ISO-8859-1', ProfileId='00e30000001YGorAAG',LanguageLocaleKey='en_US' , LastName = 'TestLastName', Alias = 'Test789' , Email = 'Test789@gmail.com' , UserName = 'Test559@gmail.com',CommunityNickname = 'TestNickName', Division='CCS'); try{ insert u; }catch (exception e){ system.debug('exception:'+e); } u.LastName='Final456'; try{ update u; }catch(exception e){ system.debug('exception:'+e); } u.IsActive=False; try{ update u; }catch(exception e){ system.debug('exception:'+e); } } }





Accounts

Accounts:
When a lead is converted you can create account, contact and potentially an opportunity.
Accounts are key to building and accessing all your customer-related data.
Accounts are the backbone of information that represent prospective, existing and former customers.Each account stores information, such as name, address and phone numbers.

For each account, you can store related information  such as an opportunities, activities, cases, partners, contacts and notes.
You can also sort and filter your accounts using standard and custom list views.
Open Activities : You can track items, such as tasks, events, and emails, in both the open activities and activity history related lists.Open activities related list include all Open Tasks, Open Events.
Activity History related list includes completed tasks, logged phone calls, expired events, logged emails, merged documents.The Notes and Attachments related list contains account related files and file size limit is 5 MB.The contacts related list includes contact information for all contacts associated with the record.The contact roles related list displays contact information for individuals who are not directly linked to an account.