• rsfdc
  • NEWBIE
  • 25 Points
  • Member since 2014
  • Salesforce Developer


  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 1
    Questions
  • 6
    Replies
I'm updaing the contracts object for our org.  There is a section on the object about Contact Details such as First Name, Last Name, Email, Title, Phone and Fax.  Currently these are just text fields where a rep has to enter the data.

We are adding a lookup field called Existing Contact where the rep can search for a contact in Salesforce.  If the contact exists then populate the contact detail fields with information.  If the information doesn't exist on the contact record then we still need to leave the contact details free text so the rep can manually enter information (I've tried to get them to update the contact record but apparently that's too much work).

Below is the code that I have at the moment.  It works fine when you're updating an existing contract but when you create a new contract I get the following error:

Apex trigger ContractsTrigger caused an unexpected exception, contact your administrator: ContractsTrigger: execution of BeforeInsert caused by: System.ListException: List index out of bounds: 0: Class.ContractsTriggerHandler.getContactValues: line 86, column 1.

Any help would be greatly appreciated.

public with sharing class ContractsTriggerHandler {
    private boolean triggerIsExecuting = false;
   
    private Contract contracts = null;
    private integer batchSize = 0;

  public boolean isTriggerContext{
        get { return triggerIsExecuting;}
    }
   
    public boolean isVisualforcePageContext{
        get { return !isTriggerContext;}
    }
   
    public boolean isWebServiceContext{
        get { return !isTriggerContext;}
    }
   
    public boolean isExecuteAnonymousContext{
        get { return !isTriggerContext;}
    }

   public ContractsTriggerHandler(boolean isExecuting, integer size){
     triggerIsExecuting = isExecuting;
     BatchSize = size;
   }
  
public void setContract(Contract value) {
  if(value == null) {
   contracts = new Contract();
  }
  else {
    contracts = value;
  }
}    
  
   public void onBeforeInsert(Contract[] newContract){

    if(newContract != null)
    {
   getContactValues(null,newContract,null);
    }
    }
  public void onBeforeUpdate(Contract[] oldContract, Contract[] updatedContract, Map<ID, Contract> oldContractMap) {
   getContactValues(oldContract,updatedContract,oldContractMap);
    }
   
public void getContactValues(Contract[] oldContract, Contract[] updatedContract, Map<ID, Contract> oldContractMap)
{ 
  for(Contract contract : updatedContract)
  {
   List<Contract> UpdateCont = [SELECT  Contract.ID
               ,Contract.Email__c
            ,Existing_Contact__r.Email
            ,Name__c
            ,Title__c
            ,Phone__c
            ,Fax__c
                  ,Existing_Contact__r.Title
                  ,Existing_Contact__r.Phone
                  ,Existing_Contact__r.Fax
                  ,Existing_Contact__r.Name
            FROM Contract Where ID = :contract.Id];

   if(!Util.IsEmptyOrNull(UpdateCont[0].Existing_Contact__c))
   {
    if(!Util.IsEmptyOrNull(UpdateCont[0].Existing_Contact__r.Email))
    {
     contract.Email__c = UpdateCont[0].Existing_Contact__r.Email;
    }
    else
    {
     contract.Email__c = contract.Email__c;
    }
    if(!Util.IsEmptyOrNull(UpdateCont[0].Existing_Contact__r.Name))
    {
     contract.Name__c  = UpdateCont[0].Existing_Contact__r.Name;
    }
    else
    {
     contract.Name__c = contract.Name__c;
    }
    if(!Util.IsEmptyOrNull(UpdateCont[0].Existing_Contact__r.Title))
    {
     contract.Title__c = UpdateCont[0].Existing_Contact__r.Title;
    }
    else
    {
     contract.Title__c = contract.Title__c;
    }
    if(!Util.IsEmptyOrNull(UpdateCont[0].Existing_Contact__r.Phone))
    {
     contract.Phone__c = UpdateCont[0].Existing_Contact__r.Phone;
    }
    else
    {
     contract.Phone__c = contract.Phone__c;
    }
    if(!Util.IsEmptyOrNull(UpdateCont[0].Existing_Contact__r.Fax))
    {
     contract.Fax__c = UpdateCont[0].Existing_Contact__r.Fax;
    }
    else
    {
     contract.Fax__c = contract.Fax__c;
    }                   

    System.debug('Email'+contract.Email__c);
   }
  }
}
To hide leads from portal, I've created following sharing rule (see screenshot)
User-added image

However there is still one particular instance where Lead Created/Owned by User A is not visible to User B. Both User A and B have CRUD lead permission, and are salesforce users.
What could be other factors? I've recalculated the sharing rules. Also I've manually tested the records created by a lot of other users are shared with All Internal users.
  • July 17, 2014
  • Like
  • 0
Can anyone provide some idea or approach on how to create a multiselect picklist like below pic.User-added image

Regards
I need to have Address related list in Accounts populate the Address information from Accounts to display in Contact's Address related list.  Can this be done using a formula?
Hi,

Could u please help me in the following scnearios - 

1. I have a vf page which displays list of cases with a picklist in each row and a save button. I want when i press save button it will save the record and redirect me to the same page. 

Currently i am not using any custom controller  and the save button after click is re-directing to home page.
I'm updaing the contracts object for our org.  There is a section on the object about Contact Details such as First Name, Last Name, Email, Title, Phone and Fax.  Currently these are just text fields where a rep has to enter the data.

We are adding a lookup field called Existing Contact where the rep can search for a contact in Salesforce.  If the contact exists then populate the contact detail fields with information.  If the information doesn't exist on the contact record then we still need to leave the contact details free text so the rep can manually enter information (I've tried to get them to update the contact record but apparently that's too much work).

Below is the code that I have at the moment.  It works fine when you're updating an existing contract but when you create a new contract I get the following error:

Apex trigger ContractsTrigger caused an unexpected exception, contact your administrator: ContractsTrigger: execution of BeforeInsert caused by: System.ListException: List index out of bounds: 0: Class.ContractsTriggerHandler.getContactValues: line 86, column 1.

Any help would be greatly appreciated.

public with sharing class ContractsTriggerHandler {
    private boolean triggerIsExecuting = false;
   
    private Contract contracts = null;
    private integer batchSize = 0;

  public boolean isTriggerContext{
        get { return triggerIsExecuting;}
    }
   
    public boolean isVisualforcePageContext{
        get { return !isTriggerContext;}
    }
   
    public boolean isWebServiceContext{
        get { return !isTriggerContext;}
    }
   
    public boolean isExecuteAnonymousContext{
        get { return !isTriggerContext;}
    }

   public ContractsTriggerHandler(boolean isExecuting, integer size){
     triggerIsExecuting = isExecuting;
     BatchSize = size;
   }
  
public void setContract(Contract value) {
  if(value == null) {
   contracts = new Contract();
  }
  else {
    contracts = value;
  }
}    
  
   public void onBeforeInsert(Contract[] newContract){

    if(newContract != null)
    {
   getContactValues(null,newContract,null);
    }
    }
  public void onBeforeUpdate(Contract[] oldContract, Contract[] updatedContract, Map<ID, Contract> oldContractMap) {
   getContactValues(oldContract,updatedContract,oldContractMap);
    }
   
public void getContactValues(Contract[] oldContract, Contract[] updatedContract, Map<ID, Contract> oldContractMap)
{ 
  for(Contract contract : updatedContract)
  {
   List<Contract> UpdateCont = [SELECT  Contract.ID
               ,Contract.Email__c
            ,Existing_Contact__r.Email
            ,Name__c
            ,Title__c
            ,Phone__c
            ,Fax__c
                  ,Existing_Contact__r.Title
                  ,Existing_Contact__r.Phone
                  ,Existing_Contact__r.Fax
                  ,Existing_Contact__r.Name
            FROM Contract Where ID = :contract.Id];

   if(!Util.IsEmptyOrNull(UpdateCont[0].Existing_Contact__c))
   {
    if(!Util.IsEmptyOrNull(UpdateCont[0].Existing_Contact__r.Email))
    {
     contract.Email__c = UpdateCont[0].Existing_Contact__r.Email;
    }
    else
    {
     contract.Email__c = contract.Email__c;
    }
    if(!Util.IsEmptyOrNull(UpdateCont[0].Existing_Contact__r.Name))
    {
     contract.Name__c  = UpdateCont[0].Existing_Contact__r.Name;
    }
    else
    {
     contract.Name__c = contract.Name__c;
    }
    if(!Util.IsEmptyOrNull(UpdateCont[0].Existing_Contact__r.Title))
    {
     contract.Title__c = UpdateCont[0].Existing_Contact__r.Title;
    }
    else
    {
     contract.Title__c = contract.Title__c;
    }
    if(!Util.IsEmptyOrNull(UpdateCont[0].Existing_Contact__r.Phone))
    {
     contract.Phone__c = UpdateCont[0].Existing_Contact__r.Phone;
    }
    else
    {
     contract.Phone__c = contract.Phone__c;
    }
    if(!Util.IsEmptyOrNull(UpdateCont[0].Existing_Contact__r.Fax))
    {
     contract.Fax__c = UpdateCont[0].Existing_Contact__r.Fax;
    }
    else
    {
     contract.Fax__c = contract.Fax__c;
    }                   

    System.debug('Email'+contract.Email__c);
   }
  }
}
Can anyone provide some idea or approach on how to create a multiselect picklist like below pic.User-added image

Regards