function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Christine KleinChristine Klein 

Help with Account Trigger

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!


Best Answer chosen by Christine Klein
Navees AhmedNavees Ahmed
//after line 21 get rid of for loop and use below logic fro all products
if(productFocusPrefix.size()>0)
{
    acc.BPM__c=ProductFocusPreFix.containsKey('BP')?true:false;
    acc.CEM__c=ProductFocusPreFix.containsKey('CE')?true:false;
.....
}

All Answers

Navees AhmedNavees Ahmed
//after line 21 get rid of for loop and use below logic fro all products
if(productFocusPrefix.size()>0)
{
    acc.BPM__c=ProductFocusPreFix.containsKey('BP')?true:false;
    acc.CEM__c=ProductFocusPreFix.containsKey('CE')?true:false;
.....
}

This was selected as the best answer
Navees AhmedNavees Ahmed
you can get rid of if conditon which is checking map size. because map is already initialized and logic I provided above will work fine if map is empty
Christine KleinChristine Klein
Thanks so much for your help.  Works like a charm! :)