• Christine Klein
  • NEWBIE
  • 60 Points
  • Member since 2014
  • Systems Analyst
  • OpenText Corporation


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 16
    Replies
Is it possible to use a visual flow to send an email to the opportunity owner advising them that there opportunity is closing in x amount of days?  I know you can do this with the standard workflow function but was just curious if this could be replaced with a flow.
When a user clicks on "New Event" from a lead, I would like to populate the campaign field on Events with the campaign that is listed on the Lead Record.  I'm running into an error where it says "Variable does not exist: whoid".  I can't seem to figure out why it would be complaining about whoid when it shows up under Workbench for events.

public with sharing class EventTriggerHandler 
{
	private boolean triggerIsExecuting = false;
    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 EventTriggerHandler(boolean isExecuting, integer size){
    	triggerIsExecuting = isExecuting;
    	BatchSize = size;
  	}
    	
   	public void UpdateLastCampaignActivityOnEvents(Event[] newEvent)
  	{
  		Set<Id> whoIDs = new Set<ID>();
  		for(Event CurrentEvent : newEvent) 
    	{
    		WhoIds.add(CurrentEvent.whoid);
    	}
    	
    	if (whoIDs.size() > 0 )
    	{
    		list<Lead> CurrentLeads = [Select ID, Eloqua_Campaign_Name__c From Lead where ID IN :WhoIDs];
    		
    		map<id,Lead> Leads = new map<id,Lead>();
    		
    		if (currentLeads.size() > 0 )
    		{
    			for (Lead currentlead : currentleads)
    			{
    				Leads.put(currentLead.ID, currentLead);
    			}
    			
    			for(Event CurrentEvent : newEvent) 
		    	{
		    		Lead LeadLookup = Leads.get(CurrentEvent.WhoID); 
		    		if (LeadLookup <> null)
		    		{
		    			CurrentEvent.Last_Campaign_Activity__c = LeadLookup.Eloqua_Campaign_Name__C; 
		    		}
		    	}
    		}
    	}   	

  	}
 	
  	public void onBeforeInsert(Event[] newEvent)
  	{
  		UpdateLastCampaignActivityOnEvents(newEvent);
   	}
   
  
    /*
    @future public static void onAfterInsertAsync(Set<ID> newEventIDs){
    	
    }
    */
 	/*
 	public void OnAfterInsert(Event[] newEvents) {
 		
 		
 	}
 	*/
 	/*
 	public void onBeforeUpdate(Event[] oldEvent, Event[] updatedEvent, Map<ID, Event> oldEventMap) {

    }
    */
 	/*
    public void onAfterUpdate(Event[] oldEvent, Event[] updatedEvent, Map<ID, Event> oldEventMap) {
    		
    }
    */
  	/*  
    @future public static void onAfterUpdateAsync(Set<ID> updatedEvent){
    	
    }
    */
    /*
    public void onBeforeDelete(Event[] EventToDelete, Map<ID, Event> EventMap){
        
    }
    */
    /*
    public void onAfterDelete(Event[] deletedEvent, Map<ID, Event> EventMap){
    			
    }
    */
    
    /*
    @future public static void onAfterDeleteAsync(Set<ID> deletedEvent){
        //to make this work like the on after delete you need to do a select statement into 
        //a list where ID in :deletedOpportunitySplits, this would recreate the deletedOpportunitySplits list
        //from there the code would work the same.
    }
    */
    
    /*
    public void onUndelete(Event[] restoredEvent){
        
    }
    */ 
}


Below is a snippet of code which counts the number of users that have been added to a custom object on Accounts.

List<AggregateResult> numOfOwners = [select count(Account_Owner__c)cnt,Account_Name__c from Account_Coverage__c WHERE Account_Name__c in : accts AND (NOT MU__c like 'Market Development') and (NOT MU__c like 'Professional Services') and Coverage__c = true GROUP BY Account_Name__c];
  		decimal decimalResults = 0;
  		
  		if(numOfOwners.size() > 0)
  		{
  			String numOfOwnersStr = '' + numOfOwners[0].get('cnt');
  			decimalResults = Decimal.ValueOf(numOfOwnersStr);
  			System.debug('decimalResults = ' + decimalResults);
  		}

I didn't notice an issue with the above code until I tried mass inserting a bunch of owners in the custom object.  If one user was added through DemandTools, # of Owners would display 89.  If I manually add users to the custom object the # of Owners field calculates correctly.

I was just wondering how I can 'bulkify' the above so when I mass insert records the # of Owners field will display the correct count.

Thanks in advance!


I'm creating a custom object which will be a related list on Accounts.  The object is called Account Coverage.  It will act similar to account teams where you can list several account owners in the related list.  Unfortunately we can't customize Account Teams which is why we have to create this custom object.

Coverage fields were added to the account object and get updated based on users added to the Account Coverage object.  If a user is added to Account Coverage and the coverage checkbox is checked and your market unit meets the specific criteria, then your name is added to the corresponding account coverage fields on the account object.

Everything seems to be working ok, I'm just stuck on updating the coverage fields if the coverage checkbox is unchecked.  Any insight on how I can remove names from the coverage fields once the coverage checkbox is unchecked would be greatly appreciated.

Thanks!


public with sharing class AccountCoverageTriggerHandler {
	private boolean triggerIsExecuting = false;
   
    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 AccountCoverageTriggerHandler(boolean isExecuting, integer size){
    	triggerIsExecuting = isExecuting;
    	BatchSize = size;
  	}  	
  	
  	public void UpdateAccountCoverageInformation(list<Account_Coverage__c> Account_Coverage)
  	{
  		list<string> accts = new list<string>();
  		list<string> accountCoverage = new list<string>();
  		
  		for(Account_Coverage__c coverage : Account_Coverage)
  		{
  			accts.add(coverage.Account_Name__c);
  			accountCoverage.add(coverage.ID);
  		}
  		
  		list<Account> acct = [SELECT ID,Coverage_BPM__c,Coverage_Enterprise__c,Coverage_FGM__c
  										,Coverage_Global__c,Coverage_Inside_Sales__c,Coverage_IX__c
  										,Coverage_Portfolio__c,Coverage_Services__c
  										,(SELECT ID,Account_Name__c,Coverage__c,Account_Owner__r.FirstName,Account_Owner__r.LastName
  													,Account_Owner__c,Name,MU__c,BU__c,SR__c 
  													FROM Account_Coverage__r) 
  										FROM Account WHERE ID in : accts];										
  													
  		system.debug('accts = ' + acct);
  		system.debug('Account_Coverage = ' + Account_Coverage);
  		
  		for(Account accountForUpdate : acct)	
  		{
  			string coverageEnterprise = '';
  			string coverageIX = '';
  			string coverageBPM = '';
  			string coverageCorporateGlobal = '';
  			string coveragePortfolio = '';
  			string coverageFGM = '';
  			string coverageProfessionalServices = '';
  			string coverageMarketDevelopment = '';
  			
 			if(accountForUpdate.Account_Coverage__r == null ||  accountForUpdate.Account_Coverage__r.size() <1)
 			{
 				coverageEnterprise = '';
 				coverageIX = '';
  				coverageBPM = '';
  				coverageCorporateGlobal = '';
  				coveragePortfolio = '';
  				coverageFGM = '';
  				coverageProfessionalServices = '';
  				coverageMarketDevelopment = ''; 				
 			}
 			else
 			{
	  			for(Account_Coverage__c accCov : accountForUpdate.Account_Coverage__r)
	  			{
	  					system.debug('accCov' + accCov);
	
	  					if(accCov.Coverage__c == true && accCov.MU__c.contains('Enterprise'))
	  					{
	  						if(coverageEnterprise == '')
	  						{
	  							coverageEnterprise =  accCov.Account_Owner__r.FirstName + ' ' +  accCov.Account_Owner__r.LastName  + ';';
	  							system.debug('ENT Account Owner First Name = '+ accCov.Account_Owner__r.FirstName);
	  							system.debug('ENT Account Owner Last Name Name = '+ accCov.Account_Owner__r.LastName);
	  						}
	  						else
	  						{
	  							coverageEnterprise = coverageEnterprise + accCov.Account_Owner__r.FirstName + ' ' +  accCov.Account_Owner__r.LastName  + ';';
	   							system.debug('ENT Account Owner First Name = '+ accCov.Account_Owner__r.FirstName);
	  							system.debug('ENT Account Owner Last Name Name = '+ accCov.Account_Owner__r.LastName); 							
	  						}
	  					}
	  					if(accCov.Coverage__c == true && accCov.MU__c.contains('IX (Information Exchange)'))
	  					{
	  						if(coverageIX == '')
	  						{
	  							coverageIX =  accCov.Account_Owner__r.FirstName + ' ' +  accCov.Account_Owner__r.LastName  + ';';
	  							system.debug('IX Account Owner First Name = '+ accCov.Account_Owner__r.FirstName);
	  							system.debug('IX Account Owner Last Name Name = '+ accCov.Account_Owner__r.LastName);
	  						}
	  						else
	  						{
	  							coverageIX = coverageIX + accCov.Account_Owner__r.FirstName + ' ' +  accCov.Account_Owner__r.LastName  + ';';
	   							system.debug('IX Account Owner First Name = '+ accCov.Account_Owner__r.FirstName);
	  							system.debug('IX Account Owner Last Name Name = '+ accCov.Account_Owner__r.LastName); 							
	  						}
	  					} 
	  					if(accCov.Coverage__c == true && accCov.MU__c.contains('BPM'))
	  					{
	  						if(coverageBPM == '')
	  						{
	  							coverageBPM =  accCov.Account_Owner__r.FirstName + ' ' +  accCov.Account_Owner__r.LastName  + ';';
	  							system.debug('BPM Account Owner First Name = '+ accCov.Account_Owner__r.FirstName);
	  							system.debug('BPM Account Owner Last Name Name = '+ accCov.Account_Owner__r.LastName);
	  						}
	  						else
	  						{
	  							coverageBPM = coverageBPM + accCov.Account_Owner__r.FirstName + ' ' +  accCov.Account_Owner__r.LastName  + ';';
	   							system.debug('BPM Account Owner First Name = '+ accCov.Account_Owner__r.FirstName);
	  							system.debug('BPM Account Owner Last Name Name = '+ accCov.Account_Owner__r.LastName); 							
	  						}
	  					} 
	  					if(accCov.Coverage__c == true && accCov.MU__c.contains('Market Development'))
	  					{
	  						if(coverageMarketDevelopment == '')
	  						{
	  							coverageMarketDevelopment =  accCov.Account_Owner__r.FirstName + ' ' +  accCov.Account_Owner__r.LastName  + ';';
	  							system.debug('MD Account Owner First Name = '+ accCov.Account_Owner__r.FirstName);
	  							system.debug('MD Account Owner Last Name Name = '+ accCov.Account_Owner__r.LastName);
	  						}
	  						else
	  						{
	  							coverageMarketDevelopment = coverageMarketDevelopment + accCov.Account_Owner__r.FirstName + ' ' +  accCov.Account_Owner__r.LastName  + ';';
	   							system.debug('MD Account Owner First Name = '+ accCov.Account_Owner__r.FirstName);
	  							system.debug('MD Account Owner Last Name Name = '+ accCov.Account_Owner__r.LastName); 							
	  						}
	  					}
	  					if(accCov.Coverage__c == true && accCov.MU__c.contains('Professional Services'))
	  					{
	  						if(coverageProfessionalServices == '')
	  						{
	  							coverageProfessionalServices =  accCov.Account_Owner__r.FirstName + ' ' +  accCov.Account_Owner__r.LastName  + ';';
	  							system.debug('PS Account Owner First Name = '+ accCov.Account_Owner__r.FirstName);
	  							system.debug('PS Account Owner Last Name Name = '+ accCov.Account_Owner__r.LastName);
	  						}
	  						else
	  						{
	  							coverageProfessionalServices = coverageProfessionalServices + accCov.Account_Owner__r.FirstName + ' ' +  accCov.Account_Owner__r.LastName  + ';';
	   							system.debug('PS Account Owner First Name = '+ accCov.Account_Owner__r.FirstName);
	  							system.debug('PS Account Owner Last Name Name = '+ accCov.Account_Owner__r.LastName); 							
	  						}
	  					}	
	  					if(accCov.Coverage__c == true && accCov.MU__c.contains('Portfolio'))
	  					{
	  						if(coveragePortfolio == '')
	  						{
	  							coveragePortfolio =  accCov.Account_Owner__r.FirstName + ' ' +  accCov.Account_Owner__r.LastName  + ';';
	  							system.debug('Portfolio Account Owner First Name = '+ accCov.Account_Owner__r.FirstName);
	  							system.debug('Portfolio Account Owner Last Name Name = '+ accCov.Account_Owner__r.LastName);
	  						}
	  						else
	  						{
	  							coveragePortfolio = coveragePortfolio + accCov.Account_Owner__r.FirstName + ' ' +  accCov.Account_Owner__r.LastName  + ';';
	   							system.debug('Portfolio Account Owner First Name = '+ accCov.Account_Owner__r.FirstName);
	  							system.debug('Portfolio Account Owner Last Name Name = '+ accCov.Account_Owner__r.LastName); 							
	  						}
	  					}	
	  					if(accCov.Coverage__c == true && accCov.MU__c.contains('Corporate Global'))
	  					{
	  						if(coverageCorporateGlobal == '')
	  						{
	  							coverageCorporateGlobal =  accCov.Account_Owner__r.FirstName + ' ' +  accCov.Account_Owner__r.LastName  + ';';
	  							system.debug('Corp Global Account Owner First Name = '+ accCov.Account_Owner__r.FirstName);
	  							system.debug('Corp Global Account Owner Last Name Name = '+ accCov.Account_Owner__r.LastName);
	  						}
	  						else
	  						{
	  							coverageCorporateGlobal = coverageCorporateGlobal + accCov.Account_Owner__r.FirstName + ' ' +  accCov.Account_Owner__r.LastName  + ';';
	   							system.debug('Corp Global Account Owner First Name = '+ accCov.Account_Owner__r.FirstName);
	  							system.debug('Corp Global Account Owner Last Name Name = '+ accCov.Account_Owner__r.LastName); 							
	  						}
	  					}	  
	  					if(accCov.Coverage__c == true && accCov.MU__c.contains('FGM'))
	  					{
	  						if(coverageFGM == '')
	  						{
	  							coverageFGM =  accCov.Account_Owner__r.FirstName + ' ' +  accCov.Account_Owner__r.LastName  + ';';
	  							system.debug('FGM Account Owner First Name = '+ accCov.Account_Owner__r.FirstName);
	  							system.debug('FGM Account Owner Last Name Name = '+ accCov.Account_Owner__r.LastName);
	  						}
	  						else
	  						{
	  							coverageFGM = coverageFGM + accCov.Account_Owner__r.FirstName + ' ' +  accCov.Account_Owner__r.LastName  + ';';
	   							system.debug('FGM Account Owner First Name = '+ accCov.Account_Owner__r.FirstName);
	  							system.debug('FGM Account Owner Last Name Name = '+ accCov.Account_Owner__r.LastName); 							
	  						}
	  					}		  										  					  						  						  					
	  			}
 			}
  			
  			accountForUpdate.Coverage_Enterprise__c = coverageEnterprise;
  			accountForUpdate.Coverage_IX__c = coverageIX;
  			accountForUpdate.Coverage_BPM__c = coverageBPM;
  			accountForUpdate.Coverage_FGM__c = coverageFGM;
  			accountForUpdate.Coverage_Global__c = coverageCorporateGlobal;
  			accountForUpdate.Coverage_Inside_Sales__c = coverageMarketDevelopment;
  			accountForUpdate.Coverage_Portfolio__c = coveragePortfolio;
  			accountForUpdate.Coverage_Services__c = coverageProfessionalServices;
  		}
  		
  		if(acct.size()>0)
  		{
  			update acct;
  		}																	
  		
  	} 	
 	/*
  	public void onBeforeInsert(Account_Coverage__c[] newAccountCoverage){

    }
    */
    /*
    @future public static void onAfterInsertAsync(Set<ID> newAccountCoverageIDs){

    }
    */
 	
 	public void OnAfterInsert(Account_Coverage__c[] oldAccountCoverage, Account_Coverage__c[] updatedAccountCoverage, Map<ID, Account_Coverage__c> oldAccountCoverageMap) {
		UpdateAccountCoverageInformation(updatedAccountCoverage);  
 	}
	
 	/*
 	public void onBeforeUpdate(Account_Coverage__c[] oldAccountCoverage, Account_Coverage__c[] updatedAccountCoverage, Map<ID, Account_Coverage__c> oldAccountCoverageMap) {
		 
    }
	*/
	
    public void onAfterUpdate(Account_Coverage__c[] oldAccountCoverage, Account_Coverage__c[] updatedAccountCoverage, Map<ID, Account_Coverage__c> oldAccountCoverageMap) {
		UpdateAccountCoverageInformation(updatedAccountCoverage);
    }
	/*
    @future public static void onAfterUpdateAsync(Set<ID> updatedAccountCoverage){
		
    }
    */
    /*
    public void onBeforeDelete(Account_Coverage__c[] AccountCoverageToDelete, Map<ID, Account_Coverage__c> AccountCoverageMap){

    }
    */
    
    public void onAfterDelete(Account_Coverage__c[] deletedAccountCoverage, Map<ID, Account_Coverage__c> AccountCoverageMap){
		UpdateAccountCoverageInformation(deletedAccountCoverage); 
    }
    

    /*
    @future public static void onAfterDeleteAsync(Set<ID> deletedAccountCoverage){
        //to make this work like the on after delete you need to do a select statement into 
        //a list where ID in :deletedOpportunitySplits, this would recreate the deletedOpportunitySplits list
        //from there the code would work the same.
    }
    */

    /*
    public void onUndelete(Account_Coverage__c[] restoredAccountCoverage){

    }
    */

}


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);
   }
  }
}
Hello,

I have a multi picklist called Product Focus which contains 70 products.  Based on the product focus selection I have a trigger which will check off various checkboxes.

I was wondering how I could update my trigger so when a user deselects a product focus from the multi pick list, the corresponding checkbox will be unchecked.
public void getProductFocusValues(Account[] oldAccount, Account[] updatedAccount, Map<ID, Account> oldAccountMap)
	{		
		for(Account acc : updatedAccount)
		{
			List<String> productFocusSplit = new list<String>();
			map<string,string> productFocusPrefix = new map<string,string>();
			if(acc.ProductFocus__c != null)
			{
				productFocusSplit = Util.CleanSplit(acc.ProductFocus__c,';');
			}
			
			if(productFocusSplit.size() > 0)
			{			
				for(string pfs :productFocusSplit)
				{
					system.debug('pfs.substring(0,2)='+pfs.substring(0,2));
					productFocusPrefix.put(pfs.substring(0,2),pfs.substring(0,2));
				}
			}
			if(productFocusPrefix.size()>0)
			{
				for(string pfprefix :productFocusPrefix.keyset())
				{
					if(pfprefix == 'BP')
					{
						acc.BPM__c = true;
					}
					else if(pfprefix == 'CE')
					{
						acc.CEM__c = true;
					}
					else if(pfprefix == 'CL')
					{
						acc.Cloud__c = true;
					}
					else if(pfprefix == 'DI')
					{
						acc.Discovery__c = true;
					}
					else if(pfprefix == 'PO')
					{
						acc.Portfolio__c = true;
					}
					else if(pfprefix == 'EC')
					{
						acc.ECM__c = true;
					}
					else if(pfprefix == 'MS')
					{
						acc.MSFT__c = true;
					}						
					else if(pfprefix == 'SA')
					{
						acc.SAP__c = true;
					}	
					else if(pfprefix == 'IX')
					{
						acc.IX__c = true;
					}	
																					
				}
				
			}
		}
		
	}
Thanks!


Is there a way to pull in permission sets into an apex class? We are looking to restrict the ability for users to click on the submit to finance button (custom JS button on the opportunity page layout).  Creating a new profile and page layout isn't an option for a solution, so I was wondering if there was a way to prevent a user from clicking on this button if they do not belong to a specific permission set.  For example, only our Order Admin team can submit opportunities to Finance - these folks have their own permission set called Order Admins.
Thanks for your help!

Is it possible to automatically submit a specific approval step in an approval process once an opportunity has reached a certain stage?  I'm new to apex so I'm not even sure where to begin.  I've come across the following article http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_process_example.htm but I'm assuming this only works if you have one approval process per object? I'm not too sure how to loop through the approval processes to pick the one I'm trying to use.
Any help would be greatly appreciated.
Thanks!

Is it possible to use a visual flow to send an email to the opportunity owner advising them that there opportunity is closing in x amount of days?  I know you can do this with the standard workflow function but was just curious if this could be replaced with a flow.
When a user clicks on "New Event" from a lead, I would like to populate the campaign field on Events with the campaign that is listed on the Lead Record.  I'm running into an error where it says "Variable does not exist: whoid".  I can't seem to figure out why it would be complaining about whoid when it shows up under Workbench for events.

public with sharing class EventTriggerHandler 
{
	private boolean triggerIsExecuting = false;
    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 EventTriggerHandler(boolean isExecuting, integer size){
    	triggerIsExecuting = isExecuting;
    	BatchSize = size;
  	}
    	
   	public void UpdateLastCampaignActivityOnEvents(Event[] newEvent)
  	{
  		Set<Id> whoIDs = new Set<ID>();
  		for(Event CurrentEvent : newEvent) 
    	{
    		WhoIds.add(CurrentEvent.whoid);
    	}
    	
    	if (whoIDs.size() > 0 )
    	{
    		list<Lead> CurrentLeads = [Select ID, Eloqua_Campaign_Name__c From Lead where ID IN :WhoIDs];
    		
    		map<id,Lead> Leads = new map<id,Lead>();
    		
    		if (currentLeads.size() > 0 )
    		{
    			for (Lead currentlead : currentleads)
    			{
    				Leads.put(currentLead.ID, currentLead);
    			}
    			
    			for(Event CurrentEvent : newEvent) 
		    	{
		    		Lead LeadLookup = Leads.get(CurrentEvent.WhoID); 
		    		if (LeadLookup <> null)
		    		{
		    			CurrentEvent.Last_Campaign_Activity__c = LeadLookup.Eloqua_Campaign_Name__C; 
		    		}
		    	}
    		}
    	}   	

  	}
 	
  	public void onBeforeInsert(Event[] newEvent)
  	{
  		UpdateLastCampaignActivityOnEvents(newEvent);
   	}
   
  
    /*
    @future public static void onAfterInsertAsync(Set<ID> newEventIDs){
    	
    }
    */
 	/*
 	public void OnAfterInsert(Event[] newEvents) {
 		
 		
 	}
 	*/
 	/*
 	public void onBeforeUpdate(Event[] oldEvent, Event[] updatedEvent, Map<ID, Event> oldEventMap) {

    }
    */
 	/*
    public void onAfterUpdate(Event[] oldEvent, Event[] updatedEvent, Map<ID, Event> oldEventMap) {
    		
    }
    */
  	/*  
    @future public static void onAfterUpdateAsync(Set<ID> updatedEvent){
    	
    }
    */
    /*
    public void onBeforeDelete(Event[] EventToDelete, Map<ID, Event> EventMap){
        
    }
    */
    /*
    public void onAfterDelete(Event[] deletedEvent, Map<ID, Event> EventMap){
    			
    }
    */
    
    /*
    @future public static void onAfterDeleteAsync(Set<ID> deletedEvent){
        //to make this work like the on after delete you need to do a select statement into 
        //a list where ID in :deletedOpportunitySplits, this would recreate the deletedOpportunitySplits list
        //from there the code would work the same.
    }
    */
    
    /*
    public void onUndelete(Event[] restoredEvent){
        
    }
    */ 
}


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);
   }
  }
}

Hi,

I am trying to set up a custom button that is called "Log an Event" that mimicks the "Log a call" button. I have the majority of it working and populating properly except for the contact's email address. Please see attached.

I have tried a number of different "tsk" numbers but have been unsuccessful.

This is the formula I currently have in place now:

/00T/e
?what_id={!Account.Id}
&followup=1
&tsk5=Custom Task Name
&retURL=%2F{!Account.Id}
&tsk2={!Contact.Name}

Please help!

Thanks,

Jennifer

User-added image

Hello,

I have a multi picklist called Product Focus which contains 70 products.  Based on the product focus selection I have a trigger which will check off various checkboxes.

I was wondering how I could update my trigger so when a user deselects a product focus from the multi pick list, the corresponding checkbox will be unchecked.
public void getProductFocusValues(Account[] oldAccount, Account[] updatedAccount, Map<ID, Account> oldAccountMap)
	{		
		for(Account acc : updatedAccount)
		{
			List<String> productFocusSplit = new list<String>();
			map<string,string> productFocusPrefix = new map<string,string>();
			if(acc.ProductFocus__c != null)
			{
				productFocusSplit = Util.CleanSplit(acc.ProductFocus__c,';');
			}
			
			if(productFocusSplit.size() > 0)
			{			
				for(string pfs :productFocusSplit)
				{
					system.debug('pfs.substring(0,2)='+pfs.substring(0,2));
					productFocusPrefix.put(pfs.substring(0,2),pfs.substring(0,2));
				}
			}
			if(productFocusPrefix.size()>0)
			{
				for(string pfprefix :productFocusPrefix.keyset())
				{
					if(pfprefix == 'BP')
					{
						acc.BPM__c = true;
					}
					else if(pfprefix == 'CE')
					{
						acc.CEM__c = true;
					}
					else if(pfprefix == 'CL')
					{
						acc.Cloud__c = true;
					}
					else if(pfprefix == 'DI')
					{
						acc.Discovery__c = true;
					}
					else if(pfprefix == 'PO')
					{
						acc.Portfolio__c = true;
					}
					else if(pfprefix == 'EC')
					{
						acc.ECM__c = true;
					}
					else if(pfprefix == 'MS')
					{
						acc.MSFT__c = true;
					}						
					else if(pfprefix == 'SA')
					{
						acc.SAP__c = true;
					}	
					else if(pfprefix == 'IX')
					{
						acc.IX__c = true;
					}	
																					
				}
				
			}
		}
		
	}
Thanks!


Hello,

I'm trying to setup IF statements for my HTML email (not using visualforce).

I put the following code, and it gives me problems:

<p>New test: {!if({!Lead.Campaign_Ran_On__c='True'},{!Lead.Campaign_Ran_On__c},{!Lead.Campaign_Ran_From__c} and {!Lead.Campaign_Ran_To__c})}</p>
Please advise.

1. Is it possible to add a custom button to a detail page without creating a visualforce page?

 

2. I need to create a custom button that will save my case, then go directly to an edit page of a related object to cases.  That will allow users to bypass a step and will remind them to add information required for the case.  How do I do this?

 

Thank you

 

 

 

  • September 16, 2009
  • Like
  • 0