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
Bryan CerratiBryan Cerrati 

Cross-Object oldMap

i have a class that updates accounts "Tier" based on how many items they have in pipeline and if they are older then a year. 

i would like the trigger to not fire if the tier on the account is already in that status to not update it again. 

i am getting chatter feed tracking items "Tier has changed from Platinum to Platinum. 
 
public with sharing class accountTiers 
{
	public void addTier(List<Wholesale_Pipeline__c> lstPipeline)
	{
		addTierPrivate(lstPipeline);
	}

	private void addTierPrivate(List<Wholesale_Pipeline__c> lstPipeline)
	{
		//Setting Date Variables
		Date zoday = Date.today();
		Integer oneYear = zoday.year() - 1;
		Integer oneMonth = zoday.month();
		Integer oneDay = zoday.day();
		Date oneYearFromToday = date.newInstance(oneYear, oneMonth, oneDay);
		
		//getting ids
		Set<Id> pipeId = new Set<Id>();
		for(Wholesale_Pipeline__c pipeIds : lstPipeline)
			pipeId.add(pipeIds.Account__c);
		List<Account> accts = new list<Account>([SELECT Id, Tier__c FROM Account WHERE Id = : pipeId]);
		List<Wholesale_Pipeline__c> amntAccount = new List<Wholesale_Pipeline__c>([SELECT Id, Closed_Date__c FROM Wholesale_Pipeline__c WHERE Account__c =: pipeId]);
		
		//dedupe list to update
		List<Account> lstToUpdate = new List<Account>();
		Set<Account> dedupe = new Set<Account>();
		List<Account> detwo = new List<Account>();
		
		//this year or last yeas accounts
		List<Wholesale_Pipeline__c> currentPipeline = new List<Wholesale_Pipeline__c>();
		List<Wholesale_Pipeline__c> previousPipeline = new List<Wholesale_Pipeline__c>();
		
	
		//mapping for old account
		Boolean areChangesMade = null;
		
		//old account
		Account oldAcc = new Account();
		
		
		
		for(Wholesale_Pipeline__c loopPipe : amntAccount)
		{
			if(loopPipe.Closed_Date__c != null)
			{
				if(loopPipe.Closed_Date__c > oneYearFromToday)
					currentPipeline.add(loopPipe);
				else
					previousPipeline.add(loopPipe);
			}
		
		{

			
			oldAcc = (Account)Trigger.oldMap.get(acc.Id);

			for(Wholesale_Pipeline__c timeLoop : amntAccount)
			{
				if(currentPipeline.size() >= 3)
				{
					acc.Tier__c = 'Platinum';
					lstToUpdate.add(acc);
				}
				else if(currentPipeline.size() >= 1)
				{
					acc.Tier__c = 'Gold';
					lstToUpdate.add(acc);
				}
				else if(previousPipeline.size() >= 3 && currentPipeline.isEmpty())
				{
					acc.Tier__c = 'Silver';
					lstToUpdate.add(acc);
				}
				else if(previousPipeline.size() >=1 && currentPipeline.isEmpty())
				{
					acc.Tier__c = 'Bronze';
					lstToUpdate.add(acc);
				}
				else if(previousPipeline.isEmpty() && currentPipeline.isEmpty())
				{
					acc.Tier__c = null;
					lstToUpdate.add(acc);
				}
			}
		}
		
		
	
		for(Account accChangeLoop : lstToUpdate)
		{
			Boolean accTierChange = null;
			if(oldAcc != null)
			{
				string oldTier = oldAcc.Tier__c;
				string newTier = accChangeLoop.Tier__c;
				accTierChange = newTier.equals(oldTier);
				if(!accTierChange)
					areChangesMade = true;
				else
					areChangesMade = false;
			}
		}
		
		if(!lstToUpdate.isEmpty())
		{
			if(areChangesMade != null)
			{
				if(areChangesMade)
				{
					dedupe.addAll(lstToUpdate);
					detwo.addAll(dedupe);
					update detwo;
				}
			}
		}

	}
}





i dont think the account oldAcc is populating, and it breaks out of the loop before it is populated.