• Bryan Cerrati
  • NEWBIE
  • 35 Points
  • Member since 2016


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 14
    Replies
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. 
Trying to add an html signature from each user to the templates. 

i have a feild provided by jungo thats just a rich text field so that i can paste a rich text signature including images... but they are formatted horribly so i would like to have a html signature placed on each users profile and either write templates to merge and compile the html in a letter head form, or add a comment in each html for apex to seek out and replace with html before it is sent, now im just not sure if say i sent a mass email am i able to catch the email before being sent and add the replacement html before each email is sent out? if so is there any examples anyone can show me of this being don?
i have a class and trigger that takes a string from a custom field on an account that it is associated with a custom object "Wholesale Pipeline" and places the account name into the account lookup field in the custom object. 
 
public with sharing class addNMLSPipeline 
{
	public void addNMLS(List<Wholesale_Pipeline__c> lstPipeline)
	{
		addNMLSPrivate(lstPipeline);
	}
	private void addNMLSPrivate(List<Wholesale_Pipeline__c> lstPipeline)
	{
		Set<String> accId = new Set<String>();
		for(Wholesale_Pipeline__c accloop : lstPipeline)
			accId.add(accloop.NMLS__c);
		List<Account> lstAcc = new List<Account>([SELECT Id, Name, NMLS_Number__c FROM Account WHERE NMLS_Number__c =: accId LIMIT 1]);
		for(Account accloop2 : lstAcc)
		{
			for(Wholesale_Pipeline__c pipe : lstPipeline)
				if(pipe.NMLS__c != null)
					pipe.Account__c = accloop2.Id;
		}
	}
}

when i update the pipeline object records with a nmls using the data loader i get about 200 records succeed and 800 fail saying "Apex CPU time limit exceeded"

can someone please help me, i have looked at a million links and even other posts that deal with similar problems but dont seem to understand where i have gone wrong. 
 
Upon update of a date field on an Account, i would like all contacts that have the checkbox "Admin Contact" selected to update the same date field. 

i cannot see what i am doing wrong. i have looked up every single post and help forum i can find. documentation does not help. please dont post links, im sure ive seen it. 

tell me how i can get this to actually fire? 

Class:
public with sharing class AdminUsersAccount
{
	public void leadAlerts(List<Account> lstAcct)
	{
		sendAlertsPrivate(lstAcct);
	}

	private void sendAlertsPrivate(List<Account> lstAcct)
	{
		List<Contact> lstUpdateCon = new List<Contact>();
		map<Id, Contact> conMap = new map<Id, Contact>();
		for(Account a : lstAcct)
			conMap.put(a.Id, null);
		conMap.remove(null);
		conMap.putAll([SELECT Id, Admin_User__c, Account_Expiration__c FROM Contact WHERE Admin_User__c = true AND AccountId In : conMap.keySet()]);
		for(Account acc : lstAcct)
		{	
			if(conMap.containsKey(acc.Id))
			{
				if(acc.Approved_Date__c != null)
				{
					Date tdy = date.today();
					Date expire = acc.Approved_Date__c.addDays(365);
					boolean approved = expire >= tdy;
					lstUpdateCon.add(new Contact(Account_Expiration__c = approved?conMap.get(acc.Id).Account_Expiration__c: null));
				}
				else
				{
					lstUpdateCon.add(new Contact(Account_Expiration__c = null));
				}
			}
		}
		if(!lstUpdateCon.isEmpty())
			update lstUpdateCon;		
	}
}

 
i am trying to update a date field on my contacts that are marked as "admin Contacts" everytime a matching date field on my accounts are updated. 

Class:
public with sharing class AdminUsersAccount
	{
		public void leadAlerts(List<Account> lstAcct)
		{
			sendAlertsPrivate(lstAcct);
		}
	
		private void sendAlertsPrivate(List<Account> lstAcct)
		{
			List<Contact> lstUpdateCon = new List<Contact>();
			
			Set<Id> accID = new Set<Id>();
			for (Account a : lstAcct)
				accID.add(a.Id);	
			map<Id, Contact> conMap = new map<Id, Contact>([SELECT Id, Admin_User__c, Account_Expiration__c FROM Contact WHERE Admin_User__c = true AND AccountId IN :accID]);
	
			for(Account acc : lstAcct)
			{	
				
				if(conMap.containsKey(acc.Id))
				{
					if(acc.Approved_Date__c != null)
					{
						Date tdy = date.today();
						Date expire = acc.Approved_Date__c.addDays(365);
						boolean approved = expire >= tdy;
						lstUpdateCon.add(new Contact(Account_Expiration__c = approved?conMap.get(acc.Id).Account_Expiration__c: null));
					}
					else
					{
						lstUpdateCon.add(new Contact(Account_Expiration__c = null));
					}
				}
			}
			if(!lstUpdateCon.isEmpty())
				update lstUpdateCon;		
		}
	}

Trigger:
 
trigger AdminUsersAccountTrigger on Account (after update) 
	{
		AdminUsersAccount objAcctHandler = new AdminUsersAccount();
		
		if (Trigger.IsUpdate)
		{
			objAcctHandler.leadAlerts(Trigger.New);
		}
	    
	}

im really not sure where this is going wrong... i get no errors but nothing happens when updating the field on the account. 
hello there. with the help of Nayana K and the developer community here. i wrote a class to send 2 diffrent sets of emails based on when they are recieved. one set is between the hours of 6pm to 8.59am EST and the other email is sent at 9am to 5.59pm EST. it is 100% working but i have been having trouble using the setCreateDate inside the test class it doesnt seem to be firing within the times i set. 

heres the if statement that does not fire. 
 
if(objLead.CreatedDate.hour() >= 18 || objLead.CreatedDate.hour() <= 8)

no code below this gets covered but everything in the else gets covered. 

here are my tests
 
@isTest 
private class jungoLeadFollowupTest 
{

	@isTest static void zillowNull() 
	{
		Time myTime = Time.newInstance(12, 0, 0, 0);
		Date myDate = Date.newInstance(2016, 10, 5);
		DateTime dt = DateTime.newInstance(myDate, myTime);		
		JungoLeadsFrc__JungoLeads__c newLead = new JungoLeadsFrc__JungoLeads__c(
		JungoLeadsFrc__Zillow_Recipient_Email__c = null);
		insert newLead;
		Test.setCreatedDate(newLead.Id, dt);
		
	}
	
	@isTest static void zillowNotNull()
	{
		Time myTime = Time.newInstance(12, 0, 0, 0);
		Date myDate = Date.newInstance(2016, 10, 4);
		DateTime dt = DateTime.newInstance(myDate, myTime);
		JungoLeadsFrc__JungoLeads__c newLead = new JungoLeadsFrc__JungoLeads__c(
		JungoLeadsFrc__Zillow_Recipient_Email__c ='jfrangoulis@unitedmortgage.com');
		insert newLead;
		Test.setCreatedDate(newLead.Id, dt);		
		
	}
	@isTest static void afterHourEmailNotNull()
	{
		Time myTime = Time.newInstance(24, 0, 0, 0);
		Date myDate = Date.newInstance(2016, 10, 4);
		DateTime dt = DateTime.newInstance(myDate, myTime);
		JungoLeadsFrc__JungoLeads__c newLead = new JungoLeadsFrc__JungoLeads__c(
		JungoLeadsFrc__Zillow_Recipient_Email__c ='jfrangoulis@unitedmortgage.com',
		JungoLeadsFrc__EmailAddress__c = null);
		//newLead.setCreatedDate(newLead.Id, dt);
		insert newLead;
		Test.setCreatedDate(newLead.Id, dt);
	}
	
		@isTest static void emailnull()
	{
		Time myTime = Time.newInstance(24, 0, 0, 0);
		Date myDate = Date.newInstance(2016, 10, 4);
		DateTime dt = DateTime.newInstance(myDate, myTime);
		JungoLeadsFrc__JungoLeads__c newLead = new JungoLeadsFrc__JungoLeads__c(
		JungoLeadsFrc__EmailAddress__c = 'jfrangoulis@unitedmortgage.com',
		JungoLeadsFrc__Zillow_Recipient_Email__c = null);
		insert newLead;
		Test.setCreatedDate(newLead.Id, dt);
		
	}

}

 
hey guys im very new to programming in general, i dont know advanced techniques or anything but you all seem so generous and helpful so i thought id give it a shot. ok so here we go... i have a custom object that is a lead recieving platform from jungo. i need to write a trigger for leads that come in after buisness hours to send a specific message. i didnt see a way for the point and click tools to diferentiate the date from the time. it doesnt matter the date the leads will be coming in every day and all days. but leads that come in after 6pm est i woulld like to send specific messages and set specific tasks. 

i came to the conclusion that (i may be wrong and doing a terrible job) i would need to convert the datetime field of CreatedDate to a string, then use substringAfter(' ') to get just the time as a string. then from there i can use basic operators to compare to after hours times. 

i created a class with a method for just adding the time as a string to a field i created called time__c 

im not sure what i am doing wrong, so any advice will help 
 
public with sharing class timingClass 
{
	public static void createTimeStamp()
	{
		List<JungoLeadsFrc__JungoLeads__c> dateAndTime = [SELECT Id, CreatedDate, Time__c from JungoLeadsFrc__JungoLeads__c];
		
		
		for (JungoLeadsFrc__JungoLeads__c lead : dateAndTime)
		{
			String dateNtime = string.valueof(dateAndTime.CreatedDate);
			String s2 = dateNtime.substringBefore(' ');
			lead.Time = s2;
		}
		
		update dateAndTime;
	}
	
}

i am obviously going to have to create this as a after trigger but i am literally trying to get a feel for how salesforce works, and like i said before i know absolutly nothing about coding. 
i have a class and trigger that takes a string from a custom field on an account that it is associated with a custom object "Wholesale Pipeline" and places the account name into the account lookup field in the custom object. 
 
public with sharing class addNMLSPipeline 
{
	public void addNMLS(List<Wholesale_Pipeline__c> lstPipeline)
	{
		addNMLSPrivate(lstPipeline);
	}
	private void addNMLSPrivate(List<Wholesale_Pipeline__c> lstPipeline)
	{
		Set<String> accId = new Set<String>();
		for(Wholesale_Pipeline__c accloop : lstPipeline)
			accId.add(accloop.NMLS__c);
		List<Account> lstAcc = new List<Account>([SELECT Id, Name, NMLS_Number__c FROM Account WHERE NMLS_Number__c =: accId LIMIT 1]);
		for(Account accloop2 : lstAcc)
		{
			for(Wholesale_Pipeline__c pipe : lstPipeline)
				if(pipe.NMLS__c != null)
					pipe.Account__c = accloop2.Id;
		}
	}
}

when i update the pipeline object records with a nmls using the data loader i get about 200 records succeed and 800 fail saying "Apex CPU time limit exceeded"

can someone please help me, i have looked at a million links and even other posts that deal with similar problems but dont seem to understand where i have gone wrong. 
 
i am trying to update a date field on my contacts that are marked as "admin Contacts" everytime a matching date field on my accounts are updated. 

Class:
public with sharing class AdminUsersAccount
	{
		public void leadAlerts(List<Account> lstAcct)
		{
			sendAlertsPrivate(lstAcct);
		}
	
		private void sendAlertsPrivate(List<Account> lstAcct)
		{
			List<Contact> lstUpdateCon = new List<Contact>();
			
			Set<Id> accID = new Set<Id>();
			for (Account a : lstAcct)
				accID.add(a.Id);	
			map<Id, Contact> conMap = new map<Id, Contact>([SELECT Id, Admin_User__c, Account_Expiration__c FROM Contact WHERE Admin_User__c = true AND AccountId IN :accID]);
	
			for(Account acc : lstAcct)
			{	
				
				if(conMap.containsKey(acc.Id))
				{
					if(acc.Approved_Date__c != null)
					{
						Date tdy = date.today();
						Date expire = acc.Approved_Date__c.addDays(365);
						boolean approved = expire >= tdy;
						lstUpdateCon.add(new Contact(Account_Expiration__c = approved?conMap.get(acc.Id).Account_Expiration__c: null));
					}
					else
					{
						lstUpdateCon.add(new Contact(Account_Expiration__c = null));
					}
				}
			}
			if(!lstUpdateCon.isEmpty())
				update lstUpdateCon;		
		}
	}

Trigger:
 
trigger AdminUsersAccountTrigger on Account (after update) 
	{
		AdminUsersAccount objAcctHandler = new AdminUsersAccount();
		
		if (Trigger.IsUpdate)
		{
			objAcctHandler.leadAlerts(Trigger.New);
		}
	    
	}

im really not sure where this is going wrong... i get no errors but nothing happens when updating the field on the account. 
hello there. with the help of Nayana K and the developer community here. i wrote a class to send 2 diffrent sets of emails based on when they are recieved. one set is between the hours of 6pm to 8.59am EST and the other email is sent at 9am to 5.59pm EST. it is 100% working but i have been having trouble using the setCreateDate inside the test class it doesnt seem to be firing within the times i set. 

heres the if statement that does not fire. 
 
if(objLead.CreatedDate.hour() >= 18 || objLead.CreatedDate.hour() <= 8)

no code below this gets covered but everything in the else gets covered. 

here are my tests
 
@isTest 
private class jungoLeadFollowupTest 
{

	@isTest static void zillowNull() 
	{
		Time myTime = Time.newInstance(12, 0, 0, 0);
		Date myDate = Date.newInstance(2016, 10, 5);
		DateTime dt = DateTime.newInstance(myDate, myTime);		
		JungoLeadsFrc__JungoLeads__c newLead = new JungoLeadsFrc__JungoLeads__c(
		JungoLeadsFrc__Zillow_Recipient_Email__c = null);
		insert newLead;
		Test.setCreatedDate(newLead.Id, dt);
		
	}
	
	@isTest static void zillowNotNull()
	{
		Time myTime = Time.newInstance(12, 0, 0, 0);
		Date myDate = Date.newInstance(2016, 10, 4);
		DateTime dt = DateTime.newInstance(myDate, myTime);
		JungoLeadsFrc__JungoLeads__c newLead = new JungoLeadsFrc__JungoLeads__c(
		JungoLeadsFrc__Zillow_Recipient_Email__c ='jfrangoulis@unitedmortgage.com');
		insert newLead;
		Test.setCreatedDate(newLead.Id, dt);		
		
	}
	@isTest static void afterHourEmailNotNull()
	{
		Time myTime = Time.newInstance(24, 0, 0, 0);
		Date myDate = Date.newInstance(2016, 10, 4);
		DateTime dt = DateTime.newInstance(myDate, myTime);
		JungoLeadsFrc__JungoLeads__c newLead = new JungoLeadsFrc__JungoLeads__c(
		JungoLeadsFrc__Zillow_Recipient_Email__c ='jfrangoulis@unitedmortgage.com',
		JungoLeadsFrc__EmailAddress__c = null);
		//newLead.setCreatedDate(newLead.Id, dt);
		insert newLead;
		Test.setCreatedDate(newLead.Id, dt);
	}
	
		@isTest static void emailnull()
	{
		Time myTime = Time.newInstance(24, 0, 0, 0);
		Date myDate = Date.newInstance(2016, 10, 4);
		DateTime dt = DateTime.newInstance(myDate, myTime);
		JungoLeadsFrc__JungoLeads__c newLead = new JungoLeadsFrc__JungoLeads__c(
		JungoLeadsFrc__EmailAddress__c = 'jfrangoulis@unitedmortgage.com',
		JungoLeadsFrc__Zillow_Recipient_Email__c = null);
		insert newLead;
		Test.setCreatedDate(newLead.Id, dt);
		
	}

}

 
hey guys im very new to programming in general, i dont know advanced techniques or anything but you all seem so generous and helpful so i thought id give it a shot. ok so here we go... i have a custom object that is a lead recieving platform from jungo. i need to write a trigger for leads that come in after buisness hours to send a specific message. i didnt see a way for the point and click tools to diferentiate the date from the time. it doesnt matter the date the leads will be coming in every day and all days. but leads that come in after 6pm est i woulld like to send specific messages and set specific tasks. 

i came to the conclusion that (i may be wrong and doing a terrible job) i would need to convert the datetime field of CreatedDate to a string, then use substringAfter(' ') to get just the time as a string. then from there i can use basic operators to compare to after hours times. 

i created a class with a method for just adding the time as a string to a field i created called time__c 

im not sure what i am doing wrong, so any advice will help 
 
public with sharing class timingClass 
{
	public static void createTimeStamp()
	{
		List<JungoLeadsFrc__JungoLeads__c> dateAndTime = [SELECT Id, CreatedDate, Time__c from JungoLeadsFrc__JungoLeads__c];
		
		
		for (JungoLeadsFrc__JungoLeads__c lead : dateAndTime)
		{
			String dateNtime = string.valueof(dateAndTime.CreatedDate);
			String s2 = dateNtime.substringBefore(' ');
			lead.Time = s2;
		}
		
		update dateAndTime;
	}
	
}

i am obviously going to have to create this as a after trigger but i am literally trying to get a feel for how salesforce works, and like i said before i know absolutly nothing about coding.