-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
11Questions
-
12Replies
Trouble with scheduled apex
Hello,
I'm having some trouble getting scheduled Apex classes to run consistently and correctly.
I have one that sends out emails every morning to clients who have meetings in 2 days. This class is scheduled to run every morning (including the weekends). Is there any reason it would run for a few days and then just stop? If it experiences an exception, does that then prevent it from running the following day? Do they run on weekends? I have yet to see one run on the weekends, but that may just be a coincidence. In the list of scheduled classes, it always says that they run, but no emails are being sent...
The second scheduled class I have is supposed to update all contacts and, in turn, trigger my Contact update triggers. This class seems to be running correctly, but none of the Contact onUpdate triggers are running correctly. However, when I edit an individual Contact, the triggers run correctly.
I'm having some trouble getting scheduled Apex classes to run consistently and correctly.
I have one that sends out emails every morning to clients who have meetings in 2 days. This class is scheduled to run every morning (including the weekends). Is there any reason it would run for a few days and then just stop? If it experiences an exception, does that then prevent it from running the following day? Do they run on weekends? I have yet to see one run on the weekends, but that may just be a coincidence. In the list of scheduled classes, it always says that they run, but no emails are being sent...
The second scheduled class I have is supposed to update all contacts and, in turn, trigger my Contact update triggers. This class seems to be running correctly, but none of the Contact onUpdate triggers are running correctly. However, when I edit an individual Contact, the triggers run correctly.
- Sean Barczynski
- September 25, 2017
- Like
- 0
Task not getting created, email not sending, other piece of IF statement firing
Good afternoon,
I'm struggling with some code that I wrote not producing the results I'm looking for. The section I want to focus on is the creation of the Scan Tax Docs task. When I check the box for Tax Docs Received and hit save, the test email is not being sent (the others in the else statements are sent when applicable) and the task is not being created, but the box for Scan Tax Docs Task Created is being checked (I confirmed that this is the line that is checking this box - I commented it out and it stopped getting checked).
Please help! Thanks in advance...
I'm struggling with some code that I wrote not producing the results I'm looking for. The section I want to focus on is the creation of the Scan Tax Docs task. When I check the box for Tax Docs Received and hit save, the test email is not being sent (the others in the else statements are sent when applicable) and the task is not being created, but the box for Scan Tax Docs Task Created is being checked (I confirmed that this is the line that is checking this box - I commented it out and it stopped getting checked).
Please help! Thanks in advance...
trigger TaxServiceBeforeUpdate on Tax_Services__c (before update) { Set <Id> WhatIdSet = new Set <Id> (); for(Tax_Services__c t : trigger.new) { if(t.Business_Account__c != NULL) { WhatIdSet.add(t.Business_Account__c); } } List<User> userList = [select id, Name, Email, Title, CompanyName, Phone from User]; List<Contact> contactList = [select Id, Name, AccountId, Email, FirstName, ACTDDEV__Nickname__c, Include_on_Correspondence__c, Primary__c from Contact Where AccountId in :WhatIdSet]; List<Task> serviceTaskList = [select Id, Subject, Status, WhatID, ActivityDate, Hidden__c from Task Where WhatId in :WhatIdSet and Subject = 'URGENT! Request Tax Docs from Client']; List<OrgWideEmailAddress> owaList = [select id, DisplayName, Address from OrgWideEmailAddress]; String taxPlanning = Schema.SObjectType.Tax_Services__c.getRecordTypeInfosByName().get('Tax Planning').getRecordTypeId(); String taxPrep = Schema.SObjectType.Tax_Services__c.getRecordTypeInfosByName().get('Tax Prep').getRecordTypeId(); List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>(); List <Task> TasksToCreate = new List <Task> (); List <Task> tasksToUpdate = new List <Task> (); String greeting; String email; String newBody2; String PrimaryTaxPayer; String SecondaryTaxPayer; String TaxPayers; List <String> emailAddresses = new List <String> (); User sinkrote; User sdonatelli; User TA; OrgWideEmailAddress owa; for(Tax_Services__c e : Trigger.new) { Tax_Services__c oldservice = Trigger.oldMap.get(e.ID); /*********************************************************************** * * Determining values for numerous pieces of vital information: * Tax Advisor * Tax Admin * Names of Tax Payers * ***********************************************************************/ for(Integer u=0;u<=userList.size()-1;u++) { for(Integer o=0;o<=owaList.size()-1;o++) { if(userList[u].Id == e.Tax_Advisor__c && userList[u].Email == owaList[o].Address) { owa = owaList[o]; TA = userList[u]; } } if(userList[u].Email == 'sd****mg.com') sdonatelli = userList[u]; if(userList[u].Email == 'si****mg.com') sinkrote = userList[u]; } for(Integer c=0; c<=contactList.size()-1; c++) { if(e.Business_Account__c == contactList[c].AccountId && contactList[c].Include_on_Correspondence__c && contactList[c].Email != NULL) { emailAddresses.add(contactList[c].Email); if(contactList[c].ACTDDEV__Nickname__c != NULL) greeting = contactList[c].ACTDDEV__Nickname__c; else greeting = contactList[c].FirstName; } if(e.Tax_Payer_1__c == contactList[c].Id) PrimaryTaxPayer = contactList[c].Name; if(e.Tax_Payer_2__c == contactList[c].Id) SecondaryTaxPayer = contactList[c].Name; } if(SecondaryTaxPayer != NULL) TaxPayers = PrimaryTaxPayer + ' & ' + SecondaryTaxPayer; else TaxPayers = PrimaryTaxPayer; /*********************************************************************** * * Tax Prep Workflow * ***********************************************************************/ if(e.RecordTypeId == taxPrep) { /* Updating Status */ if(e.Client_Lost__c) e.Status2__c = 'Client Lost'; if(e.Tax_Docs_Received__c == TRUE && e.Tax_Docs_Scanned__c == FALSE) { if(e.Tax_Docs_Received__c != oldservice.Tax_Docs_Received__c || e.Tax_Docs_Scanned__c != oldservice.Tax_Docs_Scanned__c) { e.Status2__c = 'Docs Received'; e.Status_Date__c = system.Today(); e.Tax_Docs_Received_Date__c = system.Today(); } } if(e.Tax_Docs_Received__c == TRUE && e.Tax_Docs_Scanned__c == TRUE) { if(e.Tax_Docs_Received__c != oldservice.Tax_Docs_Received__c && e.Tax_Docs_Scanned__c != oldservice.Tax_Docs_Scanned__c) { e.Status2__c = 'Docs Scanned'; e.Status_Date__c = system.Today(); e.Tax_Docs_Scanned_Date__c = system.Today(); } if(e.Tax_Docs_Received__c != oldservice.Tax_Docs_Received__c) e.Tax_Docs_Received_Date__c = system.Today(); } if(e.X8879_Given_to_Client__c && oldservice.X8879_Given_to_Client__c != e.X8879_Given_to_Client__c) { e.Status2__c = 'Waiting for 8879'; e.Status_Date__c = system.Today(); } if(e.Return_Filed__c && oldservice.Return_Filed__c != e.Return_Filed__c) { e.Status2__c = 'Filed'; e.Status_Date__c = system.Today(); } if(e.TARCT_Return_Locked_Completed__c && oldservice.TARCT_Return_Locked_Completed__c != e.TARCT_Return_Locked_Completed__c) { e.Status2__c = 'Final'; e.Status_Date__c = system.Today(); e.Tax_Return_Closed_Date__c = system.Today(); } /* Creating Tasks */ if(e.Tax_Docs_Received__c && !e.Tax_Docs_Scanned__c && !e.Scan_Tax_Docs_Task_Created__c) { if(e.Tax_Docs_Received__c != oldservice.Tax_Docs_Received__c || e.Tax_Docs_Scanned__c != oldservice.Tax_Docs_Scanned__c) { Messaging.SingleEmailMessage mail2 = new Messaging.SingleEmailMessage(); String[] toAddresses = new String[] {emailAddresses[0]}; mail2.setOrgWideEmailAddressId(owa.Id); mail2.setToAddresses(toAddresses); mail2.setSubject('Test 1'); String body2 = 'Hi ' + greeting + ','; mail2.setHtmlBody(body2); mails.add(mail2); Date ScanDocsDueDate = Date.today(); if(e.On_Extension__c) ScanDocsDueDate = Date.newInstance(Date.today().year(),4,18); else ScanDocsDueDate = Date.today(); TasksToCreate.add(new Task(OwnerID = sinkrote.Id, Subject = 'Scan Tax Docs', WhatID = e.Id, ActivityDate = ScanDocsDueDate, Status = 'Not Started', Priority = 'Normal', Category__c = 'Client/Prospect Work', Hidden__c = 'Scan Tax Docs')); e.Scan_Tax_Docs_Task_Created__c = TRUE; } else { Messaging.SingleEmailMessage mail2 = new Messaging.SingleEmailMessage(); String[] toAddresses = new String[] {emailAddresses[0]}; mail2.setOrgWideEmailAddressId(owa.Id); mail2.setToAddresses(toAddresses); mail2.setSubject('Test 2'); String body2 = 'Hi ' + greeting + ','; mail2.setHtmlBody(body2); mails.add(mail2); } } else { Messaging.SingleEmailMessage mail2 = new Messaging.SingleEmailMessage(); String[] toAddresses = new String[] {emailAddresses[0]}; mail2.setOrgWideEmailAddressId(owa.Id); mail2.setToAddresses(toAddresses); mail2.setSubject('Test 3'); String body2 = 'Hi ' + greeting + ','; mail2.setHtmlBody(body2); mails.add(mail2); } if(e.Tax_Docs_Received__c && e.Tax_Docs_Scanned__c && !e.Complete_Tax_Return_Task_Created__c && e.Tax_Docs_Scanned__c != oldservice.Tax_Docs_Scanned__c) { Date CompleteReturnDueDate; if(e.Tax_Prep_Meeting_Date__c != NULL) { if(e.Tax_Prep_Meeting_Date__c.addDays(-7) < system.Today()) CompleteReturnDueDate = system.Today(); else CompleteReturnDueDate = e.Tax_Prep_Meeting_Date__c.addDays(-7); } else { if(e.On_Extension__c) CompleteReturnDueDate = date.newInstance(date.today().year(),4,18); else CompleteReturnDueDate = system.Today().addDays(10); } TasksToCreate.add(new Task(OwnerID = e.Tax_Preparer__c, Subject = 'Complete Tax Return', WhatID = e.Id, WhoId = e.Tax_Payer_1__c, ActivityDate = CompleteReturnDueDate, Status = 'Not Started', Description = 'Please prepare tax return. Marking this complete will create a task for the Tax Advisor to review the return.', Priority = 'Normal', Hidden__c = 'Complete Tax Return')); e.Complete_Tax_Return_Task_Created__c = TRUE; } if(!e.Review_Tax_Return_Task_Created__c && e.Complete_Tax_Return_Task_Completed__c && e.Complete_Tax_Return_Task_Completed__c != oldservice.Complete_Tax_Return_Task_Completed__c) { Date ReviewReturnDueDate; if(e.Tax_Prep_Meeting_Date__c == NULL) { ReviewReturnDueDate = system.Today(); } else { if(e.Tax_Prep_Meeting_Date__c.addDays(-2) < system.Today()) { ReviewReturnDueDate = system.Today(); } else { ReviewReturnDueDate = e.Tax_Prep_Meeting_Date__c.addDays(-2); } } TasksToCreate.add(new Task(OwnerID = e.Tax_Advisor__c, Subject = 'Review Tax Return', WhatID = e.Id, WhoId = e.Tax_Payer_1__c, ActivityDate = ReviewReturnDueDate, Description = 'Mark this task complete once it has been reviewed with and approved by the client.', Status = 'Not Started', Priority = 'Normal', Category__c = 'Client/Prospect Work', Hidden__c = 'Review Tax Return')); e.Review_Tax_Return_Task_Created__c = TRUE; e.In_Review__c = True; e.Status2__c = 'In Review'; e.Status_Date__c = system.Today(); } if(!e.Close_Return_Task_Created__c && e.Review_Tax_Return_Task_Completed__c) { TasksToCreate.add(new Task(OwnerID = sinkrote.Id, Subject = 'Close Tax Return', WhatID = e.Id, WhoId = e.Tax_Payer_1__c, ActivityDate = system.Today(), Description = 'Perform closing tasks for tax return. Please ensure the appropriate items are checked on the Tax Service before marking this task complete.', Status = 'Not Started', Priority = 'Normal', Category__c = 'Client/Prospect Work', Hidden__c = 'Close Tax Return')); e.Close_Return_Task_Created__c = True; e.Completed_Status__c = TRUE; e.Tax_Return_Reviewed_Date__c = system.Today(); e.Status2__c = 'Completed'; e.Status_Date__c = system.Today(); e.Tax_Return_Complete_Date__c = system.Today(); } if(!e.Invoice_Client_Task_Created__c && e.Review_Tax_Return_Task_Completed__c && e.Client_Needs_to_be_Invoiced__c && !e.Invoice_Given_to_Client__c) { TasksToCreate.add(new Task(OwnerID = sdonatelli.Id, Subject = 'Invoice Client', WhatID = e.Id, WhoId = e.Tax_Payer_1__c, ActivityDate = system.Today(), Description = '', Status = 'Not Started', Priority = 'Normal', Category__c = 'Client/Prospect Work', Hidden__c = 'Invoice Client')); e.Invoice_Client_Task_Created__c = TRUE; } if(e.Tax_Docs_Received__c && serviceTaskList != null && serviceTaskList.size()>0) { for(Integer t=0;t<serviceTaskList.size();t++) { if(serviceTaskList[t].WhatId == e.Business_Account__c) { serviceTaskList[t].Status = 'Canceled'; tasksToUpdate.add(serviceTaskList[t]); } } } } } try { if(TasksToCreate.size()>0) insert TasksToCreate; if(tasksToUpdate.size()>0) update tasksToUpdate; if(mails.size()>0) Messaging.sendEmail(mails); } catch (System.DmlException ex) { System.Debug (ex); } }
- Sean Barczynski
- February 08, 2017
- Like
- 0
Visual Workflow Send Email Failing
I am trying to build a Visual Workflow and I like to send myself emails at the different stages of development so I can make sure it's doing what I want it to do. I have started a very simple one (for now) with 2 Fast Lookups and a Send Email. I receive the two emails below whenever I try to force it to run providing details of the error that occurs. It is autolaunched whenever a custom object record is created. The Send Email piece seems to be what is causing the issue, but I don't know why; if I delete the Send Email piece, it works with no errors.
-----
Sandbox: Error Occurred During Flow "Tax_Prep_Service_Update": The flow failed to access the value for varTaxPayer1...
This report lists the elements that the flow interview executed. The report is a beta feature.
We welcome your feedback on IdeaExchange.
Flow Details
Flow Name: Tax_Prep_Service_Update
Type: Autolaunched Flow
Version: 9
Status: Active
Flow Interview Details
Interview Label: Tax Prep Service Update 12/9/2016 3:54 PM
Current User: Sean Barczynski (00537000000ahJS)
Start time: 12/9/2016 3:54 PM
Duration: 0 seconds
How the Interview Started
Sean Barczynski (00537000000ahJS) started the flow interview.
Some of this flow's variables were set when the interview started.
varTaxService = a2C210000000i7CEAQ
FAST LOOKUP: Fast_Lookup_Tax_Payer_1
Find all Contact records where:
Id Equals {!varTaxService.Tax_Payer_1__c} (0032100000FHUJBAA5)
Assign those records to {!varTaxPayer1}.
Save these field values in the variable: Id, Name, Email, Include_on_Correspondence__c, FirstName
Result
Successfully found records.
FAST LOOKUP: Lookup_Tax_Payer_2
Find all Contact records where:
Id Equals {!varTaxService.Tax_Payer_2__c} (0032100000FHUJGAA5)
Assign those records to {!varTaxPayer2}.
Save these field values in the variable: Id, Name, FirstName, Email, Include_on_Correspondence__c
Result
Successfully found records.
-----
Sandbox: Error Occurred During Flow "Tax_Prep_Workflow": An error occurred when executing a flow interview.
An error occurred at element myRule_1_A1 (FlowActionCall).
An error occurred when executing a flow interview.
This report lists the elements that the flow interview executed. The report is a beta feature.
We welcome your feedback on IdeaExchange.
Flow Details
Flow Name: Tax_Prep_Workflow
Type: Workflow
Version: 1
Status: Active
Flow Interview Details
Interview Label: Tax_Prep_Workflow-1_Tax_Services__c
Current User: Sean Barczynski (00537000000ahJS)
Start time: 12/9/2016 3:54 PM
Duration: 0 seconds
How the Interview Started
Sean Barczynski (00537000000ahJS) started the flow interview.
Some of this flow's variables were set when the interview started.
myVariable_old = null
myVariable_current = a2C210000000i7CEAQ
ASSIGNMENT: myVariable_waitStartTimeAssignment
{!myVariable_waitStartTimeVariable} Equals {!Flow.CurrentDateTime}
Result
{!myVariable_waitStartTimeVariable} = "12/9/2016 3:54 PM"
DECISION: myDecision
Executed this outcome: myRule_1
Outcome conditions: and
1. {!myVariable_current.RecordType.Name} (Tax Prep) Equals Tax Prep
Logic: All conditions must be true (AND)
TAX_PREP_SERVICE_UPDATE (FLOWS): myRule_1_A1
Inputs:
varTaxService = {!myVariable_current} (a2C210000000i7CEAQ)
Error Occurred: An error occurred when executing a flow interview.
-----
Any help is greatly appreciated!
-----
Sandbox: Error Occurred During Flow "Tax_Prep_Service_Update": The flow failed to access the value for varTaxPayer1...
This report lists the elements that the flow interview executed. The report is a beta feature.
We welcome your feedback on IdeaExchange.
Flow Details
Flow Name: Tax_Prep_Service_Update
Type: Autolaunched Flow
Version: 9
Status: Active
Flow Interview Details
Interview Label: Tax Prep Service Update 12/9/2016 3:54 PM
Current User: Sean Barczynski (00537000000ahJS)
Start time: 12/9/2016 3:54 PM
Duration: 0 seconds
How the Interview Started
Sean Barczynski (00537000000ahJS) started the flow interview.
Some of this flow's variables were set when the interview started.
varTaxService = a2C210000000i7CEAQ
FAST LOOKUP: Fast_Lookup_Tax_Payer_1
Find all Contact records where:
Id Equals {!varTaxService.Tax_Payer_1__c} (0032100000FHUJBAA5)
Assign those records to {!varTaxPayer1}.
Save these field values in the variable: Id, Name, Email, Include_on_Correspondence__c, FirstName
Result
Successfully found records.
FAST LOOKUP: Lookup_Tax_Payer_2
Find all Contact records where:
Id Equals {!varTaxService.Tax_Payer_2__c} (0032100000FHUJGAA5)
Assign those records to {!varTaxPayer2}.
Save these field values in the variable: Id, Name, FirstName, Email, Include_on_Correspondence__c
Result
Successfully found records.
-----
Sandbox: Error Occurred During Flow "Tax_Prep_Workflow": An error occurred when executing a flow interview.
An error occurred at element myRule_1_A1 (FlowActionCall).
An error occurred when executing a flow interview.
We welcome your feedback on IdeaExchange.
Flow Details
Flow Name: Tax_Prep_Workflow
Type: Workflow
Version: 1
Status: Active
Flow Interview Details
Interview Label: Tax_Prep_Workflow-1_Tax_Services__c
Current User: Sean Barczynski (00537000000ahJS)
Start time: 12/9/2016 3:54 PM
Duration: 0 seconds
How the Interview Started
Sean Barczynski (00537000000ahJS) started the flow interview.
Some of this flow's variables were set when the interview started.
myVariable_old = null
myVariable_current = a2C210000000i7CEAQ
ASSIGNMENT: myVariable_waitStartTimeAssignment
{!myVariable_waitStartTimeVariable} Equals {!Flow.CurrentDateTime}
Result
{!myVariable_waitStartTimeVariable} = "12/9/2016 3:54 PM"
DECISION: myDecision
Executed this outcome: myRule_1
Outcome conditions: and
1. {!myVariable_current.RecordType.Name} (Tax Prep) Equals Tax Prep
Logic: All conditions must be true (AND)
TAX_PREP_SERVICE_UPDATE (FLOWS): myRule_1_A1
Inputs:
varTaxService = {!myVariable_current} (a2C210000000i7CEAQ)
-----
Any help is greatly appreciated!
- Sean Barczynski
- December 12, 2016
- Like
- 0
Updating Account based on Task created by Salesforce for Outlook
Hello,
I'm trying to update an Account field based upon certain criteria of an email that is sent in Outlook and synced to Salesforce using SFO. When I manually create the task in Salesforce, the trigger works, but it doesn't work when I sync one using SFO.
Here are the relevant snippets from my code:
Any help is greatly appreciated!
I'm trying to update an Account field based upon certain criteria of an email that is sent in Outlook and synced to Salesforce using SFO. When I manually create the task in Salesforce, the trigger works, but it doesn't work when I sync one using SFO.
Here are the relevant snippets from my code:
trigger taskTrigger on Task (before insert, before update) { Set <Id> whatIdSet = new Set <Id> (); Set <Id> whoIdSet = new Set <Id> (); Contact contact; for(Task t : trigger.new) { if(t.WhatId != null) { whatIdSet.add(t.WhatId); } if(t.WhoId != null) { whoIdSet.add(t.WhoId); } } Map<ID, Account> accountMap = new Map<ID, Account>([select Id, Name, Number_of_Attempts_to_Schedule_Review__c, Number_of_Attempts_to_Schedule_TaxPlan__c, Number_of_Attempts_to_Schedule_TaxPrep__c from Account Where Id in :whatIdSet]); Boolean accountNeedsUpdating = FALSE; Boolean attemptToScheduleReview = FALSE; List <Account> AccountsToUpdate = new List <Account> (); String whatObjectType; Account household; for(Task t : trigger.new) { if(t.WhatID != NULL && accountMap.containsKey(t.WhatId)) { whatObjectType = 'household'; household = accountMap.get(t.WhatId); } if(trigger.isInsert) { if(t.Subject=='Email:Scheduling a Review Meeting') { if(t.Attempt_to_Schedule__c == NULL) t.Attempt_to_Schedule__c = 'Client Review Meeting'; else t.Attempt_to_Schedule__c += ';Client Review Meeting'; attemptToScheduleReview = TRUE; } if(t.WhatId != NULL && whatObjectType == 'household') { if(t.Attempt_to_Schedule__c != NULL && (t.Attempt_to_Schedule__c.contains('Client Review Meeting') || attemptToScheduleReview)) { if(household.Number_of_Attempts_to_Schedule_Review__c == NULL) household.Number_of_Attempts_to_Schedule_Review__c = 1; else household.Number_of_Attempts_to_Schedule_Review__c++; accountNeedsUpdating = TRUE; } } if(accountNeedsUpdating) AccountsToUpdate.add(household); accountNeedsUpdating = FALSE; try { if(AccountsToUpdate.size()>0) { update AccountsToUpdate; } } catch (System.DmlException ex) { System.Debug (ex); } }
Any help is greatly appreciated!
- Sean Barczynski
- September 19, 2016
- Like
- 0
Internal Salesforce Error when running test class
Good afternoon,
I'm attempting to run a test method that creates a recurring event, but whenever I try to run it, I get an Internal Salesforce Error. If I comment out the recurrence part, the test class runs just fine.
Here's the snippet in question:
Please help!
I'm attempting to run a test method that creates a recurring event, but whenever I try to run it, I get an Internal Salesforce Error. If I comment out the recurrence part, the test class runs just fine.
Here's the snippet in question:
events.add(new Event(Subject = 'Review Meeting', WhatID = accounts[0].Id, ActivityDateTime = datetime.newInstance(2015, 8, 19, 10, 30, 0), FSTR__SUB_TYPE__C = 'Client Review Meeting', FINANCIAL_PLAN_UPDATE__C = TRUE, TAX_PLAN__C = TRUE, IPS_UPDATED__C = TRUE, IsRecurrence = true, RecurrenceStartDateTime = System.today(), RecurrenceEndDateOnly = System.today()+30, RecurrenceType = 'RecursDaily', RecurrenceInterval = 1, Status__c = 'Scheduled', DurationInMinutes = 60));
Please help!
- Sean Barczynski
- August 04, 2016
- Like
- 0
Error: Unknown Property
Hello,
I'm trying to create a VisualForce page listing all clients who are due for a meeting. I have created a Controller class and VF page using Eclipse. When I try to save the VF page to the server, I receive the following error:
Save error: Unknown property 'DueForReview.getAccounts'
Here is my code
Controller
VF Page
Please help!
I'm trying to create a VisualForce page listing all clients who are due for a meeting. I have created a Controller class and VF page using Eclipse. When I try to save the VF page to the server, I receive the following error:
Save error: Unknown property 'DueForReview.getAccounts'
Here is my code
Controller
public class DueForReview { private final List<Account> accounts =[select Id, Name, Review_Frequency__c, Last_Review_Meeting__c from Account]; List<Account> DueForReview; public DueForReview() { for(Integer i=0; i<=accounts.Size()-1; i++) { if(accounts[i].Review_Frequency__c == 'Quarterly' && accounts[i].Last_Review_Meeting__c <= Date.newInstance(System.today().year(),System.today().month()-3,System.today().day())) { DueForReview.add(accounts[i]); } if(accounts[i].Review_Frequency__c == 'Semi-Annually' && accounts[i].Last_Review_Meeting__c <= Date.newInstance(System.today().year(),System.today().month()-6,System.today().day())) { DueForReview.add(accounts[i]); } if(accounts[i].Review_Frequency__c == 'Annually' && accounts[i].Last_Review_Meeting__c <= Date.newInstance(System.today().year()-1,System.today().month(),System.today().day())) { DueForReview.add(accounts[i]); } } } public List<Account> getAccounts() { return DueForReview; } }
VF Page
<apex:page controller="DueForReview"> <apex:pageBlock title="Clients Due For Review"> <apex:pageBlockTable value="{!getAccounts}" var="account"> <apex:column value="{!account.name}"/> <apex:column value="{!account.Review_Frequency__c}"/> <apex:column value="{!account.Last_Review_Meeting__c}"/> </apex:pageBlockTable> </apex:pageBlock> </apex:page>
Please help!
- Sean Barczynski
- December 03, 2015
- Like
- 0
Save error: Unknown Property
Hello,
I'm trying to create a VisualForce page listing all clients who are due for a meeting. I have created a Controller class and VF page using Eclipse. When I try to save the VF page to the server, I receive the following error:
Save error: Unknown property 'DueForReview.getAccounts'
Here is my code:
Controller
VF Page
Please help!
I'm trying to create a VisualForce page listing all clients who are due for a meeting. I have created a Controller class and VF page using Eclipse. When I try to save the VF page to the server, I receive the following error:
Save error: Unknown property 'DueForReview.getAccounts'
Here is my code:
Controller
public class DueForReview { private final List<Account> accounts =[select Id, Name, Review_Frequency__c, Last_Review_Meeting__c from Account]; List<Account> DueForReview; public DueForReview() { for(Integer i=0; i<=accounts.Size()-1; i++) { if(accounts[i].Review_Frequency__c == 'Quarterly' && accounts[i].Last_Review_Meeting__c <= Date.newInstance(System.today().year(),System.today().month()-3,System.today().day())) { DueForReview.add(accounts[i]); } if(accounts[i].Review_Frequency__c == 'Semi-Annually' && accounts[i].Last_Review_Meeting__c <= Date.newInstance(System.today().year(),System.today().month()-6,System.today().day())) { DueForReview.add(accounts[i]); } if(accounts[i].Review_Frequency__c == 'Annually' && accounts[i].Last_Review_Meeting__c <= Date.newInstance(System.today().year()-1,System.today().month(),System.today().day())) { DueForReview.add(accounts[i]); } } } public List<Account> getAccounts() { return DueForReview; } }
VF Page
<apex:page controller="DueForReview"> <apex:pageBlock title="Clients Due For Review"> <apex:pageBlockTable value="{!getAccounts}" var="account"> <apex:column value="{!account.name}"/> <apex:column value="{!account.Review_Frequency__c}"/> <apex:column value="{!account.Last_Review_Meeting__c}"/> </apex:pageBlockTable> </apex:pageBlock> </apex:page>
Please help!
- Sean Barczynski
- December 03, 2015
- Like
- 0
Tasks not being created
Hello!
I'm having a problem with a trigger not creating tasks that are part of a FOR loop, even though other pieces of the loop are being performed. I think it has something to do with ActivityDate field because if I do date.today(), it works fine, but if I do date.newinstance(...), it doesn't get created. In the fields list for Tasks, it shows as date/time, but when I try to do datetime.newinstance, I get an error saying it's expecting a date. The issue is from line 85 to line 115 (bold and italics).
I'm having a problem with a trigger not creating tasks that are part of a FOR loop, even though other pieces of the loop are being performed. I think it has something to do with ActivityDate field because if I do date.today(), it works fine, but if I do date.newinstance(...), it doesn't get created. In the fields list for Tasks, it shows as date/time, but when I try to do datetime.newinstance, I get an error saying it's expecting a date. The issue is from line 85 to line 115 (bold and italics).
/********************************************************************** This trigger updates the Last Meeting Date fields at the HH level **********************************************************************/ trigger LastEventDate on Event (after insert, after update) { // The sets used to store the IDs of the Accounts or Contacts/Leads within an event that need to get updated Set <Id> whatIdSet = new Set <Id> (); for(Event e : trigger.new) { if(e.WhatId != null) { whatIdSet.add(e.WhatId); } } // Creates two maps in case whatId is not populated Map<ID, Account> accountMap = new Map<ID, Account>([select Id, Last_Review_Meeting__c, Last_FP_Update__c, Last_IPS_Update__c, Last_Tax_Planning_Meeting__c, Last_Tax_Prep_Meeting__c from Account Where Id in :whatIdSet]); List<Event> eventList = [select Id, WhatID, StartDateTime, ActivityDateTime, FSTR__Sub_Type__c, Status__c, Financial_Plan_Update__c, IPS_Updated__c, Tax_Plan__c from Event Where WhatId in :whatIdSet]; List<Tax_Services__c> serviceList = [select Id, Business_Account__c, Meeting_Date__c, Client_will_send_docs__c, Tax_Docs_Received__c, Tax_Docs_Scanned__c, Tax_Preparer__c, Tax_Year__c from Tax_Services__c Where Business_Account__c in :whatIdSet]; // The actual Accounts & Tax Services to save List <Account> AccountsToUpdate = new List <Account> (); List <Tax_Services__c> ServicesToUpdate = new List <Tax_Services__c> (); List <Task> TasksToCreate = new List <Task> (); for(Event e : Trigger.new) { if(e.WhatID != null && accountMap.containsKey(e.whatId)) { Account a1 = accountMap.get(e.WhatId); Date d1 = Date.newInstance(e.ActivityDateTime.year(), e.ActivityDateTime.month(), e.ActivityDateTime.day()); //If new meeting is scheduled as planned, set this meeting date to the appropriate Last Meeting Date field if(e.Status__c != 'Canceled' && e.Status__c != 'Re-Scheduled' && Trigger.isInsert) { if(e.FSTR__Sub_Type__c == 'Tax Preparation Meeting') { if(d1 > a1.Last_Tax_Prep_Meeting__c) { a1.Last_Tax_Prep_Meeting__c = d1; } } if(e.FSTR__Sub_Type__c == 'Tax Planning Meeting' || e.Tax_Plan__c) { if(d1 > a1.Last_Tax_Planning_Meeting__c) { a1.Last_Tax_Planning_Meeting__c = d1; } for(Integer i=0; i<=serviceList.size()-1; i++) { if(serviceList[i].Business_Account__c==a1.Id && integer.valueof(serviceList[i].Tax_Year__c)==e.ActivityDateTime.year()) { //Update Tax Service Meeting Date serviceList[i].Meeting_Date__c=Date.newInstance(e.ActivityDateTime.year(), e.ActivityDateTime.month(), e.ActivityDateTime.day()); ServicesToUpdate.add(serviceList[i]); TasksToCreate.add(new Task(OwnerID = serviceList[i].Tax_Preparer__c, Subject = 'Complete Tax Plan', WhatID = serviceList[i].Id, ActivityDate = d1.addDays(-5), Description = 'Mark task complete when tax plan is received', Status = 'Not Started', Priority = 'Normal', Hidden__c = 'Complete Tax Plan')); // Create "Expect Tax Docs" task if client is sending, but have not been received if(serviceList[i].Client_will_send_docs__c==TRUE && serviceList[i].Tax_Docs_Received__c==FALSE) { TasksToCreate.add(new Task(OwnerID = serviceList[i].Tax_Preparer__c, Subject = 'Expect Tax Docs', WhatID = serviceList[i].Id, ActivityDate = d1.addDays(-5), Description = 'Mark task complete when tax docs are received', Status = 'Not Started', Priority = 'Normal', Hidden__c = 'Expect Tax Docs')); } } } } if(e.FSTR__Sub_Type__c == 'Client Review Meeting') { if(d1 > a1.Last_Review_Meeting__c) { a1.Last_Review_Meeting__c = d1; } } if(e.Financial_Plan_Update__c) { if(d1 > a1.Last_FP_Update__c) { a1.Last_FP_Update__c = d1; } } if(e.IPS_Updated__c) { if(d1 > a1.Last_IPS_Update__c) { a1.Last_IPS_Update__c = d1; } } AccountsToUpdate.add (a1); } // If meeting is canceled or rescheduled, update all Last Meeting date fields if(Trigger.isUpdate) { a1.Last_Review_Meeting__c=Date.newInstance(1900, 1, 1); a1.Last_FP_Update__c=Date.newInstance(1900, 1, 1); a1.Last_IPS_Update__c=Date.newInstance(1900, 1, 1); a1.Last_Tax_Planning_Meeting__c=Date.newInstance(1900, 1, 1); a1.Last_Tax_Prep_Meeting__c=Date.newInstance(1900, 1, 1); for(Integer i=0; i<=serviceList.size()-1; i++) { if(serviceList[i].Business_Account__c==a1.Id && integer.valueof(serviceList[i].Tax_Year__c)==e.ActivityDateTime.year() && e.FSTR__Sub_Type__c == 'Tax Planning Meeting') { if(e.Status__c == 'Canceled' || e.Status__c == 'Re-Scheduled') { serviceList[i].Meeting_Date__c=NULL; ServicesToUpdate.add(serviceList[i]); } } } for(Integer i=0; i<=eventList.size()-1; i++) { // Tax Planning Meeting if(eventList[i].FSTR__Sub_Type__c == 'Tax Preparation Meeting' && eventList[i].WhatID == a1.Id && eventList[i].ActivityDateTime > a1.Last_Tax_Prep_Meeting__c && eventList[i].Status__c == 'Scheduled') { a1.Last_Tax_Prep_Meeting__c = Date.newInstance(eventList[i].ActivityDateTime.year(), eventList[i].ActivityDateTime.month(),eventList[i].ActivityDateTime.day()); } // Tax Prep Meeting if(eventList[i].FSTR__Sub_Type__c == 'Tax Planning Meeting' || eventList[i].Tax_Plan__c) { if(eventList[i].WhatID == a1.Id && eventList[i].ActivityDateTime > a1.Last_Tax_Planning_Meeting__c && eventList[i].Status__c == 'Scheduled') { a1.Last_Tax_Planning_Meeting__c = Date.newInstance(eventList[i].ActivityDateTime.year(), eventList[i].ActivityDateTime.month(),eventList[i].ActivityDateTime.day()); } } // Client Review Meeting if(eventList[i].FSTR__Sub_Type__c == 'Client Review Meeting' && eventList[i].WhatID == a1.Id && eventList[i].ActivityDateTime > a1.Last_Review_Meeting__c && eventList[i].Status__c == 'Scheduled') { a1.Last_Review_Meeting__c = Date.newInstance(eventList[i].ActivityDateTime.year(), eventList[i].ActivityDateTime.month(),eventList[i].ActivityDateTime.day()); } // IPS Update if(eventList[i].IPS_Updated__c && eventList[i].WhatID == a1.Id && eventList[i].ActivityDateTime > a1.Last_IPS_Update__c && eventList[i].Status__c == 'Scheduled') { a1.Last_IPS_Update__c = Date.newInstance(eventList[i].ActivityDateTime.year(), eventList[i].ActivityDateTime.month(), eventList[i].ActivityDateTime.day()); } // FP Update if(eventList[i].Financial_Plan_Update__c && eventList[i].WhatID == a1.Id && eventList[i].ActivityDateTime > a1.Last_FP_Update__c && eventList[i].Status__c == 'Scheduled') { a1.Last_FP_Update__c = Date.newInstance(eventList[i].ActivityDateTime.year(), eventList[i].ActivityDateTime.month(),eventList[i].ActivityDateTime.day()); } } AccountsToUpdate.add (a1); } try { update AccountsToUpdate; update ServicesToUpdate; insert TasksToCreate; } catch (System.DmlException ex) { System.Debug (ex); } } } }
- Sean Barczynski
- October 28, 2015
- Like
- 0
Trigger won't link task to custom object record
Greetings,
I'm having some trouble with a trigger I've written. This is intended to create a task based upon certain fields in a custom object. The tasks are created as expected, except WhatID is not populated in the tasks, therefore they are not linked to the custom object record.
Any thoughts on what may be happening here?
I'm having some trouble with a trigger I've written. This is intended to create a task based upon certain fields in a custom object. The tasks are created as expected, except WhatID is not populated in the tasks, therefore they are not linked to the custom object record.
/********************************************************************** This trigger checks if tax docs are received and/or scanned on Tax_Services__c object and assigns tasks accordingly. **********************************************************************/ trigger Tax_Docs on Tax_Services__c (before insert, before update) { // The sets used to store the IDs of the Accounts or Contacts/Leads within an event that need to get updated /* Set <Id> IdSet = new Set <Id> (); for(Tax_Services__c e : trigger.new) { IdSet.add(e.Id); } // Creates two maps in case whatId is not populated Map<ID, Tax_Services__c> serviceMap = new Map<ID, Tax_Services__c>([select Id, Tax_Docs_Received__c, Tax_Docs_Scanned__c, Business_Account__c, Tax_Advisor__c, Tax_Preparer__c from Tax_Services__c Where Id in :IdSet]); List<Task> taskList = [select Id, WhatID, StartDateTime, ActivityDateTime, FSTR__Sub_Type__c, Status__c, Financial_Plan_Update__c, IPS_Updated__c, Tax_Plan__c from Event Where WhatId in :whatIdSet]; */ // The actual Accounts to save List <Task> TasksToCreate = new List <Task> (); for(Tax_Services__c e : Trigger.new) { if(Trigger.isUpdate) { Tax_Services__c oldService = Trigger.oldMap.get(e.ID); if(e.Tax_Docs_Received__c == TRUE && e.Tax_Docs_Scanned__c == TRUE) { if(e.Tax_Docs_Received__c != oldService.Tax_Docs_Received__c || e.Tax_Docs_Scanned__c != oldService.Tax_Docs_Scanned__c) { TasksToCreate.add(new Task(OwnerID = e.Tax_Advisor__c, Subject = 'Tax Docs Received and Scanned', WhatID = e.Id, ActivityDate = date.today(), Status = 'Not Started', Priority = 'Normal', Hidden__c = 'Tax Docs Received & Scanned')); } } if(e.Tax_Docs_Received__c == TRUE && e.Tax_Docs_Scanned__c == FALSE) { if(e.Tax_Docs_Received__c != oldService.Tax_Docs_Received__c || e.Tax_Docs_Scanned__c != oldService.Tax_Docs_Scanned__c) { TasksToCreate.add(new Task(OwnerID = e.Tax_Advisor__c, Subject = 'Scan Tax Docs', WhatID = e.Id, ActivityDate = date.today(), Status = 'Not Started', Priority = 'Normal', Hidden__c = 'Scan Tax Docs')); } } } if(Trigger.isInsert) { if(e.Tax_Docs_Received__c == TRUE && e.Tax_Docs_Scanned__c == TRUE) { TasksToCreate.add(new Task(OwnerID = e.Tax_Advisor__c, Subject = 'Tax Docs Received and Scanned', WhatID = e.Id, ActivityDate = date.today(), Status = 'Not Started', Priority = 'Normal', Hidden__c = 'Tax Docs Received & Scanned')); } if(e.Tax_Docs_Received__c == TRUE && e.Tax_Docs_Scanned__c == FALSE) { TasksToCreate.add(new Task(OwnerID = e.Tax_Advisor__c, Subject = 'Scan Tax Docs', WhatID = e.Id, ActivityDate = date.today(), Status = 'Not Started', Priority = 'Normal', Hidden__c = 'Scan Tax Docs')); } } /* if(e.WhatID != null && accountMap.containsKey(e.whatId)) { } */ } try { Insert TasksToCreate; } catch (System.DmlException ex) { System.Debug (ex); } }
Any thoughts on what may be happening here?
- Sean Barczynski
- October 18, 2015
- Like
- 0
Setting WhatID to Custom Object
Greetings,
I'm having some trouble with a trigger I've written. This is intended to create a task based upon certain fields in a custom object. The tasks are created as expected, except WhatID is not populated in the tasks, therefore they are not linked to the custom object record.
Any thoughts on what may be happening here?
I'm having some trouble with a trigger I've written. This is intended to create a task based upon certain fields in a custom object. The tasks are created as expected, except WhatID is not populated in the tasks, therefore they are not linked to the custom object record.
/********************************************************************** This trigger checks if tax docs are received and/or scanned on Tax_Services__c object and assigns tasks accordingly. **********************************************************************/ trigger Tax_Docs on Tax_Services__c (before insert, before update) { List <Task> TasksToCreate = new List <Task> (); for(Tax_Services__c e : Trigger.new) { if(Trigger.isUpdate) { Tax_Services__c oldService = Trigger.oldMap.get(e.ID); if(e.Tax_Docs_Received__c == TRUE && e.Tax_Docs_Scanned__c == TRUE) { if(e.Tax_Docs_Received__c != oldService.Tax_Docs_Received__c || e.Tax_Docs_Scanned__c != oldService.Tax_Docs_Scanned__c) { TasksToCreate.add(new Task(OwnerID = e.Tax_Advisor__c, Subject = 'Tax Docs Received and Scanned', WhatID = e.Id, ActivityDate = date.today(), Status = 'Not Started', Priority = 'Normal', Hidden__c = 'Tax Docs Received & Scanned')); } } if(e.Tax_Docs_Received__c == TRUE && e.Tax_Docs_Scanned__c == FALSE) { if(e.Tax_Docs_Received__c != oldService.Tax_Docs_Received__c || e.Tax_Docs_Scanned__c != oldService.Tax_Docs_Scanned__c) { TasksToCreate.add(new Task(OwnerID = e.Tax_Advisor__c, Subject = 'Scan Tax Docs', WhatID = e.Id, ActivityDate = date.today(), Status = 'Not Started', Priority = 'Normal', Hidden__c = 'Scan Tax Docs')); } } } if(Trigger.isInsert) { if(e.Tax_Docs_Received__c == TRUE && e.Tax_Docs_Scanned__c == TRUE) { TasksToCreate.add(new Task(OwnerID = e.Tax_Advisor__c, Subject = 'Tax Docs Received and Scanned', WhatID = e.Id, ActivityDate = date.today(), Status = 'Not Started', Priority = 'Normal', Hidden__c = 'Tax Docs Received & Scanned')); } if(e.Tax_Docs_Received__c == TRUE && e.Tax_Docs_Scanned__c == FALSE) { TasksToCreate.add(new Task(OwnerID = e.Tax_Advisor__c, Subject = 'Scan Tax Docs', WhatID = e.Id, ActivityDate = date.today(), Status = 'Not Started', Priority = 'Normal', Hidden__c = 'Scan Tax Docs')); } } } try { Insert TasksToCreate; } catch (System.DmlException ex) { System.Debug (ex); } }
Any thoughts on what may be happening here?
- Sean Barczynski
- October 18, 2015
- Like
- 0
Last Meeting Date
Hello,
I'm attempting to write my first trigger, so please bare with me while I explain.
The purpose of the trigger is to update some date fields based upon Events to show when the last meeting of various types was completed. I've seen a few different threads on this site that I was able to pull some ideas from, but have been unable to figure out how to get one particular piece to work. The issue comes when a meeting is Canceled or Rescheduled. We want to keep these events in the system so we can refer back to them in the future (e.g. if a client says we haven't seen them in over a year, we can go back and see that they canceled on us twice), but we don't want these events to be reflected in the Last Meeting fields.
I believe I have it written correctly so far to update the field when a meeting is not Canceled or Rescheduled, I just don't know how to get it to work once the meeting is Canceled. Theoretically, the field would already be updated with this meeting date, so I'd want the trigger to look back and pull the last meeting that was not canceled or rescheduled. I have two ideas:
Thanks in advance for any help!
I'm attempting to write my first trigger, so please bare with me while I explain.
The purpose of the trigger is to update some date fields based upon Events to show when the last meeting of various types was completed. I've seen a few different threads on this site that I was able to pull some ideas from, but have been unable to figure out how to get one particular piece to work. The issue comes when a meeting is Canceled or Rescheduled. We want to keep these events in the system so we can refer back to them in the future (e.g. if a client says we haven't seen them in over a year, we can go back and see that they canceled on us twice), but we don't want these events to be reflected in the Last Meeting fields.
I believe I have it written correctly so far to update the field when a meeting is not Canceled or Rescheduled, I just don't know how to get it to work once the meeting is Canceled. Theoretically, the field would already be updated with this meeting date, so I'd want the trigger to look back and pull the last meeting that was not canceled or rescheduled. I have two ideas:
- Loop through the Account's Events and find the most recent one that was not canceled or rescheduled. I'm thinking this would cause too many database queries and may throw an error.
- Create a second field (not visible on the Page Layout) that contains the last successful meeting date before this one.
trigger LastEventDate on Event (after insert, after update) { // The sets used to store the IDs of the Accounts or Contacts/Leads within an event that need to get updated Set <Id> whoIdSet = new Set <Id> (); Set <Id> whatIdSet = new Set <Id> (); for(Event e : trigger.net) { if(e.WhoId != null) { whoIdSet.add(e.WhoId); } if(e.WhatId != null && e.WhoId == null) { whatIdSet.add(e.WhatId); } } // Creates two maps in case whoId or whatId is not populated Map<ID, Contact> contactMap = new Map<ID, Contact>([select Id, AccountId from Contact Where Id in :whoIdSet]); Map<ID, Account> accountMap = new Map<ID, Account>([select Id, Last_Review_Meeting__c, Last_FP_Update__c, Last_IPS_Update__c, Last_Tax_Planning_Meeting__c, Last_Tax_Prep_Meeting__c from Account Where Id in :whatIdSet]); // The actual Accounts to save List <Accounts> Scheduled = new List <Accounts> (); List <Accounts> CancelledRescheduled = new List <Accounts> (); for(Event e : Trigger.new) { if(e.whoID != null && contactMap.containsKey(e.whoId)) { //If meeting is scheduled as planned, set this meeting date to the appropriate Last Meeting Date field if(e.Status__c != "Canceled" && e.Status__c != "Re-Scheduled") { Contact c1 = contactMap.get(e.whoId); if(c1.AccountId != null) { Account a1 = c1.AccountId; Date d1 = Data.newInstance(e.StartDateTime.year(), e.StartDateTime.month(), e.StartDateTime.day()); if(e.FSTR__Sub_Type__c == "Tax Preparation Meeting") { if(d1 > a1.Last_Tax_Prep_Meeting__c) { a1.Last_Tax_Prep_Meeting__c = d1; } } if(e.FSTR__Sub_Type__c == "Tax Planning Meeting" || Tax_Plan__c == TRUE) { if(d1 > a1.Last_Tax_Planning_Meeting__c) { a1.Last_Tax_Planning_Meeting__c = d1; } } if(e.FSTR__Sub_Type__c == "Client Review Meeting") { if(d1 > a1.Last_Review_Meeting__c) { a1.Last_Review_Meeting__c = d1; } } if(e.Financial_Plan_Update__c == TRUE) { if(d1 > a1.Last_FP_Update__c) { a1.Last_FP_Update__c = d1; } } if(e.IPS_Updated__c == TRUE) { if(d1 > a1.Last_IPS_Update__c) { a1.Last_IPS_Update__c = d1; } } Scheduled.add (a1); } } // If meeting is canceled or rescheduled, set appropriate Last Meeting field to last meeting date that was not canceled or rescheduled if(e.Status__c == "Canceled" || e.Status__c == "Re-Scheduled") { } } } }
Thanks in advance for any help!
- Sean Barczynski
- August 17, 2015
- Like
- 0
Trouble with scheduled apex
Hello,
I'm having some trouble getting scheduled Apex classes to run consistently and correctly.
I have one that sends out emails every morning to clients who have meetings in 2 days. This class is scheduled to run every morning (including the weekends). Is there any reason it would run for a few days and then just stop? If it experiences an exception, does that then prevent it from running the following day? Do they run on weekends? I have yet to see one run on the weekends, but that may just be a coincidence. In the list of scheduled classes, it always says that they run, but no emails are being sent...
The second scheduled class I have is supposed to update all contacts and, in turn, trigger my Contact update triggers. This class seems to be running correctly, but none of the Contact onUpdate triggers are running correctly. However, when I edit an individual Contact, the triggers run correctly.
I'm having some trouble getting scheduled Apex classes to run consistently and correctly.
I have one that sends out emails every morning to clients who have meetings in 2 days. This class is scheduled to run every morning (including the weekends). Is there any reason it would run for a few days and then just stop? If it experiences an exception, does that then prevent it from running the following day? Do they run on weekends? I have yet to see one run on the weekends, but that may just be a coincidence. In the list of scheduled classes, it always says that they run, but no emails are being sent...
The second scheduled class I have is supposed to update all contacts and, in turn, trigger my Contact update triggers. This class seems to be running correctly, but none of the Contact onUpdate triggers are running correctly. However, when I edit an individual Contact, the triggers run correctly.
- Sean Barczynski
- September 25, 2017
- Like
- 0
Task not getting created, email not sending, other piece of IF statement firing
Good afternoon,
I'm struggling with some code that I wrote not producing the results I'm looking for. The section I want to focus on is the creation of the Scan Tax Docs task. When I check the box for Tax Docs Received and hit save, the test email is not being sent (the others in the else statements are sent when applicable) and the task is not being created, but the box for Scan Tax Docs Task Created is being checked (I confirmed that this is the line that is checking this box - I commented it out and it stopped getting checked).
Please help! Thanks in advance...
I'm struggling with some code that I wrote not producing the results I'm looking for. The section I want to focus on is the creation of the Scan Tax Docs task. When I check the box for Tax Docs Received and hit save, the test email is not being sent (the others in the else statements are sent when applicable) and the task is not being created, but the box for Scan Tax Docs Task Created is being checked (I confirmed that this is the line that is checking this box - I commented it out and it stopped getting checked).
Please help! Thanks in advance...
trigger TaxServiceBeforeUpdate on Tax_Services__c (before update) { Set <Id> WhatIdSet = new Set <Id> (); for(Tax_Services__c t : trigger.new) { if(t.Business_Account__c != NULL) { WhatIdSet.add(t.Business_Account__c); } } List<User> userList = [select id, Name, Email, Title, CompanyName, Phone from User]; List<Contact> contactList = [select Id, Name, AccountId, Email, FirstName, ACTDDEV__Nickname__c, Include_on_Correspondence__c, Primary__c from Contact Where AccountId in :WhatIdSet]; List<Task> serviceTaskList = [select Id, Subject, Status, WhatID, ActivityDate, Hidden__c from Task Where WhatId in :WhatIdSet and Subject = 'URGENT! Request Tax Docs from Client']; List<OrgWideEmailAddress> owaList = [select id, DisplayName, Address from OrgWideEmailAddress]; String taxPlanning = Schema.SObjectType.Tax_Services__c.getRecordTypeInfosByName().get('Tax Planning').getRecordTypeId(); String taxPrep = Schema.SObjectType.Tax_Services__c.getRecordTypeInfosByName().get('Tax Prep').getRecordTypeId(); List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>(); List <Task> TasksToCreate = new List <Task> (); List <Task> tasksToUpdate = new List <Task> (); String greeting; String email; String newBody2; String PrimaryTaxPayer; String SecondaryTaxPayer; String TaxPayers; List <String> emailAddresses = new List <String> (); User sinkrote; User sdonatelli; User TA; OrgWideEmailAddress owa; for(Tax_Services__c e : Trigger.new) { Tax_Services__c oldservice = Trigger.oldMap.get(e.ID); /*********************************************************************** * * Determining values for numerous pieces of vital information: * Tax Advisor * Tax Admin * Names of Tax Payers * ***********************************************************************/ for(Integer u=0;u<=userList.size()-1;u++) { for(Integer o=0;o<=owaList.size()-1;o++) { if(userList[u].Id == e.Tax_Advisor__c && userList[u].Email == owaList[o].Address) { owa = owaList[o]; TA = userList[u]; } } if(userList[u].Email == 'sd****mg.com') sdonatelli = userList[u]; if(userList[u].Email == 'si****mg.com') sinkrote = userList[u]; } for(Integer c=0; c<=contactList.size()-1; c++) { if(e.Business_Account__c == contactList[c].AccountId && contactList[c].Include_on_Correspondence__c && contactList[c].Email != NULL) { emailAddresses.add(contactList[c].Email); if(contactList[c].ACTDDEV__Nickname__c != NULL) greeting = contactList[c].ACTDDEV__Nickname__c; else greeting = contactList[c].FirstName; } if(e.Tax_Payer_1__c == contactList[c].Id) PrimaryTaxPayer = contactList[c].Name; if(e.Tax_Payer_2__c == contactList[c].Id) SecondaryTaxPayer = contactList[c].Name; } if(SecondaryTaxPayer != NULL) TaxPayers = PrimaryTaxPayer + ' & ' + SecondaryTaxPayer; else TaxPayers = PrimaryTaxPayer; /*********************************************************************** * * Tax Prep Workflow * ***********************************************************************/ if(e.RecordTypeId == taxPrep) { /* Updating Status */ if(e.Client_Lost__c) e.Status2__c = 'Client Lost'; if(e.Tax_Docs_Received__c == TRUE && e.Tax_Docs_Scanned__c == FALSE) { if(e.Tax_Docs_Received__c != oldservice.Tax_Docs_Received__c || e.Tax_Docs_Scanned__c != oldservice.Tax_Docs_Scanned__c) { e.Status2__c = 'Docs Received'; e.Status_Date__c = system.Today(); e.Tax_Docs_Received_Date__c = system.Today(); } } if(e.Tax_Docs_Received__c == TRUE && e.Tax_Docs_Scanned__c == TRUE) { if(e.Tax_Docs_Received__c != oldservice.Tax_Docs_Received__c && e.Tax_Docs_Scanned__c != oldservice.Tax_Docs_Scanned__c) { e.Status2__c = 'Docs Scanned'; e.Status_Date__c = system.Today(); e.Tax_Docs_Scanned_Date__c = system.Today(); } if(e.Tax_Docs_Received__c != oldservice.Tax_Docs_Received__c) e.Tax_Docs_Received_Date__c = system.Today(); } if(e.X8879_Given_to_Client__c && oldservice.X8879_Given_to_Client__c != e.X8879_Given_to_Client__c) { e.Status2__c = 'Waiting for 8879'; e.Status_Date__c = system.Today(); } if(e.Return_Filed__c && oldservice.Return_Filed__c != e.Return_Filed__c) { e.Status2__c = 'Filed'; e.Status_Date__c = system.Today(); } if(e.TARCT_Return_Locked_Completed__c && oldservice.TARCT_Return_Locked_Completed__c != e.TARCT_Return_Locked_Completed__c) { e.Status2__c = 'Final'; e.Status_Date__c = system.Today(); e.Tax_Return_Closed_Date__c = system.Today(); } /* Creating Tasks */ if(e.Tax_Docs_Received__c && !e.Tax_Docs_Scanned__c && !e.Scan_Tax_Docs_Task_Created__c) { if(e.Tax_Docs_Received__c != oldservice.Tax_Docs_Received__c || e.Tax_Docs_Scanned__c != oldservice.Tax_Docs_Scanned__c) { Messaging.SingleEmailMessage mail2 = new Messaging.SingleEmailMessage(); String[] toAddresses = new String[] {emailAddresses[0]}; mail2.setOrgWideEmailAddressId(owa.Id); mail2.setToAddresses(toAddresses); mail2.setSubject('Test 1'); String body2 = 'Hi ' + greeting + ','; mail2.setHtmlBody(body2); mails.add(mail2); Date ScanDocsDueDate = Date.today(); if(e.On_Extension__c) ScanDocsDueDate = Date.newInstance(Date.today().year(),4,18); else ScanDocsDueDate = Date.today(); TasksToCreate.add(new Task(OwnerID = sinkrote.Id, Subject = 'Scan Tax Docs', WhatID = e.Id, ActivityDate = ScanDocsDueDate, Status = 'Not Started', Priority = 'Normal', Category__c = 'Client/Prospect Work', Hidden__c = 'Scan Tax Docs')); e.Scan_Tax_Docs_Task_Created__c = TRUE; } else { Messaging.SingleEmailMessage mail2 = new Messaging.SingleEmailMessage(); String[] toAddresses = new String[] {emailAddresses[0]}; mail2.setOrgWideEmailAddressId(owa.Id); mail2.setToAddresses(toAddresses); mail2.setSubject('Test 2'); String body2 = 'Hi ' + greeting + ','; mail2.setHtmlBody(body2); mails.add(mail2); } } else { Messaging.SingleEmailMessage mail2 = new Messaging.SingleEmailMessage(); String[] toAddresses = new String[] {emailAddresses[0]}; mail2.setOrgWideEmailAddressId(owa.Id); mail2.setToAddresses(toAddresses); mail2.setSubject('Test 3'); String body2 = 'Hi ' + greeting + ','; mail2.setHtmlBody(body2); mails.add(mail2); } if(e.Tax_Docs_Received__c && e.Tax_Docs_Scanned__c && !e.Complete_Tax_Return_Task_Created__c && e.Tax_Docs_Scanned__c != oldservice.Tax_Docs_Scanned__c) { Date CompleteReturnDueDate; if(e.Tax_Prep_Meeting_Date__c != NULL) { if(e.Tax_Prep_Meeting_Date__c.addDays(-7) < system.Today()) CompleteReturnDueDate = system.Today(); else CompleteReturnDueDate = e.Tax_Prep_Meeting_Date__c.addDays(-7); } else { if(e.On_Extension__c) CompleteReturnDueDate = date.newInstance(date.today().year(),4,18); else CompleteReturnDueDate = system.Today().addDays(10); } TasksToCreate.add(new Task(OwnerID = e.Tax_Preparer__c, Subject = 'Complete Tax Return', WhatID = e.Id, WhoId = e.Tax_Payer_1__c, ActivityDate = CompleteReturnDueDate, Status = 'Not Started', Description = 'Please prepare tax return. Marking this complete will create a task for the Tax Advisor to review the return.', Priority = 'Normal', Hidden__c = 'Complete Tax Return')); e.Complete_Tax_Return_Task_Created__c = TRUE; } if(!e.Review_Tax_Return_Task_Created__c && e.Complete_Tax_Return_Task_Completed__c && e.Complete_Tax_Return_Task_Completed__c != oldservice.Complete_Tax_Return_Task_Completed__c) { Date ReviewReturnDueDate; if(e.Tax_Prep_Meeting_Date__c == NULL) { ReviewReturnDueDate = system.Today(); } else { if(e.Tax_Prep_Meeting_Date__c.addDays(-2) < system.Today()) { ReviewReturnDueDate = system.Today(); } else { ReviewReturnDueDate = e.Tax_Prep_Meeting_Date__c.addDays(-2); } } TasksToCreate.add(new Task(OwnerID = e.Tax_Advisor__c, Subject = 'Review Tax Return', WhatID = e.Id, WhoId = e.Tax_Payer_1__c, ActivityDate = ReviewReturnDueDate, Description = 'Mark this task complete once it has been reviewed with and approved by the client.', Status = 'Not Started', Priority = 'Normal', Category__c = 'Client/Prospect Work', Hidden__c = 'Review Tax Return')); e.Review_Tax_Return_Task_Created__c = TRUE; e.In_Review__c = True; e.Status2__c = 'In Review'; e.Status_Date__c = system.Today(); } if(!e.Close_Return_Task_Created__c && e.Review_Tax_Return_Task_Completed__c) { TasksToCreate.add(new Task(OwnerID = sinkrote.Id, Subject = 'Close Tax Return', WhatID = e.Id, WhoId = e.Tax_Payer_1__c, ActivityDate = system.Today(), Description = 'Perform closing tasks for tax return. Please ensure the appropriate items are checked on the Tax Service before marking this task complete.', Status = 'Not Started', Priority = 'Normal', Category__c = 'Client/Prospect Work', Hidden__c = 'Close Tax Return')); e.Close_Return_Task_Created__c = True; e.Completed_Status__c = TRUE; e.Tax_Return_Reviewed_Date__c = system.Today(); e.Status2__c = 'Completed'; e.Status_Date__c = system.Today(); e.Tax_Return_Complete_Date__c = system.Today(); } if(!e.Invoice_Client_Task_Created__c && e.Review_Tax_Return_Task_Completed__c && e.Client_Needs_to_be_Invoiced__c && !e.Invoice_Given_to_Client__c) { TasksToCreate.add(new Task(OwnerID = sdonatelli.Id, Subject = 'Invoice Client', WhatID = e.Id, WhoId = e.Tax_Payer_1__c, ActivityDate = system.Today(), Description = '', Status = 'Not Started', Priority = 'Normal', Category__c = 'Client/Prospect Work', Hidden__c = 'Invoice Client')); e.Invoice_Client_Task_Created__c = TRUE; } if(e.Tax_Docs_Received__c && serviceTaskList != null && serviceTaskList.size()>0) { for(Integer t=0;t<serviceTaskList.size();t++) { if(serviceTaskList[t].WhatId == e.Business_Account__c) { serviceTaskList[t].Status = 'Canceled'; tasksToUpdate.add(serviceTaskList[t]); } } } } } try { if(TasksToCreate.size()>0) insert TasksToCreate; if(tasksToUpdate.size()>0) update tasksToUpdate; if(mails.size()>0) Messaging.sendEmail(mails); } catch (System.DmlException ex) { System.Debug (ex); } }
- Sean Barczynski
- February 08, 2017
- Like
- 0
Updating Account based on Task created by Salesforce for Outlook
Hello,
I'm trying to update an Account field based upon certain criteria of an email that is sent in Outlook and synced to Salesforce using SFO. When I manually create the task in Salesforce, the trigger works, but it doesn't work when I sync one using SFO.
Here are the relevant snippets from my code:
Any help is greatly appreciated!
I'm trying to update an Account field based upon certain criteria of an email that is sent in Outlook and synced to Salesforce using SFO. When I manually create the task in Salesforce, the trigger works, but it doesn't work when I sync one using SFO.
Here are the relevant snippets from my code:
trigger taskTrigger on Task (before insert, before update) { Set <Id> whatIdSet = new Set <Id> (); Set <Id> whoIdSet = new Set <Id> (); Contact contact; for(Task t : trigger.new) { if(t.WhatId != null) { whatIdSet.add(t.WhatId); } if(t.WhoId != null) { whoIdSet.add(t.WhoId); } } Map<ID, Account> accountMap = new Map<ID, Account>([select Id, Name, Number_of_Attempts_to_Schedule_Review__c, Number_of_Attempts_to_Schedule_TaxPlan__c, Number_of_Attempts_to_Schedule_TaxPrep__c from Account Where Id in :whatIdSet]); Boolean accountNeedsUpdating = FALSE; Boolean attemptToScheduleReview = FALSE; List <Account> AccountsToUpdate = new List <Account> (); String whatObjectType; Account household; for(Task t : trigger.new) { if(t.WhatID != NULL && accountMap.containsKey(t.WhatId)) { whatObjectType = 'household'; household = accountMap.get(t.WhatId); } if(trigger.isInsert) { if(t.Subject=='Email:Scheduling a Review Meeting') { if(t.Attempt_to_Schedule__c == NULL) t.Attempt_to_Schedule__c = 'Client Review Meeting'; else t.Attempt_to_Schedule__c += ';Client Review Meeting'; attemptToScheduleReview = TRUE; } if(t.WhatId != NULL && whatObjectType == 'household') { if(t.Attempt_to_Schedule__c != NULL && (t.Attempt_to_Schedule__c.contains('Client Review Meeting') || attemptToScheduleReview)) { if(household.Number_of_Attempts_to_Schedule_Review__c == NULL) household.Number_of_Attempts_to_Schedule_Review__c = 1; else household.Number_of_Attempts_to_Schedule_Review__c++; accountNeedsUpdating = TRUE; } } if(accountNeedsUpdating) AccountsToUpdate.add(household); accountNeedsUpdating = FALSE; try { if(AccountsToUpdate.size()>0) { update AccountsToUpdate; } } catch (System.DmlException ex) { System.Debug (ex); } }
Any help is greatly appreciated!
- Sean Barczynski
- September 19, 2016
- Like
- 0
Error: Unknown Property
Hello,
I'm trying to create a VisualForce page listing all clients who are due for a meeting. I have created a Controller class and VF page using Eclipse. When I try to save the VF page to the server, I receive the following error:
Save error: Unknown property 'DueForReview.getAccounts'
Here is my code
Controller
VF Page
Please help!
I'm trying to create a VisualForce page listing all clients who are due for a meeting. I have created a Controller class and VF page using Eclipse. When I try to save the VF page to the server, I receive the following error:
Save error: Unknown property 'DueForReview.getAccounts'
Here is my code
Controller
public class DueForReview { private final List<Account> accounts =[select Id, Name, Review_Frequency__c, Last_Review_Meeting__c from Account]; List<Account> DueForReview; public DueForReview() { for(Integer i=0; i<=accounts.Size()-1; i++) { if(accounts[i].Review_Frequency__c == 'Quarterly' && accounts[i].Last_Review_Meeting__c <= Date.newInstance(System.today().year(),System.today().month()-3,System.today().day())) { DueForReview.add(accounts[i]); } if(accounts[i].Review_Frequency__c == 'Semi-Annually' && accounts[i].Last_Review_Meeting__c <= Date.newInstance(System.today().year(),System.today().month()-6,System.today().day())) { DueForReview.add(accounts[i]); } if(accounts[i].Review_Frequency__c == 'Annually' && accounts[i].Last_Review_Meeting__c <= Date.newInstance(System.today().year()-1,System.today().month(),System.today().day())) { DueForReview.add(accounts[i]); } } } public List<Account> getAccounts() { return DueForReview; } }
VF Page
<apex:page controller="DueForReview"> <apex:pageBlock title="Clients Due For Review"> <apex:pageBlockTable value="{!getAccounts}" var="account"> <apex:column value="{!account.name}"/> <apex:column value="{!account.Review_Frequency__c}"/> <apex:column value="{!account.Last_Review_Meeting__c}"/> </apex:pageBlockTable> </apex:pageBlock> </apex:page>
Please help!
- Sean Barczynski
- December 03, 2015
- Like
- 0
How to Get My 1st Jr Admin Job
Hello all,
I'm working towards my 201 certification and would like to start looking for Jr. Admin jobs. The problem is that I've never been an Admin, so technically I have 0 years of practical Admin experience and I'm currently in an unrealted field (I'm a mortgage loan officer). Every job posting I've read (on Indeed, Simply Hired, LinkedIn, etc) is requiring at least 2 years of Salesforce Admin experience, even for low-paying Jr. Admin or Admin assistant jobs.
It would stand to reason that before any given Admin became an Admin, they were not an Admin. How were you able to get your 1st Jr Admin job if you got it after being in an unrelated field? (I do not have the time or resources to work for free at a non-profit for 2 years at this point in my career).
Thanks,
Chris
I'm working towards my 201 certification and would like to start looking for Jr. Admin jobs. The problem is that I've never been an Admin, so technically I have 0 years of practical Admin experience and I'm currently in an unrealted field (I'm a mortgage loan officer). Every job posting I've read (on Indeed, Simply Hired, LinkedIn, etc) is requiring at least 2 years of Salesforce Admin experience, even for low-paying Jr. Admin or Admin assistant jobs.
It would stand to reason that before any given Admin became an Admin, they were not an Admin. How were you able to get your 1st Jr Admin job if you got it after being in an unrelated field? (I do not have the time or resources to work for free at a non-profit for 2 years at this point in my career).
Thanks,
Chris
- Christopher Weis
- November 23, 2015
- Like
- 2
Tasks not being created
Hello!
I'm having a problem with a trigger not creating tasks that are part of a FOR loop, even though other pieces of the loop are being performed. I think it has something to do with ActivityDate field because if I do date.today(), it works fine, but if I do date.newinstance(...), it doesn't get created. In the fields list for Tasks, it shows as date/time, but when I try to do datetime.newinstance, I get an error saying it's expecting a date. The issue is from line 85 to line 115 (bold and italics).
I'm having a problem with a trigger not creating tasks that are part of a FOR loop, even though other pieces of the loop are being performed. I think it has something to do with ActivityDate field because if I do date.today(), it works fine, but if I do date.newinstance(...), it doesn't get created. In the fields list for Tasks, it shows as date/time, but when I try to do datetime.newinstance, I get an error saying it's expecting a date. The issue is from line 85 to line 115 (bold and italics).
/********************************************************************** This trigger updates the Last Meeting Date fields at the HH level **********************************************************************/ trigger LastEventDate on Event (after insert, after update) { // The sets used to store the IDs of the Accounts or Contacts/Leads within an event that need to get updated Set <Id> whatIdSet = new Set <Id> (); for(Event e : trigger.new) { if(e.WhatId != null) { whatIdSet.add(e.WhatId); } } // Creates two maps in case whatId is not populated Map<ID, Account> accountMap = new Map<ID, Account>([select Id, Last_Review_Meeting__c, Last_FP_Update__c, Last_IPS_Update__c, Last_Tax_Planning_Meeting__c, Last_Tax_Prep_Meeting__c from Account Where Id in :whatIdSet]); List<Event> eventList = [select Id, WhatID, StartDateTime, ActivityDateTime, FSTR__Sub_Type__c, Status__c, Financial_Plan_Update__c, IPS_Updated__c, Tax_Plan__c from Event Where WhatId in :whatIdSet]; List<Tax_Services__c> serviceList = [select Id, Business_Account__c, Meeting_Date__c, Client_will_send_docs__c, Tax_Docs_Received__c, Tax_Docs_Scanned__c, Tax_Preparer__c, Tax_Year__c from Tax_Services__c Where Business_Account__c in :whatIdSet]; // The actual Accounts & Tax Services to save List <Account> AccountsToUpdate = new List <Account> (); List <Tax_Services__c> ServicesToUpdate = new List <Tax_Services__c> (); List <Task> TasksToCreate = new List <Task> (); for(Event e : Trigger.new) { if(e.WhatID != null && accountMap.containsKey(e.whatId)) { Account a1 = accountMap.get(e.WhatId); Date d1 = Date.newInstance(e.ActivityDateTime.year(), e.ActivityDateTime.month(), e.ActivityDateTime.day()); //If new meeting is scheduled as planned, set this meeting date to the appropriate Last Meeting Date field if(e.Status__c != 'Canceled' && e.Status__c != 'Re-Scheduled' && Trigger.isInsert) { if(e.FSTR__Sub_Type__c == 'Tax Preparation Meeting') { if(d1 > a1.Last_Tax_Prep_Meeting__c) { a1.Last_Tax_Prep_Meeting__c = d1; } } if(e.FSTR__Sub_Type__c == 'Tax Planning Meeting' || e.Tax_Plan__c) { if(d1 > a1.Last_Tax_Planning_Meeting__c) { a1.Last_Tax_Planning_Meeting__c = d1; } for(Integer i=0; i<=serviceList.size()-1; i++) { if(serviceList[i].Business_Account__c==a1.Id && integer.valueof(serviceList[i].Tax_Year__c)==e.ActivityDateTime.year()) { //Update Tax Service Meeting Date serviceList[i].Meeting_Date__c=Date.newInstance(e.ActivityDateTime.year(), e.ActivityDateTime.month(), e.ActivityDateTime.day()); ServicesToUpdate.add(serviceList[i]); TasksToCreate.add(new Task(OwnerID = serviceList[i].Tax_Preparer__c, Subject = 'Complete Tax Plan', WhatID = serviceList[i].Id, ActivityDate = d1.addDays(-5), Description = 'Mark task complete when tax plan is received', Status = 'Not Started', Priority = 'Normal', Hidden__c = 'Complete Tax Plan')); // Create "Expect Tax Docs" task if client is sending, but have not been received if(serviceList[i].Client_will_send_docs__c==TRUE && serviceList[i].Tax_Docs_Received__c==FALSE) { TasksToCreate.add(new Task(OwnerID = serviceList[i].Tax_Preparer__c, Subject = 'Expect Tax Docs', WhatID = serviceList[i].Id, ActivityDate = d1.addDays(-5), Description = 'Mark task complete when tax docs are received', Status = 'Not Started', Priority = 'Normal', Hidden__c = 'Expect Tax Docs')); } } } } if(e.FSTR__Sub_Type__c == 'Client Review Meeting') { if(d1 > a1.Last_Review_Meeting__c) { a1.Last_Review_Meeting__c = d1; } } if(e.Financial_Plan_Update__c) { if(d1 > a1.Last_FP_Update__c) { a1.Last_FP_Update__c = d1; } } if(e.IPS_Updated__c) { if(d1 > a1.Last_IPS_Update__c) { a1.Last_IPS_Update__c = d1; } } AccountsToUpdate.add (a1); } // If meeting is canceled or rescheduled, update all Last Meeting date fields if(Trigger.isUpdate) { a1.Last_Review_Meeting__c=Date.newInstance(1900, 1, 1); a1.Last_FP_Update__c=Date.newInstance(1900, 1, 1); a1.Last_IPS_Update__c=Date.newInstance(1900, 1, 1); a1.Last_Tax_Planning_Meeting__c=Date.newInstance(1900, 1, 1); a1.Last_Tax_Prep_Meeting__c=Date.newInstance(1900, 1, 1); for(Integer i=0; i<=serviceList.size()-1; i++) { if(serviceList[i].Business_Account__c==a1.Id && integer.valueof(serviceList[i].Tax_Year__c)==e.ActivityDateTime.year() && e.FSTR__Sub_Type__c == 'Tax Planning Meeting') { if(e.Status__c == 'Canceled' || e.Status__c == 'Re-Scheduled') { serviceList[i].Meeting_Date__c=NULL; ServicesToUpdate.add(serviceList[i]); } } } for(Integer i=0; i<=eventList.size()-1; i++) { // Tax Planning Meeting if(eventList[i].FSTR__Sub_Type__c == 'Tax Preparation Meeting' && eventList[i].WhatID == a1.Id && eventList[i].ActivityDateTime > a1.Last_Tax_Prep_Meeting__c && eventList[i].Status__c == 'Scheduled') { a1.Last_Tax_Prep_Meeting__c = Date.newInstance(eventList[i].ActivityDateTime.year(), eventList[i].ActivityDateTime.month(),eventList[i].ActivityDateTime.day()); } // Tax Prep Meeting if(eventList[i].FSTR__Sub_Type__c == 'Tax Planning Meeting' || eventList[i].Tax_Plan__c) { if(eventList[i].WhatID == a1.Id && eventList[i].ActivityDateTime > a1.Last_Tax_Planning_Meeting__c && eventList[i].Status__c == 'Scheduled') { a1.Last_Tax_Planning_Meeting__c = Date.newInstance(eventList[i].ActivityDateTime.year(), eventList[i].ActivityDateTime.month(),eventList[i].ActivityDateTime.day()); } } // Client Review Meeting if(eventList[i].FSTR__Sub_Type__c == 'Client Review Meeting' && eventList[i].WhatID == a1.Id && eventList[i].ActivityDateTime > a1.Last_Review_Meeting__c && eventList[i].Status__c == 'Scheduled') { a1.Last_Review_Meeting__c = Date.newInstance(eventList[i].ActivityDateTime.year(), eventList[i].ActivityDateTime.month(),eventList[i].ActivityDateTime.day()); } // IPS Update if(eventList[i].IPS_Updated__c && eventList[i].WhatID == a1.Id && eventList[i].ActivityDateTime > a1.Last_IPS_Update__c && eventList[i].Status__c == 'Scheduled') { a1.Last_IPS_Update__c = Date.newInstance(eventList[i].ActivityDateTime.year(), eventList[i].ActivityDateTime.month(), eventList[i].ActivityDateTime.day()); } // FP Update if(eventList[i].Financial_Plan_Update__c && eventList[i].WhatID == a1.Id && eventList[i].ActivityDateTime > a1.Last_FP_Update__c && eventList[i].Status__c == 'Scheduled') { a1.Last_FP_Update__c = Date.newInstance(eventList[i].ActivityDateTime.year(), eventList[i].ActivityDateTime.month(),eventList[i].ActivityDateTime.day()); } } AccountsToUpdate.add (a1); } try { update AccountsToUpdate; update ServicesToUpdate; insert TasksToCreate; } catch (System.DmlException ex) { System.Debug (ex); } } } }
- Sean Barczynski
- October 28, 2015
- Like
- 0
Trigger won't link task to custom object record
Greetings,
I'm having some trouble with a trigger I've written. This is intended to create a task based upon certain fields in a custom object. The tasks are created as expected, except WhatID is not populated in the tasks, therefore they are not linked to the custom object record.
Any thoughts on what may be happening here?
I'm having some trouble with a trigger I've written. This is intended to create a task based upon certain fields in a custom object. The tasks are created as expected, except WhatID is not populated in the tasks, therefore they are not linked to the custom object record.
/********************************************************************** This trigger checks if tax docs are received and/or scanned on Tax_Services__c object and assigns tasks accordingly. **********************************************************************/ trigger Tax_Docs on Tax_Services__c (before insert, before update) { // The sets used to store the IDs of the Accounts or Contacts/Leads within an event that need to get updated /* Set <Id> IdSet = new Set <Id> (); for(Tax_Services__c e : trigger.new) { IdSet.add(e.Id); } // Creates two maps in case whatId is not populated Map<ID, Tax_Services__c> serviceMap = new Map<ID, Tax_Services__c>([select Id, Tax_Docs_Received__c, Tax_Docs_Scanned__c, Business_Account__c, Tax_Advisor__c, Tax_Preparer__c from Tax_Services__c Where Id in :IdSet]); List<Task> taskList = [select Id, WhatID, StartDateTime, ActivityDateTime, FSTR__Sub_Type__c, Status__c, Financial_Plan_Update__c, IPS_Updated__c, Tax_Plan__c from Event Where WhatId in :whatIdSet]; */ // The actual Accounts to save List <Task> TasksToCreate = new List <Task> (); for(Tax_Services__c e : Trigger.new) { if(Trigger.isUpdate) { Tax_Services__c oldService = Trigger.oldMap.get(e.ID); if(e.Tax_Docs_Received__c == TRUE && e.Tax_Docs_Scanned__c == TRUE) { if(e.Tax_Docs_Received__c != oldService.Tax_Docs_Received__c || e.Tax_Docs_Scanned__c != oldService.Tax_Docs_Scanned__c) { TasksToCreate.add(new Task(OwnerID = e.Tax_Advisor__c, Subject = 'Tax Docs Received and Scanned', WhatID = e.Id, ActivityDate = date.today(), Status = 'Not Started', Priority = 'Normal', Hidden__c = 'Tax Docs Received & Scanned')); } } if(e.Tax_Docs_Received__c == TRUE && e.Tax_Docs_Scanned__c == FALSE) { if(e.Tax_Docs_Received__c != oldService.Tax_Docs_Received__c || e.Tax_Docs_Scanned__c != oldService.Tax_Docs_Scanned__c) { TasksToCreate.add(new Task(OwnerID = e.Tax_Advisor__c, Subject = 'Scan Tax Docs', WhatID = e.Id, ActivityDate = date.today(), Status = 'Not Started', Priority = 'Normal', Hidden__c = 'Scan Tax Docs')); } } } if(Trigger.isInsert) { if(e.Tax_Docs_Received__c == TRUE && e.Tax_Docs_Scanned__c == TRUE) { TasksToCreate.add(new Task(OwnerID = e.Tax_Advisor__c, Subject = 'Tax Docs Received and Scanned', WhatID = e.Id, ActivityDate = date.today(), Status = 'Not Started', Priority = 'Normal', Hidden__c = 'Tax Docs Received & Scanned')); } if(e.Tax_Docs_Received__c == TRUE && e.Tax_Docs_Scanned__c == FALSE) { TasksToCreate.add(new Task(OwnerID = e.Tax_Advisor__c, Subject = 'Scan Tax Docs', WhatID = e.Id, ActivityDate = date.today(), Status = 'Not Started', Priority = 'Normal', Hidden__c = 'Scan Tax Docs')); } } /* if(e.WhatID != null && accountMap.containsKey(e.whatId)) { } */ } try { Insert TasksToCreate; } catch (System.DmlException ex) { System.Debug (ex); } }
Any thoughts on what may be happening here?
- Sean Barczynski
- October 18, 2015
- Like
- 0
Last Meeting Date
Hello,
I'm attempting to write my first trigger, so please bare with me while I explain.
The purpose of the trigger is to update some date fields based upon Events to show when the last meeting of various types was completed. I've seen a few different threads on this site that I was able to pull some ideas from, but have been unable to figure out how to get one particular piece to work. The issue comes when a meeting is Canceled or Rescheduled. We want to keep these events in the system so we can refer back to them in the future (e.g. if a client says we haven't seen them in over a year, we can go back and see that they canceled on us twice), but we don't want these events to be reflected in the Last Meeting fields.
I believe I have it written correctly so far to update the field when a meeting is not Canceled or Rescheduled, I just don't know how to get it to work once the meeting is Canceled. Theoretically, the field would already be updated with this meeting date, so I'd want the trigger to look back and pull the last meeting that was not canceled or rescheduled. I have two ideas:
Thanks in advance for any help!
I'm attempting to write my first trigger, so please bare with me while I explain.
The purpose of the trigger is to update some date fields based upon Events to show when the last meeting of various types was completed. I've seen a few different threads on this site that I was able to pull some ideas from, but have been unable to figure out how to get one particular piece to work. The issue comes when a meeting is Canceled or Rescheduled. We want to keep these events in the system so we can refer back to them in the future (e.g. if a client says we haven't seen them in over a year, we can go back and see that they canceled on us twice), but we don't want these events to be reflected in the Last Meeting fields.
I believe I have it written correctly so far to update the field when a meeting is not Canceled or Rescheduled, I just don't know how to get it to work once the meeting is Canceled. Theoretically, the field would already be updated with this meeting date, so I'd want the trigger to look back and pull the last meeting that was not canceled or rescheduled. I have two ideas:
- Loop through the Account's Events and find the most recent one that was not canceled or rescheduled. I'm thinking this would cause too many database queries and may throw an error.
- Create a second field (not visible on the Page Layout) that contains the last successful meeting date before this one.
trigger LastEventDate on Event (after insert, after update) { // The sets used to store the IDs of the Accounts or Contacts/Leads within an event that need to get updated Set <Id> whoIdSet = new Set <Id> (); Set <Id> whatIdSet = new Set <Id> (); for(Event e : trigger.net) { if(e.WhoId != null) { whoIdSet.add(e.WhoId); } if(e.WhatId != null && e.WhoId == null) { whatIdSet.add(e.WhatId); } } // Creates two maps in case whoId or whatId is not populated Map<ID, Contact> contactMap = new Map<ID, Contact>([select Id, AccountId from Contact Where Id in :whoIdSet]); Map<ID, Account> accountMap = new Map<ID, Account>([select Id, Last_Review_Meeting__c, Last_FP_Update__c, Last_IPS_Update__c, Last_Tax_Planning_Meeting__c, Last_Tax_Prep_Meeting__c from Account Where Id in :whatIdSet]); // The actual Accounts to save List <Accounts> Scheduled = new List <Accounts> (); List <Accounts> CancelledRescheduled = new List <Accounts> (); for(Event e : Trigger.new) { if(e.whoID != null && contactMap.containsKey(e.whoId)) { //If meeting is scheduled as planned, set this meeting date to the appropriate Last Meeting Date field if(e.Status__c != "Canceled" && e.Status__c != "Re-Scheduled") { Contact c1 = contactMap.get(e.whoId); if(c1.AccountId != null) { Account a1 = c1.AccountId; Date d1 = Data.newInstance(e.StartDateTime.year(), e.StartDateTime.month(), e.StartDateTime.day()); if(e.FSTR__Sub_Type__c == "Tax Preparation Meeting") { if(d1 > a1.Last_Tax_Prep_Meeting__c) { a1.Last_Tax_Prep_Meeting__c = d1; } } if(e.FSTR__Sub_Type__c == "Tax Planning Meeting" || Tax_Plan__c == TRUE) { if(d1 > a1.Last_Tax_Planning_Meeting__c) { a1.Last_Tax_Planning_Meeting__c = d1; } } if(e.FSTR__Sub_Type__c == "Client Review Meeting") { if(d1 > a1.Last_Review_Meeting__c) { a1.Last_Review_Meeting__c = d1; } } if(e.Financial_Plan_Update__c == TRUE) { if(d1 > a1.Last_FP_Update__c) { a1.Last_FP_Update__c = d1; } } if(e.IPS_Updated__c == TRUE) { if(d1 > a1.Last_IPS_Update__c) { a1.Last_IPS_Update__c = d1; } } Scheduled.add (a1); } } // If meeting is canceled or rescheduled, set appropriate Last Meeting field to last meeting date that was not canceled or rescheduled if(e.Status__c == "Canceled" || e.Status__c == "Re-Scheduled") { } } } }
Thanks in advance for any help!
- Sean Barczynski
- August 17, 2015
- Like
- 0