-
ChatterFeed
-
0Best Answers
-
1Likes Received
-
0Likes Given
-
35Questions
-
15Replies
Trigger, after first SOQL seems to stop executing without error.
When I run my test class the first few lines will execute but then the logs seem to show it stops executing for no reason. I get the first two system.debugs so I know it is partially executing.
This Trigger will send an email message if an Account has 8 or more cases created within 7 days. Depending on the status of the four fields in the If/Else block will dictate the destination of the email. If the status is "Active" 1 email is sent to a set email address. If the status is "Implementation" then 2 emails are sent, addresses are grabbed from SOQL.
Any help is appreciated.
Test Class:
This Trigger will send an email message if an Account has 8 or more cases created within 7 days. Depending on the status of the four fields in the If/Else block will dictate the destination of the email. If the status is "Active" 1 email is sent to a set email address. If the status is "Implementation" then 2 emails are sent, addresses are grabbed from SOQL.
Any help is appreciated.
trigger CaseCountAlertTrigger on Case (before insert) { List<String> emailAdds = new List<String>(); // Holds '2' ToAddresses from Milestone1_project__c object Set <Id> AcctIds = new Set <Id>(); //Holds Account Ids from this Case Trigger String messageToSend; //Email body sent in email (will be in HTML format) Map < Id, String > accountIdEmailmessageMap = new Map < Id, String > (); // map of AccountId and Email body per Account/AccountId to be sent List < AggregateResult > AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co FROM Case WHERE CreatedDate = LAST_N_DAYS:7 AND Id in :Trigger.New GROUP BY Account.Name, AccountId HAVING COUNT(Id) >= 8 ]; System.debug('AggregateResult: ' + AggregateResultList); // debugs: 'AggregateResult: ()' --emtpy aggregate list System.debug('Trigger Results' + Trigger.new); // This line will print the Case that comes in as Trigger.New, debugs as expected. // ******** It seems to exit here*************** for (AggregateResult aggr: AggregateResultList){ messageToSend = 'You are receiving this email alert due to an account '; messageToSend += 'activity rule has exceeded 8 cases created within 5 business days.<br><br>'; messageToSend += 'Please, follow up with the account and provide guidance and assistance.<br><br>'; messageToSend += '<b>Account Name: </b>' + aggr.get('name') + '<br> <br>'; messageToSend += 'Thank you, <br>'; messageToSend += 'Salesforce Team'; //Crete Map of <AccountId, Message to serve as body in Email // for each accountId> Id accId = (Id) aggr.get('AccountId'); accountIdEmailmessageMap.put(accId, messageToSend); //Create List of AccountId's to grab email addresses // from child Object for 'Implementation Status AcctIds.add(accId); } System.debug(accountIdEmailmessageMap); /* List < Case > caseList = [SELECT Id, AccountId, Account.Name, Account.Eyefinity_EHR_Status__c, Account.Eyefinity_PM_Status__c, Account.OfficeMate_Status__c, Account.Project_Imp_Status__c FROM Case WHERE AccountId IN: AcctIds]; */ // SOQL to grab the four status fields on Account to check status either 'Active' or 'Implementation' // also grab two email addresses for use in ifElse block List<Account> accList = [SELECT Id, Name, Eyefinity_EHR_Status__c, Eyefinity_PM_Status__c, Project_Imp_Status__c, OfficeMate_Status__c,(select Client_Advisor_Email__c, Resource_Coordinator_Email__c from Projects__r) FROM Account WHERE Id IN :AcctIds]; List<Messaging.SingleEmailMessage> lstASingleEmailMessage = new List<Messaging.SingleEmailMessage>(); List<Messaging.SingleEmailMessage> lstBSingleEmailMessage = new List<Messaging.SingleEmailMessage>(); for (Account al: accList) { if (al.Eyefinity_EHR_Status__c == 'Active' || al.Eyefinity_PM_Status__c == 'Active' || al.Project_Imp_Status__c == 'Active' || al.OfficeMate_Status__c == 'Active') { // String messageBody = accountIdEmailmessageMap.get(al.accId); //Send Email to CustomerService if Active List<String> emailaddr = new List<String>(); emailaddr.add('CustomerSuccessManagers@test.com'); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setSenderDisplayName(' Support'); mail.setToAddresses(emailaddr); mail.Subject = 'Notification: Account Case activity rule exceeded'; mail.setHtmlBody(messageToSend); lstASingleEmailMessage.add(mail); } else if (al.Eyefinity_EHR_Status__c == 'Implementation' || al.Eyefinity_PM_Status__c == 'Implementation' || al.Project_Imp_Status__c == 'Implementation' || al.OfficeMate_Status__c == 'Implementation'){ String messageBody1 = accountIdEmailmessageMap.get(cl.AccountId); System.debug('Accounts: ' + al); //Send email to Coordinator and Advisor if in Implementation for(Account a : accList) { for(Milestone1_Project__c p : a.Projects__r) { emailAdds.add(p.Client_Advisor_Email__c); emailAdds.add(p.Resource_Coordinator_Email__c); } } System.debug(emailAdds); Messaging.SingleEmailMessage amail = new Messaging.SingleEmailMessage(); amail.SetSenderDisplayName('Support'); amail.setToAddresses(emailAdds); amail.Subject = 'Notification: Account Case activity rule exceeded'; amail.setHtmlBody(messageBody1); lstASingleEmailMessage.add(amail); } else{ System.debug(AggregateResultList); } } Messaging.SendEmailResult[] r = Messaging.sendEmail(lstASingleEmailMessage); }
Test Class:
@isTest private class TestCaseHandlerAlert { @testSetup static void setup(){ List<Account> testAccounts = new List<Account>(); Account a = new Account(); a.name = 'AccountEHRImplement'; a.RecordTypeId = '01230000000v58OAAQ'; a.Eyefinity_EHR_Status__c = 'Implementation'; a.Tax_Id__c = '123456789'; testAccounts.add(a); //Insert Account insert testAccounts; //Create User: THis user will fill required fields on the Milestone1_Project1 allowing for a an email address to populate User tuser = new User( firstname = 'tuserFname', lastName = 'tuserLastname', email = 'test@tester.com', Username = 'tuserleielkwl@test18278391.org', EmailEncodingKey = 'ISO-8859-1', Alias ='Blah', TimeZoneSidKey = 'America/Los_Angeles', LocaleSidKey = 'en_US', LanguageLocaleKey = 'en_US', ProfileId =[Select Id From Profile Where Name='Eyefinity Managers'].id ); insert tuser; //Create Project Milestone1_Project__c project1 = new Milestone1_Project__c(); project1.Customer_Account__c = [Select Id FROM Account Where Name ='AccountEHRImplement'].id; project1.Name = 'triggerProject'; project1.Client_Advisor__c = [Select Id FROM User Where Username ='tuserleielkwl@test18278391.org'].id; project1.Resource_Coordinator__c = [Select Id FROM User Where Username ='tuserleielkwl@test18278391.org'].id; project1.RecordTypeId = '01214000001RYp7AAG'; insert project1; } @isTest static void AccountEHRImplement (){ //Create and insert more than more than 8 cases List<Case> casestoInsert = new List<Case>(); for (Integer i=1; i<10; i++){ Case cas1 = new Case(); cas1.RecordTypeId = '01214000001NcOYAA0'; cas1.AccountId = [Select Id FROM Account Where name ='AccountEHRImplement'].id; cas1.Origin = 'Phone'; cas1.Impact__c = 'Low'; cas1.Severity__c = 'Minor'; cas1.Type = 'Bridge'; casesToInsert.add(cas1); } Test.startTest(); insert casesToInsert; Test.stopTest(); System.debug('Expected: 2, actual: ' + Limits.getEmailInvocations()); } }
-
- Timothy Smith
- November 24, 2019
- Like
- 0
SOQL subquery access variables
Attempting to access the variables MIlestone1_Project__c has a Lookup relationship to Account with relationship name: `Projects__r'.
Any help is greatly appreciated.
List<Account> accList = [SELECT Id, Name, EHR_Status__c, PM_Status__c, Project_Imp_Status__c, Other_Status__c,(select Client_Advisor_Email__c, Resource_Coordinator_Email__c from Projects__r) FROM Account WHERE Id IN :AcctIds];
List<String> emailAdds = new List<String>(); for (Account al: accList) { emailAdds.add(al.Projects__r.Client_Advisor_Email__c); emailAdds.add(al.Projectss__r.Resource_Coordinator_Email__c); }
Any help is greatly appreciated.
-
- Timothy Smith
- November 22, 2019
- Like
- 0
Trigger sends more than one email.
This email will send an email alert when an account has 8 cases open within 7 days. The email is being sent, but multiple emails for the Same account are being sent. What is wrong with my code that it is creating multiple emails for the same account?
Trigger:
Trigger:
trigger CaseHandlerCountAlert on Case (after insert, after update) { //Case trigger that will send email alert when 8 cases are created within 7 days. String messageToSend; List <String> ListOfMessages = new List <String>(); Set <Id> AcctIds = new Set <Id>(); String messageBody; List < AggregateResult > AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co FROM Case WHERE CreatedDate = LAST_N_DAYS:7 AND Id IN :Trigger.New GROUP BY AccountId, Account.Name HAVING COUNT(Id) >= 8 ]; Map < Id, String > accountIdEmailmessageMap = new Map < Id, String > (); for (AggregateResult aggr: AggregateResultList) { String messageToSend = 'Account name: ' + aggr.get('name') + ' has ' + (Integer) aggr.get('co') + ' cases opened in the last 8 days.'; Id accId = (Id) aggr.get('AccountId'); accountIdEmailmessageMap.put(accId, messageToSend); AcctIds.add(accId); } List < Case > caseList = [SELECT Id, AccountId, Account.Name, Parent_Project_if_applicable__r.Implementation_status__c, Parent_Project_if_applicable__r.PM_Implementation_Status__c, Parent_Project_if_applicable__r.RCM_Implementation_Status__c, Parent_Project_if_applicable__r.Resource_Coordinator_Email__c, Parent_Project_if_applicable__r.Client_Advisor_Email__c FROM Case WHERE AccountId IN: AcctIds]; List<Messaging.SingleEmailMessage> lstASingleEmailMessage = new List<Messaging.SingleEmailMessage>(); List<Messaging.SingleEmailMessage> lstBSingleEmailMessage = new List<Messaging.SingleEmailMessage>(); for (Case cl: caseList) { if (cl.Parent_Project_if_applicable__r.Implementation_status__c == 'Live - Closed Project' || cl.Parent_Project_if_applicable__r.PM_Implementation_Status__c == 'Live - Closed Project' || cl.Parent_Project_If_Applicable__r.RCM_Implementation_Status__c == 'Live - Closed Project') { String messageBody = accountIdEmailmessageMap.get(cl.AccountId); List<String> emailaddr = new List<String>(); emailaddr.add('CustomerSuccessManagers@test.com'); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setSenderDisplayName('Support'); mail.setToAddresses(emailaddr); mail.Subject = 'Multiple cases created alert message'; mail.setPlainTextBody(messageBody); lstASingleEmailMessage.add(mail); }else{ String messageBody1 = accountIdEmailmessageMap.get(cl.AccountId); List<String> emailAdds = new List<String>(); emailAdds.add(cl.Parent_Project_if_applicable__r.Resource_Coordinator_Email__c); emailAdds.add(cl.Parent_Project_if_applicable__r.Client_Advisor_Email__c); Messaging.SingleEmailMessage amail = new Messaging.SingleEmailMessage(); amail.SetSenderDisplayName('Support'); amail.setToAddresses(emailAdds); amail.Subject = 'Multiple cases created alert message'; amail.setPlainTextBody(messageBody1); lstBSingleEmailMessage.add(amail); } } Messaging.SendEmailResult[] r = Messaging.sendEmail(lstASingleEmailMessage); Messaging.SendEmailResult[] rb = Messaging.sendEmail(lstBSingleEmailMessage); }
-
- Timothy Smith
- November 16, 2019
- Like
- 0
Creating Test class - CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY
My Trigger sends an email message when an Account has 8 cases created within 7 days. The Case object has a Lookup relationship to the Milestone1__project__c object has a relationship name Parent_Project_If_Applicable__r.
If any of these fields are equal to 'Live - Closed Project':
Parent_Project_if_applicable__r.Implementation_status__c Parent_Project_if_applicable__r.PM_Implementation_Status__c Parent_Project_If_Applicable__r.RCM_Implementation_Status__c
Then the Email is sent to the address in the IF BLock. Any other value the email is sent through the Else Block.
Every test pass except setup. I am trying to create a user (preferably two) with email addresses. I found that the fields Parent_Project_if_applicable__r.Resource_Coordinator_Email__c and Parent_Project_if_applicable__r.Client_Advisor_Email__c are formula fields grabbing the email in a formula that looks like this Client_Advisor__r.Email and Resource_Coordinator_Email__c .
How do I add Insert the user so that I can test that the emails would go to the right destination?
Test Class:
Trigger:
If any of these fields are equal to 'Live - Closed Project':
Parent_Project_if_applicable__r.Implementation_status__c Parent_Project_if_applicable__r.PM_Implementation_Status__c Parent_Project_If_Applicable__r.RCM_Implementation_Status__c
Then the Email is sent to the address in the IF BLock. Any other value the email is sent through the Else Block.
Every test pass except setup. I am trying to create a user (preferably two) with email addresses. I found that the fields Parent_Project_if_applicable__r.Resource_Coordinator_Email__c and Parent_Project_if_applicable__r.Client_Advisor_Email__c are formula fields grabbing the email in a formula that looks like this Client_Advisor__r.Email and Resource_Coordinator_Email__c .
How do I add Insert the user so that I can test that the emails would go to the right destination?
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CaseHandlerCountAlert: execution of AfterInsert caused by: System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_EMAIL_ADDRESS, Email address is invalid: null: [toAddresses, null] Trigger.CaseHandlerCountAlert: line 78, column 1: []
Test Class:
@isTest private class TestCaseHandlerAlert { @TestSetup static void setup(){ //Create user to populate field Resource Coord. and Implementation Spec. Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; User u = new User(Alias = 'testER', Email='standarduser@testorg.com', EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', LocaleSidKey='en_US', ProfileId = p.Id, TimeZoneSidKey='America/Los_Angeles', UserName='standarduser101@testorg.com'); insert u; system.debug(u.email); // Create and Insert 2 Accounts Account a = new Account(); Account b = new Account(); a.name = 'testacct21'; b.name = 'testacct31'; //Set Contact id to variables // Id userIDToInsert = [select id from User Where username='standarduser101@testorg.com'].id; // Create Milestones //This Milestone will fire the If Block Milestone1_Project__c project1 = new Milestone1_Project__c(); project1.Name = 'triggertestLIVE'; project1.RCM_Implementation_Status__c = 'LIVE - CLOSED PROJECT'; project1.PM_Implementation_Status__c= 'RETURNED SOFTWARE'; project1.Implementation_Status__c= 'RETURNED SOFTWARE'; project1.Resource_Coordinator__c = u.Id; project1.Client_Advisor__c = u.Id; Milestone1_Project__c project = new Milestone1_Project__c(); project.Name = 'triggertest21'; project.RCM_Implementation_Status__c = 'RETURNED SOFTWARE'; project.PM_Implementation_Status__c= 'RETURNED SOFTWARE'; project.Implementation_Status__c= 'RETURNED SOFTWARE'; project1.Resource_Coordinator__c = u.Id; project1.Client_Advisor__c = u.id; //Insert Account insert a; insert b; //Insert Project insert project; insert project1; //Create 10 Cases associated with Project List<Case> casesToInsert = new List<Case>(); List<Case> casesToInsert1 = new List<Case>(); for (Integer i=1; i<10; i++){ Case c = new Case(); c.AccountId = a.id; c.Origin = 'Phone'; c.Impact__c = 'Low'; c.Severity__c = 'Minor'; c.Type = 'Bridge'; c.Parent_Project_if_applicable__c = project1.id; casesToInsert.add(c); } for (Integer i=1; i<10; i++){ Case c1 = new Case(); c1.AccountId = b.id; c1.Origin = 'Phone'; c1.Impact__c = 'Low'; c1.Severity__c = 'Minor'; c1.Type = 'Bridge'; c1.Parent_Project_if_applicable__c = project.id; casesToInsert.add(c1); } insert casesToInsert; insert casesToInsert1; } @isTest static void DontSendNotLimit (){ // Do not send, not enough Cases need 8 List<Case> testCases = [SELECT Id FROM Case WHERE Account.Name='testacct21' LIMIT 5]; List<Case> insertCases = new List<Case>(); Test.startTest(); insert insertCases; System.debug('Should be 0 emails sent: ' + Limits.getEmailInvocations()); Test.stopTest(); } @isTest static void SendElseBlock (){ // Else BLock Fires - 2 emails sent List<Case> testCases = [SELECT Id FROM Case WHERE Account.Name='testacct21' LIMIT 8]; List<Case> insertCases = new List<Case>(); Test.startTest(); insert insertCases; System.debug('Should be 3: ' + Limits.getEmailInvocations()); Test.stopTest(); } @isTest static void SendRCMiFBlock (){ // Fires the If BLock 1/3 List<Case> testCases = [SELECT Id FROM Case WHERE Account.Name='testacct31' LIMIT 8]; List<Case> insertCases = new List<Case>(); for(Case cas :testCases ){ insertCases.add(cas); } Test.startTest(); insert insertCases; Test.stopTest(); } @isTest static void SendPMiFBlock (){ // Fires the If BLock 2/3 List<Case> testCases = [SELECT Id FROM Case WHERE Account.Name='testacct31' LIMIT 8]; List<Case> insertCases = new List<Case>(); for(Case cas :testCases ){ cas.Parent_Project_if_applicable__r.PM_Implementation_Status__c = 'LIVE - CLOSED PROJECT'; insertCases.add(cas); } Test.startTest(); insert insertCases; Test.stopTest(); } @isTest static void SendIMPiFBlock (){ // Fires the If BLock 3/3 List<Case> testCases = [SELECT Id FROM Case WHERE Account.Name='testacct31' LIMIT 8]; List<Case> insertCases = new List<Case>(); for(Case cas :testCases ){ cas.Parent_Project_if_applicable__r.Implementation_Status__c= 'LIVE - CLOSED PROJECT'; insertCases.add(cas); } Test.startTest(); insert insertCases; Test.stopTest(); } }
Trigger:
trigger CaseHandlerCountAlert on Case (after insert, after update) { //Case trigger that will send email alert when 8 cases are created within 7 days. String messageToSend; List <String> ListOfMessages = new List <String>(); Set <Id> AcctIds = new Set <Id>(); String messageBody; List < AggregateResult > AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co FROM Case WHERE CreatedDate = LAST_N_DAYS:7 AND Id IN :Trigger.New GROUP BY AccountId, Account.Name HAVING COUNT(Id) >= 8 ]; Map < Id, String > accountIdEmailmessageMap = new Map < Id, String > (); for (AggregateResult aggr: AggregateResultList) { String messageToSend = 'Account name: ' + aggr.get('name') + ' has ' + (Integer) aggr.get('co') + ' cases opened in the last 8 days.'; Id accId = (Id) aggr.get('AccountId'); accountIdEmailmessageMap.put(accId, messageToSend); AcctIds.add(accId); } List < Case > caseList = [SELECT Id, AccountId, Account.Name, Parent_Project_if_applicable__r.Implementation_status__c, Parent_Project_if_applicable__r.PM_Implementation_Status__c, Parent_Project_if_applicable__r.RCM_Implementation_Status__c, Parent_Project_if_applicable__r.Resource_Coordinator_Email__c, Parent_Project_if_applicable__r.Client_Advisor_Email__c FROM Case WHERE AccountId IN: AcctIds]; List<Messaging.SingleEmailMessage> lstASingleEmailMessage = new List<Messaging.SingleEmailMessage>(); List<Messaging.SingleEmailMessage> lstBSingleEmailMessage = new List<Messaging.SingleEmailMessage>(); for (Case cl: caseList) { if (cl.Parent_Project_if_applicable__r.Implementation_status__c == 'Live - Closed Project' || cl.Parent_Project_if_applicable__r.PM_Implementation_Status__c == 'Live - Closed Project' || cl.Parent_Project_If_Applicable__r.RCM_Implementation_Status__c == 'Live - Closed Project') { String messageBody = accountIdEmailmessageMap.get(cl.AccountId); List<String> emailaddr = new List<String>(); emailaddr.add('GlobalEmailAddress@domain.com'); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setSenderDisplayName('Support'); mail.setToAddresses(emailaddr); mail.Subject = 'Multiple cases created alert message'; mail.setPlainTextBody(messageBody); lstASingleEmailMessage.add(mail); }else{ String messageBody1 = accountIdEmailmessageMap.get(cl.AccountId); List<String> emailAdds = new List<String>(); emailAdds.add(cl.Parent_Project_if_applicable__r.Resource_Coordinator_Email__c); emailAdds.add(cl.Parent_Project_if_applicable__r.Client_Advisor_Email__c); Messaging.SingleEmailMessage amail = new Messaging.SingleEmailMessage(); amail.SetSenderDisplayName('Support'); amail.setToAddresses(emailAdds); amail.Subject = 'Multiple cases created alert message'; amail.setPlainTextBody(messageBody1); lstBSingleEmailMessage.add(amail); } } Messaging.SendEmailResult[] r = Messaging.sendEmail(lstASingleEmailMessage); Messaging.SendEmailResult[] rb = Messaging.sendEmail(lstBSingleEmailMessage); }
-
- Timothy Smith
- November 12, 2019
- Like
- 0
Test Case - Attempt to de-reference a null object (Formula Field)
I get 100% test coverage but receiving error on setup method:
`System.NullPointerException: Attempt to de-reference a null object
(TestCasehandlerAlert.setup: line 17, column 1)`
The email address fields are formula fields. The formula fields are `Client_Advisor__r.Email` and `Resource_Coordinator__r.Email.` The trigger will send an email message if an account has 8 cases or more created within 7 days. If the value of any of three specified fields is "Live - Closed Project", the email is sent to a single email address. If any of the three fields is equal to "Live - Closed Project", the Else block is fired and email is sent to two other email addresses.
I am trying to create two types of projects; one will run through the IF statement, the other will run through the Else statement.
Trigger:
trigger CaseHandlerCountAlert on Case (after insert) { //Case trigger that will send email alert when 8 cases are created within 7 days. String messageToSend; List <String> ListOfMessages = new List <String>(); Set <Id> AcctIds = new Set <Id>(); String messageBody; List < AggregateResult > AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co FROM Case WHERE CreatedDate = LAST_N_DAYS:7 AND Id IN :Trigger.New GROUP BY AccountId, Account.Name HAVING COUNT(Id) >= 8 ]; Map < Id, String > accountIdEmailmessageMap = new Map < Id, String > (); for (AggregateResult aggr: AggregateResultList) { String messageToSend = 'Account name: ' + aggr.get('name') + ' has ' + (Integer) aggr.get('co') + ' cases opened in the last 8 days.'; Id accId = (Id) aggr.get('AccountId'); accountIdEmailmessageMap.put(accId, messageToSend); AcctIds.add(accId); } List < Case > caseList = [SELECT Id, AccountId, Account.Name, Parent_Project_if_applicable__r.Implementation_status__c, Parent_Project_if_applicable__r.PM_Implementation_Status__c, Parent_Project_if_applicable__r.RCM_Implementation_Status__c, Parent_Project_if_applicable__r.Resource_Coordinator_Email__c, Parent_Project_if_applicable__r.Client_Advisor_Email__c FROM Case WHERE AccountId IN: AcctIds]; List<Messaging.SingleEmailMessage> lstASingleEmailMessage = new List<Messaging.SingleEmailMessage>(); List<Messaging.SingleEmailMessage> lstBSingleEmailMessage = new List<Messaging.SingleEmailMessage>(); for (Case cl: caseList) { if (cl.Parent_Project_if_applicable__r.Implementation_status__c == 'Live - Closed Project' || cl.Parent_Project_if_applicable__r.PM_Implementation_Status__c == 'Live - Closed Project' || cl.Parent_Project_If_Applicable__r.RCM_Implementation_Status__c == 'Live - Closed Project') { String messageBody = accountIdEmailmessageMap.get(cl.AccountId); List<String> emailaddr = new List<String>(); emailaddr.add('CustomerSuccessManagers@test.com'); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setSenderDisplayName('Support'); mail.setToAddresses(emailaddr); mail.Subject = 'Multiple cases created alert message'; mail.setPlainTextBody(messageBody); lstASingleEmailMessage.add(mail); }else{ String messageBody = accountIdEmailmessageMap.get(cl.AccountId); List<String> emailAdds = new List<String>(); emailAdds.add(cl.Parent_Project_if_applicable__r.Resource_Coordinator_Email__c); emailAdds.add(cl.Parent_Project_if_applicable__r.Client_Advisor_Email__c); Messaging.SingleEmailMessage amail = new Messaging.SingleEmailMessage(); amail.SetSenderDisplayName('Support'); amail.setToAddresses(emailAdds); amail.Subject = 'Multiple cases created alert message'; amail.setPlainTextBody(messageBody); lstBSingleEmailMessage.add(amail); System.debug('messageBody: ' + messageBody); System.debug('email message: ' + amail); } } Messaging.SendEmailResult[] r = Messaging.sendEmail(lstASingleEmailMessage); Messaging.SendEmailResult[] rb = Messaging.sendEmail(lstBSingleEmailMessage); }
Test Class:
@isTest private class TestCaseHandlerAlert { @isTest static void setup(){ Account a = new Account(); Account b = new Account(); a.name = 'testacct21'; b.name = 'testacct31'; // Create Milestone Milestone1_Project__c project = new Milestone1_Project__c(); project.Name = 'triggertest21'; project.RCM_Implementation_Status__c = 'RETURNED SOFTWARE'; project.PM_Implementation_Status__c= 'RETURNED SOFTWARE'; project.Implementation_Status__c= 'RETURNED SOFTWARE'; Milestone1_Project__c project1 = new Milestone1_Project__c(); //project.RecordTypeId = '01214000001RYp2AAG'; project1.Name = 'triggertest31'; project1.RCM_Implementation_Status__c = 'LIVE - CLOSED PROJECT'; project1.PM_Implementation_Status__c= 'RETURNED SOFTWARE'; project1.Implementation_Status__c= 'RETURNED SOFTWARE'; //Insert Account insert a; insert b; //Insert Project insert project; insert project1; //Create 10 Cases associated with Project List<Case> casesToInsert = new List<Case>(); List<Case> casesToInsert1 = new List<Case>(); for (Integer i=1; i<12; i++){ Case c1 = new Case(); c1.AccountId = b.id; c1.Origin = 'Phone'; c1.Impact__c = 'Low'; c1.Severity__c = 'Minor'; c1.Type = 'Bridge'; c1.Parent_Project_if_applicable__c = project.id; casesToInsert1.add(c1); } for (Integer i=1; i<12; i++){ Case c = new Case(); c.AccountId = a.id; c.Origin = 'Phone'; c.Impact__c = 'Low'; c.Severity__c = 'Minor'; c.Type = 'Bridge'; c.Parent_Project_if_applicable__c = project1.id; casesToInsert.add(c); } insert casesToInsert; insert casesToInsert1; } @isTest static void DontSendNotLimit (){ // Do not send, not enough Cases need 8 List<Case> testCases = [SELECT Id FROM Case WHERE Account.Name='testacct21' LIMIT 5]; List<Case> insertCases = new List<Case>(); Test.startTest(); insert insertCases; System.debug(Limits.getEmailInvocations()); Test.stopTest(); } @isTest static void SendElseBlock (){ // Else BLock Fires - 2 emails sent List<Case> testCases = [SELECT Id FROM Case WHERE Account.Name='testacct21' LIMIT 8]; List<Case> insertCases = new List<Case>(); Test.startTest(); insert insertCases; System.debug(Limits.getEmailInvocations()); Test.stopTest(); } @isTest static void SendRCMiFBlock (){ // Fires the If BLock 1/3 List<Case> testCases = [SELECT Id FROM Case WHERE Account.Name='testacct31' LIMIT 8]; List<Case> insertCases = new List<Case>(); for(Case cas :testCases ){ insertCases.add(cas); } Test.startTest(); insert insertCases; Test.stopTest(); } @isTest static void SendPMiFBlock (){ // Fires the If BLock 2/3 List<Case> testCases = [SELECT Id FROM Case WHERE Account.Name='testacct31' LIMIT 8]; List<Case> insertCases = new List<Case>(); for(Case cas :testCases ){ cas.Parent_Project_if_applicable__r.PM_Implementation_Status__c = 'LIVE - CLOSED PROJECT'; insertCases.add(cas); } Test.startTest(); insert insertCases; Test.stopTest(); } @isTest static void SendIMPiFBlock (){ // Fires the If BLock 3/3 List<Case> testCases = [SELECT Id FROM Case WHERE Account.Name='testacct31' LIMIT 8]; List<Case> insertCases = new List<Case>(); for(Case cas :testCases ){ cas.Parent_Project_if_applicable__r.Implementation_Status__c= 'LIVE - CLOSED PROJECT'; insertCases.add(cas); } Test.startTest(); insert insertCases; Test.stopTest(); } }
-
- Timothy Smith
- November 11, 2019
- Like
- 0
Expecting '}' but was: 'else'. Line 64
trigger CaseHandlerCountAlert on Case (after insert) { //Case trigger that will send email alert when 8 cases are created within 7 days. String messageToSend; List <String> ListOfMessages = new List <String>(); Set <Id> AcctIds = new Set <Id>(); String messageBody; List < AggregateResult > AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co FROM Case WHERE CreatedDate = LAST_N_DAYS:7 AND Id IN :Trigger.New GROUP BY AccountId, Account.Name HAVING COUNT(Id) >= 8 ]; Map < Id, String > accountIdEmailmessageMap = new Map < Id, String > (); for (AggregateResult aggr: AggregateResultList) { String messageToSend = 'Account name: ' + aggr.get('name') + ' has ' + (Integer) aggr.get('co') + ' cases opened in the last 8 days.'; Id accId = (Id) aggr.get('AccountId'); accountIdEmailmessageMap.put(accId, messageToSend); AcctIds.add(accId); } List < Case > caseList = [SELECT Id, AccountId, Account.Name, Parent_Project_if_applicable__r.Implementation_status__c, Parent_Project_if_applicable__r.PM_Implementation_Status__c, Parent_Project_if_applicable__r.RCM_Implementation_Status__c, Parent_Project_if_applicable__r.Resource_Coordinator_Email__c, Parent_Project_if_applicable__r.Client_Advisor_Email__c FROM Case WHERE AccountId IN: AcctIds]; List<Messaging.SingleEmailMessage> lstASingleEmailMessage = new List<Messaging.SingleEmailMessage>(); List<Messaging.SingleEmailMessage> lstBSingleEmailMessage = new List<Messaging.SingleEmailMessage>(); for (Case cl: caseList) { if (cl.Parent_Project_if_applicable__r.Implementation_status__c == 'Live - Closed Project' || cl.Parent_Project_if_applicable__r.PM_Implementation_Status__c == 'Live - Closed Project' || cl.Parent_Project_If_Applicable__r.RCM_Implementation_Status__c == 'Live - Closed Project') { String messageBody = accountIdEmailmessageMap.get(cl.AccountId); List<String> emailaddr = new List<String>(); emailaddr.add('CustomerSuccessManagers@test.com'); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setSenderDisplayName('Support'); mail.setToAddresses(emailaddr); mail.Subject = 'Multiple cases created alert message'; mail.setPlainTextBody(messageBody); lstASingleEmailMessage.add(mail); } } Messaging.SendEmailResult[] r = Messaging.sendEmail(lstASingleEmailMessage); else{ String messageBody = accountIdEmailmessageMap.get(cl.AccountId); List<String> emailAdds = new List<String>(); emailAdds.add(cl.Parent_Project_if_applicable__r.Resource_Coordinator_Email__c); emailAdds.add(cl.Parent_Project_if_applicable__r.Client_Advisor_Email__c); Messaging.SingleEmailMessage amail = new Messaging.SingleEmailMessage(); amail.SetSenderDisplayName('Support'); amail.setToAddresses(emailAdds); amail.Subject = 'Multiple cases created alert message'; amail.setPlainTextBody(messageBody); lstBSingleEmailMessage.add(amail); } Messaging.SendEmailResult[] r = Messaging.sendEmail(lstBSingleEmailMessage); }
In an effort to keep both email SendEmail methods out side of a `For-Loop`, I have mixed up my {}. Any help is appreciated.
-
- Timothy Smith
- November 09, 2019
- Like
- 0
Trigger sending email, ToAddresses depend on conditional
I need to send an email to one of two Public Groups depending on the value of the 3 fields in the `If Statement`. Within the the If and Else blocks I have a `String mailGroup` with the value of the Public Class.Now that I need the Else statement to access that private class with a different Public class name, I am having issues inserting `String mailGroup` , into the Private class `getAddresses()`. The Variable `emailAdds` declared at the top holds the email address values from the `getAddresses()` function. Is it my syntax? I am receiving numerous errors:
`Unexpected token 'private'`
`Unexpected token '<'`
`Unexpected token '>'`
`Method does not exist or incorrect signature: void getAddresses(String) from type CaseHandlerCountAlert`
`Unexpected token 'private'`
`Unexpected token '<'`
`Unexpected token '>'`
`Method does not exist or incorrect signature: void getAddresses(String) from type CaseHandlerCountAlert`
trigger CaseHandlerCountAlert on Case (after insert) { String messageToSend; List<String> ListOfMessages = new List<String>(); Set<Id> AcctIds = new Set<Id>(); List<String> clientEmail; String messageBody; String mailGroup; List<String> emailAdds = getAddresses(mailGroup); List<AggregateResult> AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co FROM Case WHERE CreatedDate = LAST_N_DAYS:1 AND Id IN :Trigger.New GROUP BY AccountId, Account.Name HAVING COUNT(Id) >= 5 ]; Map<Id, String> accountIdEmailmessageMap = new Map<Id, String>(); for(AggregateResult aggr: AggregateResultList){ String messageToSend = 'Account name: ' + aggr.get('name') + ' has ' + (Integer)aggr.get('co') + ' cases opened in the last 8 days.'; Id accId = (Id)aggr.get('AccountId'); accountIdEmailmessageMap.put(accId,messageToSend); AcctIds.add(accId); } List<Case> caseList = [SELECT Id, AccountId, Account.Name,Parent_Project_if_applicable__r.Implementation_status__c, Parent_Project_if_applicable__r.PM_Implementation_Status__c, Parent_Project_if_applicable__r.RCM_Implementation_Status__c, Parent_Project_if_applicable__r.Client_Advisor_Email__c FROM Case WHERE AccountId IN :AcctIds]; for(Case cl:caseList){ if(cl.Parent_Project_if_applicable__r.Implementation_status__c == 'Live - Closed Project'|| cl.Parent_Project_if_applicable__r.PM_Implementation_Status__c == 'Live - Closed Project'|| cl.Parent_Project_If_Applicable__r.RCM_Implementation_Status__c == 'Live - Closed Project'){ mailGroup = 'Customer Success Managers'; String messageBody = accountIdEmailmessageMap.get(cl.AccountId); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setSenderDisplayName('IT Support'); mail.setToAddresses(emailAdds); mail.Subject = 'Multiple cases created alert message'; mail.setPlainTextBody(messageBody); if(messageToSend != null){ Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); } } else{ mailGroup = 'BI Team'; Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.SetSenderDisplayName('IT Support'); mail.setToAddresses(emailAdds); mail.Subject = 'Multiple cases created alert message'; mail.setPlainTextBody(messageToSend); if(messageToSend != null){ Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); } } } private List<String> getAddresses(mailGroup){ List<User> UserList = [SELECT id, name, email FROM User WHERE id IN (SELECT userorgroupid FROM groupmember WHERE group.name = :mailGroup)]; List<String> emailString = new List<String>(); for(User u: UserList){ emailstring.add(u.email); } return (emailString); //System.debug(emailString); } }
-
- Timothy Smith
- November 05, 2019
- Like
- 0
Access Results from SOQL in APEX
Syntax help please. I am trying to access the fields in my SOQL search. I am receiving error message:
`System.SObjectException: Invalid field Parent_Project_if_applicable__r.Implementation_status__c for Case`
I verified Relationship name through WorkBench.
My code is:
List<Case> caseList = [SELECT Id, AccountId, Account.Name,Parent_Project_if_applicable__r.Implementation_status__c, Parent_Project_if_applicable__r.PM_Implementation_Status__c, Parent_Project_if_applicable__r.RCM_Implementation_Status__c, Parent_Project_if_applicable__r.Client_Advisor_Email__c FROM Case WHERE AccountId IN :AcctIds]; for(Case cl:caseList){ System.debug(cl.get('Parent_Project_if_applicable__r.Implementation_status__c')); }
-
- Timothy Smith
- November 01, 2019
- Like
- 0
Second SOQL query help
This is a Trigger that will send an email when the same Account has 8 cases created in the last 5 days. I need to create a second SOQL search for the Project__c object.
What would the second query look like?
System.UnexpectedException: field 'Client_Advisor_Email__c' can not be grouped in a query call
trigger CaseHandlerCountAlert on Case (after insert) { List<AggregateResult> AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co, Project__r.Implementation_status__c, Project__r.Client_Advisor_Email__c FROM Case WHERE CreatedDate = LAST_N_DAYS:5 AND Id IN :Trigger.New GROUP BY AccountId, Account.Name HAVING COUNT(Id) >= 8]; for(AggregateResult aggr:AggregateResultList){ Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage(); if(aggr != Null && Project__r.Implementation_status__c == 'LIVE - TRANSITION'){ //Set Outgoing Email to Implementation Coordinator message.toAddresses = new String[] { Project__r.Client_Advisor_Email__c }; } else if (aggr != Null && Project__r.Implementation_status__c == 'Live - Closed Project'){ //Private method getAddresses() retrieves email address from Customer_Success_Managers Public Group message.toAddresses = new String[] { getAddresses() }; } message.Subject = 'Subject Test Message'; message.PlainTextBody = 'Account name: ' + aggr.get('name') + ' has ' + (Integer)aggr.get('co') + ' cases opened in the last 8 days.'; Messaging.SingleEmailMessage[] messages = new List<Messaging.SingleEmailMessage> {message}; Messaging.SendEmailResult[] results = Messaging.sendEmail(messages); System.debug('Account Name: ' + aggr.get('name')); } private List<String> getAddresses(){ List<User> UserList = [SELECT id, name, email FROM User WHERE id IN (SELECT userorgroupid FROM groupmember WHERE group.name = 'Customer Success Managers')]; List<String> emailString = new List<String>(); for(User u: UserList){ emailstring.add(u.email); } return (emailString); } }
-
- Timothy Smith
- October 30, 2019
- Like
- 0
Comparison arguments must be compatible types -- String
The field, Milestone1_Project__c.Implementation_status__c, is a Picklist in my If/Else statement used for comparison. To my understanding I would treat it as a String. However I am receiving:
Comparison arguments must be compatible types: Schema.SObjectField, String
Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage(); if(Milestone1_Project__c.Implementation_status__c == 'LIVE - TRANSITION'){ // Set Outgoing Email to Implementation Coordinator //message.toAddresses = new String[] { 'test@test.com' }; } else if (Milestone1_Project__c.Implementation_status__c == 'Live'){ // Private method *** getAddresses() *** retrieves email address from Customer_Success_Managers Public Group //message.toAddresses = new String[] { 'test@test.com' }; }
-
- Timothy Smith
- October 29, 2019
- Like
- 0
SOQL with two WHERE clauses help
Help with syntax for 2 WHERE Clauses please.
List<AggregateResult> AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co, Milestone1_Project__c.id, Milestone1_Project__c.Implementation_status__c, Milestone1_Project__c.Client_Advisor_Email__c FROM Case WHERE CreatedDate = LAST_N_DAYS:5 AND Id IN :Trigger.New GROUP BY AccountId, Account.Name HAVING COUNT(Id) >= 8 ];
-
- Timothy Smith
- October 29, 2019
- Like
- 0
Trigger syntax error
Inside the Developer Console, I am receiving the error:
I believe my syntax defining my List<AggregateResult> is correct.
Unexpected Token '<' on Line 2
I believe my syntax defining my List<AggregateResult> is correct.
trigger CaseHandlerCountAlert on SOBJECT (after insert) { List<AggregateResult> AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co, Milestone1_Project__c.id, Milestone1_Project__c.Implementation_status__c, Milestone1_Project__c.Client_Advisor_Email__c FROM Case WHERE CreatedDate = LAST_N_DAYS:5 GROUP BY AccountId, Account.Name HAVING COUNT(Id) >= 8 WHERE Id IN :Trigger.New]; for(AggregateResult aggr:AggregateResultList){ system.debug(aggr); Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage(); if(Milestone1_Project__c.Implementation_status__c == 'LIVE - TRANSITION'){ // Set Outgoing Email to Implementation Coordinator //message.toAddresses = new String[] { test@test.com }; } else if (Milestone1_Project__c.Implementation_status__c == 'Live'){ // Private method *** getAddresses() *** retrieves email address from Customer_Success_Managers Public Group //message.toAddresses = new String[] { "test@test.com" }; } message.setSubject = 'Subject Test Message'; message.setPlainTextBody = 'Account name: ' + aggr.get('name') + ' has ' + (Integer)aggr.get('co') + ' cases opened in the last 8 days.'; Messaging.SingleEmailMessage[] messages = new List<Messaging.SingleEmailMessage> {message}; Messaging.SendEmailResult[] results = Messaging.sendEmail(messages); System.debug('Account Name: ' + aggr.get('name')); } private List<String> getAddresses(){ List<User> UserList = [SELECT id, name, email FROM User WHERE id IN (SELECT userorgroupid FROM groupmember WHERE group.name = 'Customer Success Managers')]; Set<String> emailString = new Set<String>(); for(User u: UserList){ emailstring.add(u.email); } return (emailString); } }
-
- Timothy Smith
- October 29, 2019
- Like
- 0
SOQL how to access children in Trigger
Account - Standard Object
Case - Child of Account
Milestone__Project__c - Child of Case
The After-Insert Trigger will send an email message anytime an account has 8 cases or more created in a 5 day period. The email will be sent to one of two addresses (depending on Project.status). How do I access the Milestone__Project__c.Status field? I cannot get the syntax correct.
Case - Child of Account
Milestone__Project__c - Child of Case
The After-Insert Trigger will send an email message anytime an account has 8 cases or more created in a 5 day period. The email will be sent to one of two addresses (depending on Project.status). How do I access the Milestone__Project__c.Status field? I cannot get the syntax correct.
public class CaseHandlerCountAlert{ public static void CaseCounter(){ List<AggregateResult> AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co, (Id FROM Milestone1_Project__c mi) FROM Case WHERE CreatedDate = LAST_N_DAYS:5 GROUP BY AccountId, Account.Name HAVING COUNT(Id) >= 8 WHERE Id IN :Trigger.new]; for(AggregateResult aggr:AggregateResultList){ Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage(); if((aggr.get(mi.status) == "Transition"){ // If Status = Transition // Set Outgoing Email to Implementation Coordinator "Implementation.Consultalt " message.toAddresses = new String[] { Milestone1_Project__c.Client_Advisor_Email__c }; } else if ((aggr.get(mi.status) == "Live"){ // If Status equals "Live" - Out Of Transition // Private method retrieves email address from Customer Success Managers message.toAddresses = new String[] { getAddresses() }; } // Set Email Template Id //EmailTemplate templateId = [Select id from EmailTemplate where name = 'Template Name']; //mail.setTemplateID(templateId.Id); message.setSubject = 'Subject Test Message'; message.setPlainTextBody = 'Account name: ' + aggr.get('name') + ' has ' + (Integer)aggr.get('co') + ' cases opened in the last 8 days.'; Messaging.SingleEmailMessage[] messages = new List<Messaging.SingleEmailMessage> {message}; Messaging.SendEmailResult[] results = Messaging.sendEmail(messages); System.debug('Account Name: ' + aggr.get('name')); } } private List<String> getAddresses(){ List<User> UserList = [SELECT id, name, email, isactive, profile.name, userrole.name, usertype FROM User WHERE id IN (SELECT userorgroupid FROM groupmember WHERE group.name = 'Customer Success Managers')]; Set<String> emailString = new Set<String>(); for(User u: UserList){ emailstring.add(u.email); // System.debug(u.email); } //System.debug('The list ' + emailstring); return (emailString); } }
-
- Timothy Smith
- October 28, 2019
- Like
- 0
Access CustomObject sibling to Case inside Case Trigger
I am writing an after-insert trigger on the Case object. I am looking to send an email to one of two people depending on a field that is a child of the Account object. A sibling to Case. In my journey I have found that it is not possible to query a sibling (correct me if I'm wrong). So I've decided, once I have the Case, I will take the AccountId and do all of my logic and querys from there.
CustObject_Chld2Acct.fieldname - Child to Account, sibling to Contact
CustObject_Chld2Acct.fieldname - Child to Account, sibling to Contact
List<AggregateResult> AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co, FROM Case WHERE CreatedDate = LAST_N_DAYS:5 GROUP BY AccountId, Account.Name HAVING COUNT(Id) >= 8]; Set<Id> accIdSet = new Set<Id>(); for(Case c: AggregateResultList) { if(c.AccountId != null) { System.debug(c.AccountId); // Now i have the Account ID, what do I do? //Need to access fields in Account Object (Parent) //Need to access fields in CustObject_Chld2Acct }
-
- Timothy Smith
- October 26, 2019
- Like
- 0
SOQL retlationship help - Child to Parent to another Child
I am trying to find the number of Accounts with 8 cases created in the last 5 days. And I need to bring in another field 'Implementation_Status__c' from Milestone1_Project__c.
Account -Parent
Case - Child to Account
Milestone1_Project__c - Child to Account
Account
/ \
Case Milestone1_Proect__c
Account -Parent
Case - Child to Account
Milestone1_Project__c - Child to Account
Account
/ \
Case Milestone1_Proect__c
List<AggregateResult> AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co, Account.Milestone1_Project__c status1 FROM Case WHERE CreatedDate = LAST_N_DAYS:5 GROUP BY AccountId, Account.Name HAVING COUNT(Id) >= 8];
-
- Timothy Smith
- October 25, 2019
- Like
- 0
Any managed apps have integration problems during testing for TLS 1.2?
Just wondering if anyone came across any managed apps or anything worth note regarding integrations during testing for TLS 1.2?
-
- Timothy Smith
- October 24, 2019
- Like
- 0
Advice for Multiple Triggers on single Object (Case)
My company's org has about five triggers more than one existing (after insert, after edit). I am about to create an (after insert) trigger. Suggestions as to how I would consolidate or should I create my trigger and add to the pile. If I should consolidate, how would that look?
-
- Timothy Smith
- October 17, 2019
- Like
- 0
SOQL number of cases created by same account in (n) hours
Is there a way to run a SOQL search for number of cases ran in 40 hours. My org is looking to send a notification via email anytime an Account has created 8 or more cases within a 40 hour period.
I am aware that I can use Last_N_Days, just wondering if there is a way to use hours.
I am aware that I can use Last_N_Days, just wondering if there is a way to use hours.
-
- Timothy Smith
- October 14, 2019
- Like
- 0
Salesforce is disabling TLS 1.1 and I was able to verify that my Users do not login with 1.1 using Workbench. My question is, how do I check that my Integrations and Callouts are using 1.2?
Is there a place in SETUP or is this something individually I need to search out for each?
I have zero endpoints listed in 'Auth. Providers' in Setup, so I don't believe I have any callouts in APEX. Also, the vast majority of my production org APEX classes are from managed packages. I am just looking to not be surprised when TLS 1.1 is gone.
I have zero endpoints listed in 'Auth. Providers' in Setup, so I don't believe I have any callouts in APEX. Also, the vast majority of my production org APEX classes are from managed packages. I am just looking to not be surprised when TLS 1.1 is gone.
-
- Timothy Smith
- October 14, 2019
- Like
- 0
Apex test for Class sending email
At a lost, I don't know where to start on the testing for this Class. I don't know the next steps. Any assistance moving on with the test for this class is appreciated.
I have created a Test Factory:
My test Class So far:
public class caseTriggerHandlerCount{ public static void CaseCounter(){ List<AggregateResult> AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co FROM Case WHERE CreatedDate = LAST_N_DAYS:50 GROUP BY AccountId, Account.Name HAVING COUNT(Id) >=1]; for(AggregateResult aggr:AggregateResultList){ // Send Email to Implementation Coordinator Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage(); message.toAddresses = new String[] { 'test@test.com' }; message.subject = 'Subject Test Message'; message.plainTextBody = 'Account name: ' + aggr.get('name') + ' has ' + (Integer)aggr.get('co') + ' cases opened in the last 8 days.'; Messaging.SingleEmailMessage[] messages = new List<Messaging.SingleEmailMessage> {message}; Messaging.SendEmailResult[] results = Messaging.sendEmail(messages); System.debug('Account Name: ' + aggr.get('name')); } } }
I have created a Test Factory:
@isTest public class TestDataFactoryCases { public static List<Case> createCasesData(Integer numConts) { List<Case> lConts = new List<Case>(); for(Integer i=0;i<numConts;i++) { Case cse = new Case(); cse.status = 'Escalated'; cse.origin = 'Community'; cse.AccountId = '0013000000qLB9MAAW'; cse.Description = 'test ' + i; lConts.add(cse); } insert lConts; return lConts; } }
My test Class So far:
@isTest private class TestCaseCountAlert { @isTest static void TestPositiveResult() { // Test data setup Case[] cases = TestDataFactoryCases.createCasesData(10); // Perform test Test.startTest(); Test.stopTest(); } }
-
- Timothy Smith
- October 11, 2019
- Like
- 0
Unexpected file found in package directory: -Received when delploying with VSCode.
I am receiving the error:
I have also noticed that in the 'Problems' tab, I have the message:
Unexpected file found in package directory:When I try to deploy a class that I have just created. The file is saved in the /force-app/main/default/classes/Case_Trigger_Alert_Count.
I have also noticed that in the 'Problems' tab, I have the message:
The sourcepath ".../force-app/main/default/classes/Case_Trigger_Alert_Count" is not a valid source file path. SourcePathInvalid [1,1] The filename of the file I have just created and attempting to deploy is 'Case_Trigger_Alert_Count"What am I missing to be able to deploy to my Sandbox?
-
- Timothy Smith
- October 10, 2019
- Like
- 1
Trigger, after first SOQL seems to stop executing without error.
When I run my test class the first few lines will execute but then the logs seem to show it stops executing for no reason. I get the first two system.debugs so I know it is partially executing.
This Trigger will send an email message if an Account has 8 or more cases created within 7 days. Depending on the status of the four fields in the If/Else block will dictate the destination of the email. If the status is "Active" 1 email is sent to a set email address. If the status is "Implementation" then 2 emails are sent, addresses are grabbed from SOQL.
Any help is appreciated.
Test Class:
This Trigger will send an email message if an Account has 8 or more cases created within 7 days. Depending on the status of the four fields in the If/Else block will dictate the destination of the email. If the status is "Active" 1 email is sent to a set email address. If the status is "Implementation" then 2 emails are sent, addresses are grabbed from SOQL.
Any help is appreciated.
trigger CaseCountAlertTrigger on Case (before insert) { List<String> emailAdds = new List<String>(); // Holds '2' ToAddresses from Milestone1_project__c object Set <Id> AcctIds = new Set <Id>(); //Holds Account Ids from this Case Trigger String messageToSend; //Email body sent in email (will be in HTML format) Map < Id, String > accountIdEmailmessageMap = new Map < Id, String > (); // map of AccountId and Email body per Account/AccountId to be sent List < AggregateResult > AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co FROM Case WHERE CreatedDate = LAST_N_DAYS:7 AND Id in :Trigger.New GROUP BY Account.Name, AccountId HAVING COUNT(Id) >= 8 ]; System.debug('AggregateResult: ' + AggregateResultList); // debugs: 'AggregateResult: ()' --emtpy aggregate list System.debug('Trigger Results' + Trigger.new); // This line will print the Case that comes in as Trigger.New, debugs as expected. // ******** It seems to exit here*************** for (AggregateResult aggr: AggregateResultList){ messageToSend = 'You are receiving this email alert due to an account '; messageToSend += 'activity rule has exceeded 8 cases created within 5 business days.<br><br>'; messageToSend += 'Please, follow up with the account and provide guidance and assistance.<br><br>'; messageToSend += '<b>Account Name: </b>' + aggr.get('name') + '<br> <br>'; messageToSend += 'Thank you, <br>'; messageToSend += 'Salesforce Team'; //Crete Map of <AccountId, Message to serve as body in Email // for each accountId> Id accId = (Id) aggr.get('AccountId'); accountIdEmailmessageMap.put(accId, messageToSend); //Create List of AccountId's to grab email addresses // from child Object for 'Implementation Status AcctIds.add(accId); } System.debug(accountIdEmailmessageMap); /* List < Case > caseList = [SELECT Id, AccountId, Account.Name, Account.Eyefinity_EHR_Status__c, Account.Eyefinity_PM_Status__c, Account.OfficeMate_Status__c, Account.Project_Imp_Status__c FROM Case WHERE AccountId IN: AcctIds]; */ // SOQL to grab the four status fields on Account to check status either 'Active' or 'Implementation' // also grab two email addresses for use in ifElse block List<Account> accList = [SELECT Id, Name, Eyefinity_EHR_Status__c, Eyefinity_PM_Status__c, Project_Imp_Status__c, OfficeMate_Status__c,(select Client_Advisor_Email__c, Resource_Coordinator_Email__c from Projects__r) FROM Account WHERE Id IN :AcctIds]; List<Messaging.SingleEmailMessage> lstASingleEmailMessage = new List<Messaging.SingleEmailMessage>(); List<Messaging.SingleEmailMessage> lstBSingleEmailMessage = new List<Messaging.SingleEmailMessage>(); for (Account al: accList) { if (al.Eyefinity_EHR_Status__c == 'Active' || al.Eyefinity_PM_Status__c == 'Active' || al.Project_Imp_Status__c == 'Active' || al.OfficeMate_Status__c == 'Active') { // String messageBody = accountIdEmailmessageMap.get(al.accId); //Send Email to CustomerService if Active List<String> emailaddr = new List<String>(); emailaddr.add('CustomerSuccessManagers@test.com'); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setSenderDisplayName(' Support'); mail.setToAddresses(emailaddr); mail.Subject = 'Notification: Account Case activity rule exceeded'; mail.setHtmlBody(messageToSend); lstASingleEmailMessage.add(mail); } else if (al.Eyefinity_EHR_Status__c == 'Implementation' || al.Eyefinity_PM_Status__c == 'Implementation' || al.Project_Imp_Status__c == 'Implementation' || al.OfficeMate_Status__c == 'Implementation'){ String messageBody1 = accountIdEmailmessageMap.get(cl.AccountId); System.debug('Accounts: ' + al); //Send email to Coordinator and Advisor if in Implementation for(Account a : accList) { for(Milestone1_Project__c p : a.Projects__r) { emailAdds.add(p.Client_Advisor_Email__c); emailAdds.add(p.Resource_Coordinator_Email__c); } } System.debug(emailAdds); Messaging.SingleEmailMessage amail = new Messaging.SingleEmailMessage(); amail.SetSenderDisplayName('Support'); amail.setToAddresses(emailAdds); amail.Subject = 'Notification: Account Case activity rule exceeded'; amail.setHtmlBody(messageBody1); lstASingleEmailMessage.add(amail); } else{ System.debug(AggregateResultList); } } Messaging.SendEmailResult[] r = Messaging.sendEmail(lstASingleEmailMessage); }
Test Class:
@isTest private class TestCaseHandlerAlert { @testSetup static void setup(){ List<Account> testAccounts = new List<Account>(); Account a = new Account(); a.name = 'AccountEHRImplement'; a.RecordTypeId = '01230000000v58OAAQ'; a.Eyefinity_EHR_Status__c = 'Implementation'; a.Tax_Id__c = '123456789'; testAccounts.add(a); //Insert Account insert testAccounts; //Create User: THis user will fill required fields on the Milestone1_Project1 allowing for a an email address to populate User tuser = new User( firstname = 'tuserFname', lastName = 'tuserLastname', email = 'test@tester.com', Username = 'tuserleielkwl@test18278391.org', EmailEncodingKey = 'ISO-8859-1', Alias ='Blah', TimeZoneSidKey = 'America/Los_Angeles', LocaleSidKey = 'en_US', LanguageLocaleKey = 'en_US', ProfileId =[Select Id From Profile Where Name='Eyefinity Managers'].id ); insert tuser; //Create Project Milestone1_Project__c project1 = new Milestone1_Project__c(); project1.Customer_Account__c = [Select Id FROM Account Where Name ='AccountEHRImplement'].id; project1.Name = 'triggerProject'; project1.Client_Advisor__c = [Select Id FROM User Where Username ='tuserleielkwl@test18278391.org'].id; project1.Resource_Coordinator__c = [Select Id FROM User Where Username ='tuserleielkwl@test18278391.org'].id; project1.RecordTypeId = '01214000001RYp7AAG'; insert project1; } @isTest static void AccountEHRImplement (){ //Create and insert more than more than 8 cases List<Case> casestoInsert = new List<Case>(); for (Integer i=1; i<10; i++){ Case cas1 = new Case(); cas1.RecordTypeId = '01214000001NcOYAA0'; cas1.AccountId = [Select Id FROM Account Where name ='AccountEHRImplement'].id; cas1.Origin = 'Phone'; cas1.Impact__c = 'Low'; cas1.Severity__c = 'Minor'; cas1.Type = 'Bridge'; casesToInsert.add(cas1); } Test.startTest(); insert casesToInsert; Test.stopTest(); System.debug('Expected: 2, actual: ' + Limits.getEmailInvocations()); } }
- Timothy Smith
- November 24, 2019
- Like
- 0
Trigger sends more than one email.
This email will send an email alert when an account has 8 cases open within 7 days. The email is being sent, but multiple emails for the Same account are being sent. What is wrong with my code that it is creating multiple emails for the same account?
Trigger:
Trigger:
trigger CaseHandlerCountAlert on Case (after insert, after update) { //Case trigger that will send email alert when 8 cases are created within 7 days. String messageToSend; List <String> ListOfMessages = new List <String>(); Set <Id> AcctIds = new Set <Id>(); String messageBody; List < AggregateResult > AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co FROM Case WHERE CreatedDate = LAST_N_DAYS:7 AND Id IN :Trigger.New GROUP BY AccountId, Account.Name HAVING COUNT(Id) >= 8 ]; Map < Id, String > accountIdEmailmessageMap = new Map < Id, String > (); for (AggregateResult aggr: AggregateResultList) { String messageToSend = 'Account name: ' + aggr.get('name') + ' has ' + (Integer) aggr.get('co') + ' cases opened in the last 8 days.'; Id accId = (Id) aggr.get('AccountId'); accountIdEmailmessageMap.put(accId, messageToSend); AcctIds.add(accId); } List < Case > caseList = [SELECT Id, AccountId, Account.Name, Parent_Project_if_applicable__r.Implementation_status__c, Parent_Project_if_applicable__r.PM_Implementation_Status__c, Parent_Project_if_applicable__r.RCM_Implementation_Status__c, Parent_Project_if_applicable__r.Resource_Coordinator_Email__c, Parent_Project_if_applicable__r.Client_Advisor_Email__c FROM Case WHERE AccountId IN: AcctIds]; List<Messaging.SingleEmailMessage> lstASingleEmailMessage = new List<Messaging.SingleEmailMessage>(); List<Messaging.SingleEmailMessage> lstBSingleEmailMessage = new List<Messaging.SingleEmailMessage>(); for (Case cl: caseList) { if (cl.Parent_Project_if_applicable__r.Implementation_status__c == 'Live - Closed Project' || cl.Parent_Project_if_applicable__r.PM_Implementation_Status__c == 'Live - Closed Project' || cl.Parent_Project_If_Applicable__r.RCM_Implementation_Status__c == 'Live - Closed Project') { String messageBody = accountIdEmailmessageMap.get(cl.AccountId); List<String> emailaddr = new List<String>(); emailaddr.add('CustomerSuccessManagers@test.com'); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setSenderDisplayName('Support'); mail.setToAddresses(emailaddr); mail.Subject = 'Multiple cases created alert message'; mail.setPlainTextBody(messageBody); lstASingleEmailMessage.add(mail); }else{ String messageBody1 = accountIdEmailmessageMap.get(cl.AccountId); List<String> emailAdds = new List<String>(); emailAdds.add(cl.Parent_Project_if_applicable__r.Resource_Coordinator_Email__c); emailAdds.add(cl.Parent_Project_if_applicable__r.Client_Advisor_Email__c); Messaging.SingleEmailMessage amail = new Messaging.SingleEmailMessage(); amail.SetSenderDisplayName('Support'); amail.setToAddresses(emailAdds); amail.Subject = 'Multiple cases created alert message'; amail.setPlainTextBody(messageBody1); lstBSingleEmailMessage.add(amail); } } Messaging.SendEmailResult[] r = Messaging.sendEmail(lstASingleEmailMessage); Messaging.SendEmailResult[] rb = Messaging.sendEmail(lstBSingleEmailMessage); }
- Timothy Smith
- November 16, 2019
- Like
- 0
Trigger sending email, ToAddresses depend on conditional
I need to send an email to one of two Public Groups depending on the value of the 3 fields in the `If Statement`. Within the the If and Else blocks I have a `String mailGroup` with the value of the Public Class.Now that I need the Else statement to access that private class with a different Public class name, I am having issues inserting `String mailGroup` , into the Private class `getAddresses()`. The Variable `emailAdds` declared at the top holds the email address values from the `getAddresses()` function. Is it my syntax? I am receiving numerous errors:
`Unexpected token 'private'`
`Unexpected token '<'`
`Unexpected token '>'`
`Method does not exist or incorrect signature: void getAddresses(String) from type CaseHandlerCountAlert`
`Unexpected token 'private'`
`Unexpected token '<'`
`Unexpected token '>'`
`Method does not exist or incorrect signature: void getAddresses(String) from type CaseHandlerCountAlert`
trigger CaseHandlerCountAlert on Case (after insert) { String messageToSend; List<String> ListOfMessages = new List<String>(); Set<Id> AcctIds = new Set<Id>(); List<String> clientEmail; String messageBody; String mailGroup; List<String> emailAdds = getAddresses(mailGroup); List<AggregateResult> AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co FROM Case WHERE CreatedDate = LAST_N_DAYS:1 AND Id IN :Trigger.New GROUP BY AccountId, Account.Name HAVING COUNT(Id) >= 5 ]; Map<Id, String> accountIdEmailmessageMap = new Map<Id, String>(); for(AggregateResult aggr: AggregateResultList){ String messageToSend = 'Account name: ' + aggr.get('name') + ' has ' + (Integer)aggr.get('co') + ' cases opened in the last 8 days.'; Id accId = (Id)aggr.get('AccountId'); accountIdEmailmessageMap.put(accId,messageToSend); AcctIds.add(accId); } List<Case> caseList = [SELECT Id, AccountId, Account.Name,Parent_Project_if_applicable__r.Implementation_status__c, Parent_Project_if_applicable__r.PM_Implementation_Status__c, Parent_Project_if_applicable__r.RCM_Implementation_Status__c, Parent_Project_if_applicable__r.Client_Advisor_Email__c FROM Case WHERE AccountId IN :AcctIds]; for(Case cl:caseList){ if(cl.Parent_Project_if_applicable__r.Implementation_status__c == 'Live - Closed Project'|| cl.Parent_Project_if_applicable__r.PM_Implementation_Status__c == 'Live - Closed Project'|| cl.Parent_Project_If_Applicable__r.RCM_Implementation_Status__c == 'Live - Closed Project'){ mailGroup = 'Customer Success Managers'; String messageBody = accountIdEmailmessageMap.get(cl.AccountId); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setSenderDisplayName('IT Support'); mail.setToAddresses(emailAdds); mail.Subject = 'Multiple cases created alert message'; mail.setPlainTextBody(messageBody); if(messageToSend != null){ Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); } } else{ mailGroup = 'BI Team'; Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.SetSenderDisplayName('IT Support'); mail.setToAddresses(emailAdds); mail.Subject = 'Multiple cases created alert message'; mail.setPlainTextBody(messageToSend); if(messageToSend != null){ Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); } } } private List<String> getAddresses(mailGroup){ List<User> UserList = [SELECT id, name, email FROM User WHERE id IN (SELECT userorgroupid FROM groupmember WHERE group.name = :mailGroup)]; List<String> emailString = new List<String>(); for(User u: UserList){ emailstring.add(u.email); } return (emailString); //System.debug(emailString); } }
- Timothy Smith
- November 05, 2019
- Like
- 0
Access Results from SOQL in APEX
Syntax help please. I am trying to access the fields in my SOQL search. I am receiving error message:
`System.SObjectException: Invalid field Parent_Project_if_applicable__r.Implementation_status__c for Case`
I verified Relationship name through WorkBench.
My code is:
List<Case> caseList = [SELECT Id, AccountId, Account.Name,Parent_Project_if_applicable__r.Implementation_status__c, Parent_Project_if_applicable__r.PM_Implementation_Status__c, Parent_Project_if_applicable__r.RCM_Implementation_Status__c, Parent_Project_if_applicable__r.Client_Advisor_Email__c FROM Case WHERE AccountId IN :AcctIds]; for(Case cl:caseList){ System.debug(cl.get('Parent_Project_if_applicable__r.Implementation_status__c')); }
- Timothy Smith
- November 01, 2019
- Like
- 0
Comparison arguments must be compatible types -- String
The field, Milestone1_Project__c.Implementation_status__c, is a Picklist in my If/Else statement used for comparison. To my understanding I would treat it as a String. However I am receiving:
Comparison arguments must be compatible types: Schema.SObjectField, String
Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage(); if(Milestone1_Project__c.Implementation_status__c == 'LIVE - TRANSITION'){ // Set Outgoing Email to Implementation Coordinator //message.toAddresses = new String[] { 'test@test.com' }; } else if (Milestone1_Project__c.Implementation_status__c == 'Live'){ // Private method *** getAddresses() *** retrieves email address from Customer_Success_Managers Public Group //message.toAddresses = new String[] { 'test@test.com' }; }
- Timothy Smith
- October 29, 2019
- Like
- 0
SOQL with two WHERE clauses help
Help with syntax for 2 WHERE Clauses please.
List<AggregateResult> AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co, Milestone1_Project__c.id, Milestone1_Project__c.Implementation_status__c, Milestone1_Project__c.Client_Advisor_Email__c FROM Case WHERE CreatedDate = LAST_N_DAYS:5 AND Id IN :Trigger.New GROUP BY AccountId, Account.Name HAVING COUNT(Id) >= 8 ];
- Timothy Smith
- October 29, 2019
- Like
- 0
SOQL how to access children in Trigger
Account - Standard Object
Case - Child of Account
Milestone__Project__c - Child of Case
The After-Insert Trigger will send an email message anytime an account has 8 cases or more created in a 5 day period. The email will be sent to one of two addresses (depending on Project.status). How do I access the Milestone__Project__c.Status field? I cannot get the syntax correct.
Case - Child of Account
Milestone__Project__c - Child of Case
The After-Insert Trigger will send an email message anytime an account has 8 cases or more created in a 5 day period. The email will be sent to one of two addresses (depending on Project.status). How do I access the Milestone__Project__c.Status field? I cannot get the syntax correct.
public class CaseHandlerCountAlert{ public static void CaseCounter(){ List<AggregateResult> AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co, (Id FROM Milestone1_Project__c mi) FROM Case WHERE CreatedDate = LAST_N_DAYS:5 GROUP BY AccountId, Account.Name HAVING COUNT(Id) >= 8 WHERE Id IN :Trigger.new]; for(AggregateResult aggr:AggregateResultList){ Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage(); if((aggr.get(mi.status) == "Transition"){ // If Status = Transition // Set Outgoing Email to Implementation Coordinator "Implementation.Consultalt " message.toAddresses = new String[] { Milestone1_Project__c.Client_Advisor_Email__c }; } else if ((aggr.get(mi.status) == "Live"){ // If Status equals "Live" - Out Of Transition // Private method retrieves email address from Customer Success Managers message.toAddresses = new String[] { getAddresses() }; } // Set Email Template Id //EmailTemplate templateId = [Select id from EmailTemplate where name = 'Template Name']; //mail.setTemplateID(templateId.Id); message.setSubject = 'Subject Test Message'; message.setPlainTextBody = 'Account name: ' + aggr.get('name') + ' has ' + (Integer)aggr.get('co') + ' cases opened in the last 8 days.'; Messaging.SingleEmailMessage[] messages = new List<Messaging.SingleEmailMessage> {message}; Messaging.SendEmailResult[] results = Messaging.sendEmail(messages); System.debug('Account Name: ' + aggr.get('name')); } } private List<String> getAddresses(){ List<User> UserList = [SELECT id, name, email, isactive, profile.name, userrole.name, usertype FROM User WHERE id IN (SELECT userorgroupid FROM groupmember WHERE group.name = 'Customer Success Managers')]; Set<String> emailString = new Set<String>(); for(User u: UserList){ emailstring.add(u.email); // System.debug(u.email); } //System.debug('The list ' + emailstring); return (emailString); } }
- Timothy Smith
- October 28, 2019
- Like
- 0
TLS 1.1 update, Workbench SOQL search show "No Records found". Am I ok?
To find my TLS 1.1 logins I ran the SOQL search and followed instuctions from:
https://help.salesforce.com/articleView?id=000322198&type=1&mode=1&language=en_US
I received no records found:
Does this mean, I don't have any issues with the update? Anything else I should check?
https://help.salesforce.com/articleView?id=000322198&type=1&mode=1&language=en_US
I received no records found:
- Timothy Smith
- October 11, 2019
- Like
- 0
How to Access Account.Name field within SOQL using Aggregate
I would like to send an email anytime an account has created 8 cases in the last 8 days. The email is sending, but within the email, the AccountId (id) is showing. How would I get the much more readable Account.Name field to show.
Line: 1, Column: 44 Field must be grouped or aggregated: Name
List<AggregateResult> AggregateResultList =[SELECT AccountId, Account.name, COUNT(Id) co FROM Case WHERE CreatedDate = LAST_N_DAYS:8 GROUP BY AccountId HAVING COUNT(Id) > 1]; for(AggregateResult aggr:AggregateResultList){ //Send Email to Implementation Coordinator Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage(); message.toAddresses = new String[] { 'test@test.com' }; message.subject = 'Subject Test Message'; message.plainTextBody = 'Account name: ' + (id)aggr.get('AccountId') + ' has ' + (Integer)aggr.get('co') + ' cases opened in the last 8 days.'; Messaging.SingleEmailMessage[] messages = new List<Messaging.SingleEmailMessage> {message}; Messaging.SendEmailResult[] results = Messaging.sendEmail(messages); if (results[0].success) { System.debug('The email was sent successfully.'); } else { System.debug('The email failed to send: ' + results[0].errors[0].message); } }
- Timothy Smith
- October 10, 2019
- Like
- 0
Users cannot access Salesforce after My Domain Deployment
Hello,
We deployed My Domain this morning and some of our users are having issues logging in. When they try to login from both login.salesforce.com and our custom domain they are redirected back to the login screen after they enter their credentials and press submit. On our admin side, it shows their log ins as successful, but they cannot actually get into the instance.
We have tried clearing caches, disabling extensions, etc. but nothing has allowed them to log in.
Has any one ever encountered this problem? Do you know a solution?
We deployed My Domain this morning and some of our users are having issues logging in. When they try to login from both login.salesforce.com and our custom domain they are redirected back to the login screen after they enter their credentials and press submit. On our admin side, it shows their log ins as successful, but they cannot actually get into the instance.
We have tried clearing caches, disabling extensions, etc. but nothing has allowed them to log in.
Has any one ever encountered this problem? Do you know a solution?
- Alexis Scott 16
- August 10, 2018
- Like
- 0
Argument must be an object that implements Database.Batchable
Hello all,
I am trying to write a batch class (MY FIRST EVER), to take in the AsyncApexJob object and create a csv file of the errors and send to an email address. I'm sure that some of my syntax is not correct (I would appreciate any input), but I can't even execute to see if it works. I am receiving the above message when I open a second anonymous window and enter:
AriaBatchErrors objClass=new AriaBatchErrors();
Database.executeBatch(objClass);
So that I can execute:
global class AriaBatchErrors implements Database.Batchable<Sobject>
{
global string[] email=new String[] {'myEmail@address.com'};
string[] Lines;
//start method
global Database.QueryLocator start(Database.BatchableContext BC)
{
lines = new String[0];
return Database.getQueryLocator('SELECT Id, Status, NumberOfErrors, JobItemsProcessed,TotalJobItems, CreatedBy.Email FROM AsyncApexJob WHERE NumberOfErrors > 0');
}
//execute
global void execute(Database.BatchableContext BC, List<String> scope)
{
// process
for(String record: scope)
{
String line = '';
// header row
if ( lines.size() == 0 ) {
line = 'ID, Status, Number of Errors, Job Items Processed, Total Job Items, Created By';
lines.add(line);
}
else {
// build csv lines here
line +='"' + record.get('Id') +'"'
+',' + '"' + record.get('Status') + '"'
+',' + '"' + record.get('NumberOfErrors') +'"'
+',' + '"' + record.get('JobItemsProcessed') + '"'
+',' + '"' + record.get('TotalJobItems') + '"'
+',' + '"' + record.get('CreatedBy.Email') + '"' ;
lines.add(line);
system.debug('Line No >>> ' + line);
}
} // end of for loop
}
//finish
global void finish (Database.BatchableContext BC)
{
Messaging.SingleEmailMessage mail=new Messaging.SingleEmailMessage();
AsyncApexJob a =[select a.TotalJobItems,a.Status,a.NumberOfErrors,a.JobItemsProcessed,a.ExtendedStatus,a.createdById,a.completedDate from AsynchApexJob];
System.debug('Job Id')+BC.getJobId());
mail.ToAddreses(email);
mail.setSenderDisplayName('Apex Batch Processing Errors');
mail.setSubject('Batch Errors');
mail.setPlainTextBody('This will be the body of the email' + a.TotalJobItems + 'batches with '+ a.NumberOfErrors);
}
}
Please help, I am so so new.
Timothy
I am trying to write a batch class (MY FIRST EVER), to take in the AsyncApexJob object and create a csv file of the errors and send to an email address. I'm sure that some of my syntax is not correct (I would appreciate any input), but I can't even execute to see if it works. I am receiving the above message when I open a second anonymous window and enter:
AriaBatchErrors objClass=new AriaBatchErrors();
Database.executeBatch(objClass);
So that I can execute:
global class AriaBatchErrors implements Database.Batchable<Sobject>
{
global string[] email=new String[] {'myEmail@address.com'};
string[] Lines;
//start method
global Database.QueryLocator start(Database.BatchableContext BC)
{
lines = new String[0];
return Database.getQueryLocator('SELECT Id, Status, NumberOfErrors, JobItemsProcessed,TotalJobItems, CreatedBy.Email FROM AsyncApexJob WHERE NumberOfErrors > 0');
}
//execute
global void execute(Database.BatchableContext BC, List<String> scope)
{
// process
for(String record: scope)
{
String line = '';
// header row
if ( lines.size() == 0 ) {
line = 'ID, Status, Number of Errors, Job Items Processed, Total Job Items, Created By';
lines.add(line);
}
else {
// build csv lines here
line +='"' + record.get('Id') +'"'
+',' + '"' + record.get('Status') + '"'
+',' + '"' + record.get('NumberOfErrors') +'"'
+',' + '"' + record.get('JobItemsProcessed') + '"'
+',' + '"' + record.get('TotalJobItems') + '"'
+',' + '"' + record.get('CreatedBy.Email') + '"' ;
lines.add(line);
system.debug('Line No >>> ' + line);
}
} // end of for loop
}
//finish
global void finish (Database.BatchableContext BC)
{
Messaging.SingleEmailMessage mail=new Messaging.SingleEmailMessage();
AsyncApexJob a =[select a.TotalJobItems,a.Status,a.NumberOfErrors,a.JobItemsProcessed,a.ExtendedStatus,a.createdById,a.completedDate from AsynchApexJob];
System.debug('Job Id')+BC.getJobId());
mail.ToAddreses(email);
mail.setSenderDisplayName('Apex Batch Processing Errors');
mail.setSubject('Batch Errors');
mail.setPlainTextBody('This will be the body of the email' + a.TotalJobItems + 'batches with '+ a.NumberOfErrors);
}
}
Please help, I am so so new.
Timothy
- Timothy Smith
- August 29, 2017
- Like
- 0