-
ChatterFeed
-
0Best Answers
-
1Likes Received
-
0Likes Given
-
50Questions
-
18Replies
Error: List has no rows for assignment to SObject
I am wondering why my SOQL search in the test class does not show any rows. WHen I do a system.debug I can see that records are created, but my SOQL is not getting results.
trigger SelectVacationPackage on Vacation_Package__c (before insert, before update) { List<Vacation_Package__c> PackagesToUpdate = new List<Vacation_Package__c>(); List<Vacation_Package__c> WorkingPackages = [SELECT Id, Package_Type__c, Sales_Company__c, Package_Status__c FROM Vacation_Package__c WHERE Id In :Trigger.New]; for(Vacation_Package__c vp: WorkingPackages){ if(vp.Package_Type__c == 'Select' && vp.Package_Status__c != 'Canceled'){ PackagesToUpdate.add(vp); } } for (Vacation_Package__c vsp : PackagesToUpdate){ vsp.Sales_Company__c = [Select ID from Account WHERE Name = 'Upgrade Sales'].id; vsp.Balance_Type__c = 'Nights'; } upsert PackagesToUpdate; }
@isTest private class SelectVacationPackageTest { private static testMethod void SelectVacations(){ Account newAcc = FlowTestUtils.createHouseholdAccount(); newAcc.Name = 'Upgrade Sales'; insert newAcc; Product2 newProd = new Product2(); newProd.Name = 'Testing'; newProd.Family = 'Sub-Type'; newProd.Select_Package_Sub_Type__c = True; insert newProd; List<Vacation_Package__c> packList = new List<Vacation_Package__c>(); Vacation_Package__c vacPac = new Vacation_Package__c(); vacPac.Service_Charge_Frequency__c = 'Annual'; vacPac.Service_Charge_Start_Date__c = Date.today().addMonths(1).toStartofMonth(); vacPac.Package_Type__c = 'Select'; vacPac.Package_Status__c = 'Draft'; vacPac.Household__c = newAcc.id; vacPac.Sale_Date__c = Date.today().addMonths(1).toStartofMonth(); vacPac.Package_Sub_Type__c = newProd.Id; packList.add(vacPac); Vacation_Package__c vacPac1 = new Vacation_Package__c(); vacPac1.Service_Charge_Frequency__c = 'Annual'; vacPac1.Service_Charge_Start_Date__c = Date.today().addMonths(1).toStartofMonth(); vacPac1.Package_Type__c = 'Full'; vacPac1.Package_Status__c = 'Draft'; vacPac1.Household__c = newAcc.id; vacPac1.Sale_Date__c = Date.today().addMonths(1).toStartofMonth(); vacPac1.Package_Sub_Type__c = newProd.Id; packList.add(vacPac1); System.debug('vacPac' + vacPac); System.debug('vacPac1' + vacPac1); //both debugs show new records as expected Test.startTest(); upsert packList; Test.stopTest(); Account testAcc = [SELECT Name FROM Account WHERE Id=:vacPac.Id Limit 1]; System.debug('Testing Acc' + test); //No results for testAcc /* //I am receiving the error here: System.assertEquals('Upgrade Sales', [SELECT Name FROM Account WHERE Id=:vacPac.Id Limit 1].Name); System.assertNotEquals('Upgrade Sales', [SELECT Name FROM Account WHERE Id=:vacPac1.Id Limit 1].Name); */ } }
- Timothy Smith
- August 03, 2021
- Like
- 0
Apex Testing (No Rows) Error
When a Vacation_Package__c is created and the Package_Type__c is equal to 'Select', then set Sales_Company__c field to 'Upgrade Sales'. I have a trigger and test class here is my error.
- Timothy Smith
- July 29, 2021
- Like
- 0
Trigger Code error - Expression cannot be assigned and Illegl assignment
Line 8: Expression cannot be assigned
Line 17: Illegal assignment from List to Id
trigger SelectVacationPackage on Vacation_Package__c (after insert, after update) { List<Vacation_Package__c> PackagesToUpdate = new List<Vacation_Package__c>(); List<Vacation_Package__c> WorkingPackages = [SELECT Id, Package_Type__c, Sales_Company__c, Package_Status__c FROM Vacation_Package__c WHERE Id In :Trigger.New]; for(Vacation_Package__c vp: WorkingPackages){ if(vp.Package_Type__c = 'Select' && vp.Package_Status__c = 'Active'){ PackagesToUpdate.add(vp); } } for (Vacation_Package__c vsp : PackagesToUpdate){ //Sales_Company__c is a Lookup field requiring an ID vsp.Sales_Company__c = [Select ID from Account WHERE Name = 'Upgrade Sales']; } if(PackagesToUpdate.size() > 0){ update PackagesToUpdate; } }
Thank you
- Timothy Smith
- July 29, 2021
- Like
- 0
Hyperlink field leading to Opportunity Record (Flow and Process Builder)
Opportunity -> Appointment__c -> Task
I am creating a link from Task to Opportunity, the 'Text' of the Link will be the Opportunity Name.
Opportunity_Link__ on Task Object is a Lookup field to Opportunity.
Also, when creating the hyperlink am I accessing the Object, or ObjectId. Process BUilder is on Appointment__c
FLow is on Task
Thank you
#Process Builder #Formula Field #Flow #Automation
- Timothy Smith
- July 15, 2021
- Like
- 0
Formula/Hyperlink field help
On the Task Object I need to create a custom field 'Opportunity__c' that would as a value show the Opportunity's Name, and serve as a hyperlink back to the Opportunity.
I am having trouble setting up the Formula.
HYPERLINK(url, friendly_name [, target])
'friendly_name' - How do I set this variable to display the Opportunity.name?
'url' - this should lead back to the opportunity, its not working for me.
Thank you
- Timothy Smith
- July 01, 2021
- Like
- 0
Field Value to Hyperlink
On the Task object, I have an Opportunity_Name field showing the name of the Opportunity. I need to make this Lookup field, a hyperlink leading back to the Opportunity.
Considering that not every Task is attached to an Appointment, I only want this field to show if it is connected to an Appointment (ie Task for Opportunity or other object, does not show this field)
Is this possible?
- Timothy Smith
- July 01, 2021
- Like
- 0
Edit Source Code of Record Page?
Opportunity -> Appointment__c -> Task
On the Task Object the request is to have the 'Related To' field which shows the Opportunity Name, to become a hyperlink to the Opportunity if the 'Related To' is an Opportunity Record. Can this be done by editing the Task Layout in VSCode/Source Code, or am I forced to create a custom Lighting Component for one field change? Thank you
I have a request to change the value of the 'Related To' field into a hyperlink back to the specified record (Opportunity).
- Timothy Smith
- July 01, 2021
- Like
- 0
Assert Equals not working as expected.
Contact has 3 phone numbers with 'Do Not Call' status field corresponding
phone_c and phone__status__c
work_phone__c and work_phone_status
mobile_phone__c and mobile_phone_status
Anytime a Contact is Insert/Updated the Trigger will check any opportunity where this contact is associated. Trigger will check both Primary_Contact and Secondary_Contact__c of Opportunity for a valid phone number. If field is blank or status is "Do Not Call" this is considered a bad number. For any Opportunity where a good number does not exist, close the opportunity.
I have the Trigger and Test running ok. The test Opportunity should be closed. System.debug at the end shows Opportunity was closed but AssertEquals does not agree.
Trigger:
trigger Contact_DNC_Opportunity on Contact (after insert, after update){ List<Opportunity> OpportunitiesToClose = new List<Opportunity>(); List<Opportunity> WorkingOpportunities = [SELECT StageName, Primary_Contact__c, Secondary_Contact__c, Primary_Contact__r.Phone_Status__c, Primary_Contact__r.Mobile_Phone_Status__c, Primary_Contact__r.Work_Phone_Status__c, Primary_Contact__r.Phone, Primary_Contact__r.Normalized_Mobile_Phone__c, Primary_Contact__r.Normalized_Work_Phone__c, Secondary_Contact__r.Phone_Status__c, Secondary_Contact__r.Mobile_Phone_Status__c, Secondary_Contact__r.Work_Phone_Status__c, Secondary_Contact__r.Phone, Secondary_Contact__r.Normalized_Mobile_Phone__c, Secondary_Contact__r.Normalized_Work_Phone__c FROM Opportunity WHERE Primary_Contact__c In :Trigger.New OR Secondary_Contact__c In :Trigger.New ]; System.debug('Before Insertion' + WorkingOpportunities); for(Opportunity opp: WorkingOpportunities){ //Check Primary Contact phone numbers if ((opp.Primary_Contact__r.Phone == Null) || (opp.Primary_Contact__r.Phone_Status__c == 'Do Not Call')&& (opp.Primary_Contact__r.Normalized_Mobile_Phone__c == Null) || (opp.Primary_Contact__r.Mobile_Phone_Status__c == 'Do Not Call')&& (opp.Primary_Contact__r.Normalized_Work_Phone__c == Null) || (opp.Primary_Contact__r.Work_Phone_Status__c == 'Do Not Call')&& (opp.Secondary_Contact__r.Phone == Null) || (opp.Secondary_Contact__r.Phone_Status__c == 'Do Not Call')&& (opp.Secondary_Contact__r.Normalized_Mobile_Phone__c == Null) || (opp.Secondary_Contact__r.Mobile_Phone_Status__c == 'Do Not Call')&& (opp.Secondary_Contact__r.Normalized_Work_Phone__c == Null) || (opp.Secondary_Contact__r.Work_Phone_Status__c == 'Do Not Call') ) { //Add opp to List if fits criteria opportunitiesToClose.add(opp); } } for (Opportunity opp1 : opportunitiesToClose){ opp1.StageName = 'Closed Lost'; } if(opportunitiesToClose.size() > 0){ update opportunitiesToClose; System.debug('After Insert' + opportunitiesToClose); //This shows the "Closed Lost" change that is expected but the Assert.Equals statement in Test Class see 'Ready to Call/Schedule' } }
Test Class
@isTest private class ContactDNCOpportunityTest { private static testMethod void testCloseOpps(){ //Create Account Account newAcc = FlowTestUtils.createHouseholdAccount(); insert newAcc; //Create Contacts List<Contact> conList = new List<Contact> { new Contact(FirstName='test1',LastName='tester',AccountId = newAcc.Id, Email = 'test1@testing.com', Phone = '1234567891', Phone_Status__c = 'Do Not Call'), //Has Phone Number - Do not call, Closed Opp new Contact(FirstName='test2',LastName='tester',AccountId = newAcc.Id, Email = 'test2@testing.com'), //Blank No Numbers Closed Opp new Contact(FirstName='test3',LastName='tester',AccountId = newAcc.Id, Email = 'test3@testing.com', Normalized_Work_Phone__c = '1234567891',Work_Phone_Status__c = 'Active'), // Has Work Number, Active, Close Opp new Contact(FirstName='test4',LastName='tester',AccountId = newAcc.Id, Email = 'test4@testing.com', Phone = '1234567891', Phone_Status__c = 'Active'), //Has Phone Number, Active, Do not Close Opp new Contact(FirstName='test5',LastName='tester',AccountId = newAcc.Id, Email = 'test5@testing.com', Normalized_Mobile_Phone__c = '1234567891', Mobile_Phone_Status__c = 'Do Not Call'), //Has mobile number, DNC, Close Opp new Contact(FirstName='test6',LastName='tester',AccountId = newAcc.Id, Email = 'test6@testing.com', Normalized_Work_Phone__c = '1234567891', Work_Phone_Status__c = 'Do Not Call') //Has Worknumber DNC is checked }; insert conList; List<Opportunity> oppList = new List<Opportunity>(); Opportunity opptest1 = new Opportunity(Name = 'Opp1', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test1'].id); oppList.add(opptest1); Opportunity opptest2 = new Opportunity(Name = 'Opp2', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test2'].id); oppList.add(opptest2); Opportunity opptest3 = new Opportunity(Name = 'Opp3', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test3'].id); oppList.add(opptest3); Opportunity opptest4 = new Opportunity(Name = 'Opp4', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test4'].id); oppList.add(opptest4); Opportunity opptest5 = new Opportunity(Name = 'Opp5', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test5'].id); oppList.add(opptest5); Opportunity opptest6 = new Opportunity(Name = 'Opp6', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test6'].id); oppList.add(opptest6); Opportunity opptest7 = new Opportunity(Name = 'Opp7', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today()); oppList.add(opptest7); insert oppList; Test.StartTest(); update conList; Test.stopTest(); // Assert Statements System.assertEquals('Closed Lost', opptest1.StageName); //This fails. StageName = 'Ready to Call/Schedule' /* System.assertEquals('Closed Lost', opptest2.StageName); System.assertEquals('Closed Lost', opptest3.StageName); System.assertEquals('Closed Lost', opptest4.StageName); System.assertEquals('Closed Lost', opptest5.StageName); System.assertEquals('Closed Lost', opptest6.StageName); System.assertEquals('Closed Lost', opptest7.StageName); */ } }
- Timothy Smith
- June 23, 2021
- Like
- 0
Access variables of inserted data
At the bottom in my Assertion statements, I am trying to reach the StageName of the Opportunity. However I know that the variable ie (opptest1.StageName) is a reference before the insert and Stagename update. How do I access that specific Opportunity after the Insert?
@isTest private class ContactDNCOpportunityTest { private static testMethod void testCloseOpps(){ //Create Account Account newAcc = FlowTestUtils.createHouseholdAccount(); insert newAcc; //Create Contacts List<Contact> conList = new List<Contact> { new Contact(FirstName='test1',LastName='tester',AccountId = newAcc.Id, Email = 'test1@testing.com', Phone = '1234567891', Phone_Status__c = 'Do Not Call'), //Has Phone Number - Do not call, Closed Opp new Contact(FirstName='test2',LastName='tester',AccountId = newAcc.Id, Email = 'test2@testing.com'), //Blank No Numbers Closed Opp new Contact(FirstName='test3',LastName='tester',AccountId = newAcc.Id, Email = 'test3@testing.com', Normalized_Work_Phone__c = '1234567891',Work_Phone_Status__c = 'Do Not Call'), // Has Work Number, Active, Close Opp new Contact(FirstName='test4',LastName='tester',AccountId = newAcc.Id, Email = 'test4@testing.com', Phone = '1234567891', Phone_Status__c = 'Active'), //Has Phone Number, Active, Do not Close Opp new Contact(FirstName='test5',LastName='tester',AccountId = newAcc.Id, Email = 'test5@testing.com', Normalized_Mobile_Phone__c = '1234567891', Mobile_Phone_Status__c = 'Do Not Call'), //Has mobile number, DNC, Close Opp new Contact(FirstName='test6',LastName='tester',AccountId = newAcc.Id, Email = 'test6@testing.com', Normalized_Work_Phone__c = '1234567891', Work_Phone_Status__c = 'Do Not Call') //Has Worknumber DNC is checked }; insert conList; List<Opportunity> oppList = new List<Opportunity>(); Opportunity opptest1 = new Opportunity(Name = 'Opp1', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test1'].id); oppList.add(opptest1); Opportunity opptest2 = new Opportunity(Name = 'Opp2', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test2'].id); oppList.add(opptest2); Opportunity opptest3 = new Opportunity(Name = 'Opp3', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test3'].id); oppList.add(opptest3); Opportunity opptest4 = new Opportunity(Name = 'Opp4', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test4'].id); oppList.add(opptest4); Opportunity opptest5 = new Opportunity(Name = 'Opp5', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test5'].id); oppList.add(opptest5); Opportunity opptest6 = new Opportunity(Name = 'Opp6', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test6'].id); oppList.add(opptest6); Opportunity opptest7 = new Opportunity(Name = 'Opp7', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today()); oppList.add(opptest7); insert oppList; Test.StartTest(); update conList; Test.stopTest(); /* // Add your assert statements below here. System.assertEquals('Closed Lost', [SELECT Id FROM Opportunity WHERE Primary_Contact Name = 'test1'].id); System.assertEquals('Closed Lost', opptest2.StageName); System.assertEquals('Closed Lost', opptest3.StageName); System.assertEquals('Closed Lost', opptest4.StageName); System.assertEquals('Closed Lost', opptest5.StageName); System.assertEquals('Closed Lost', opptest6.StageName); System.assertEquals('Closed Lost', opptest7.StageName); */ } }
- Timothy Smith
- June 22, 2021
- Like
- 0
APEX testing cant populate my Trigger.new
Opportunity has Primary_Contact__c and Secondary_Contact__c
On Contact 3 phone fields to check:
Phone__c
Work_phone__c
Mobile_phone__c
On Contact 3 Phone Status Fields:
Phone_Status__c
Work_Status__c
Mobile_Status__c.
After Insert/Update of a Contact, the Trigger will check all Opportunities associated with the Contact. If there are no valid (meaning having a number and corresponding status is not equal to "Do Not Call"), then close the Opportunity.
I have created the Trigger and Test Class but I don't understand why the lines in the test class are not executing.
Thank you.
Trigger:
trigger Contact_DNC_Opportunity on Contact (after insert, after update){ List<Opportunity> OpportunitiesToClose = new List<Opportunity>(); List<Opportunity> WorkingOpportunities = [SELECT StageName, Primary_Contact__c, Secondary_Contact__c, Primary_Contact__r.Phone_Status__c, Primary_Contact__r.Mobile_Phone_Status__c, Primary_Contact__r.Work_Phone_Status__c, Primary_Contact__r.Phone, Primary_Contact__r.Normalized_Mobile_Phone__c, Primary_Contact__r.Normalized_Work_Phone__c, Secondary_Contact__r.Phone_Status__c, Secondary_Contact__r.Mobile_Phone_Status__c, Secondary_Contact__r.Work_Phone_Status__c, Secondary_Contact__r.Phone, Secondary_Contact__r.Normalized_Mobile_Phone__c, Secondary_Contact__r.Normalized_Work_Phone__c FROM Opportunity WHERE Primary_Contact__c In :Trigger.New OR Secondary_Contact__c In :Trigger.New ]; System.debug(WorkingOpportunities); for(Opportunity opp: WorkingOpportunities){ //Check Primary Contact phone numbers if ((opp.Primary_Contact__r.Phone == Null) || (opp.Primary_Contact__r.Phone_Status__c == 'Do Not Call')&& (opp.Primary_Contact__r.Normalized_Mobile_Phone__c == Null) || (opp.Primary_Contact__r.Mobile_Phone_Status__c == 'Do Not Call')&& (opp.Primary_Contact__r.Normalized_Work_Phone__c == Null) || (opp.Primary_Contact__r.Work_Phone_Status__c == 'Do Not Call')&& (opp.Secondary_Contact__r.Phone == Null) || (opp.Secondary_Contact__r.Phone_Status__c == 'Do Not Call')&& (opp.Secondary_Contact__r.Normalized_Mobile_Phone__c == Null) || (opp.Secondary_Contact__r.Mobile_Phone_Status__c == 'Do Not Call')&& (opp.Secondary_Contact__r.Normalized_Work_Phone__c == Null) || (opp.Secondary_Contact__r.Work_Phone_Status__c == 'Do Not Call') ) { //Add opp to List if fits criteria opportunitiesToClose.add(opp); } } for (Opportunity opp1 : opportunitiesToClose){ opp1.StageName = 'Closed Lost'; } if(opportunitiesToClose.size() > 0){ update opportunitiesToClose ; } }
Test Class:
@isTest private class ContactDNCOpportunityTest { private static testMethod void testCloseOpps(){ //Create Account Account newAcc = FlowTestUtils.createHouseholdAccount(); insert newAcc; //Create Contacts List<Contact> conList = new List<Contact> { new Contact(FirstName='test1',LastName='tester',AccountId = newAcc.Id, Email = 'test1@testing.com', Phone = '1234567891', Phone_Status__c = 'Do Not Call'), //Has Phone Number - Do not call, Closed Opp new Contact(FirstName='test2',LastName='tester',AccountId = newAcc.Id, Email = 'test2@testing.com'), //Blank No Numbers Closed Opp new Contact(FirstName='test3',LastName='tester',AccountId = newAcc.Id, Email = 'test3@testing.com', Normalized_Work_Phone__c = '1234567891',Work_Phone_Status__c = 'Active'), // Has Work Number, Active, Do Not Close Opp new Contact(FirstName='test4',LastName='tester',AccountId = newAcc.Id, Email = 'test4@testing.com', Phone = '1234567891', Phone_Status__c = 'Active'), //Has Phone Number, Active, Do not Close Opp new Contact(FirstName='test5',LastName='tester',AccountId = newAcc.Id, Email = 'test5@testing.com', Normalized_Mobile_Phone__c = '1234567891', Mobile_Phone_Status__c = 'Do Not Call'), //Has mobile number, DNC, Close Opp new Contact(FirstName='test6',LastName='tester',AccountId = newAcc.Id, Email = 'test6@testing.com', Normalized_Work_Phone__c = '1234567891', Work_Phone_Status__c = 'Do Not Call') //Has Worknumber DNC is checked }; insert conList; Opportunity opptest1 = new Opportunity(Name = 'Opp1', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test1'].id); Test.startTest(); insert opptest1; Test.stopTest(); System.assertEquals('Closed', opptest1.StageName); Opportunity opptest2 = new Opportunity(Name = 'Opp2', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test2'].id); Test.startTest(); insert opptest2; Test.stopTest(); System.assertEquals('Closed', opptest2.StageName); Opportunity opptest3 = new Opportunity(Name = 'Opp3', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test3'].id); Test.startTest(); insert opptest3; Test.stopTest(); System.assertEquals('Closed', opptest3.StageName); Opportunity opptest4 = new Opportunity(Name = 'Opp4', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test4'].id); Test.startTest(); insert opptest4; Test.stopTest(); System.assertNotEquals('Closed', opptest4.StageName); Opportunity opptest5 = new Opportunity(Name = 'Opp5', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test5'].id); Test.startTest(); insert opptest5; Test.stopTest(); System.assertEquals('Closed', opptest5.StageName); Opportunity opptest6 = new Opportunity(Name = 'Opp6', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test6'].id); Test.startTest(); insert opptest6; Test.stopTest(); System.assertEquals('Closed', opptest6.StageName); Opportunity opptest7 = new Opportunity(Name = 'Opp7', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today()); Test.startTest(); insert opptest7; Test.stopTest(); System.assertEquals('Closed', opptest7.StageName); } }
- Timothy Smith
- June 22, 2021
- Like
- 0
Illegal Assignment from List to Id - Apex Test
on lines: 24, 32, 40, 48, 56, 64
Thank you
@isTest private class ContactDNCOpportunityTest { private static testMethod void testCloseOpps(){ //Create Account Account newAcc = FlowTestUtils.createHouseholdAccount(); insert newAcc; //Create Contacts List<Contact> conList = new List<Contact> { new Contact(FirstName='test1',LastName='tester',AccountId = newAcc.Id, Email = 'test1@testing.com', Phone = '1234567891', Phone_Status__c = 'Do Not Call'), //Has Phone Number - Do not call, Closed Opp new Contact(FirstName='test2',LastName='tester',AccountId = newAcc.Id, Email = 'test2@testing.com'), //Blank No Numbers Closed Opp new Contact(FirstName='test3',LastName='tester',AccountId = newAcc.Id, Email = 'test3@testing.com', Normalized_Work_Phone__c = '1234567891',Work_Phone_Status__c = 'Active'), // Has Work Number, Active, Do Not Close Opp new Contact(FirstName='test4',LastName='tester',AccountId = newAcc.Id, Email = 'test4@testing.com', Phone = '1234567891', Phone_Status__c = 'Active'), //Has Phone Number, Active, Do not Close Opp new Contact(FirstName='test5',LastName='tester',AccountId = newAcc.Id, Email = 'test5@testing.com', Normalized_Mobile_Phone__c = '1234567891', Mobile_Phone_Status__c = 'Do Not Call'), //Has mobile number, DNC, Close Opp new Contact(FirstName='test6',LastName='tester',AccountId = newAcc.Id, Email = 'test6@testing.com', Normalized_Work_Phone__c = '1234567891', Work_Phone_Status__c = 'Do Not Call') //Has Worknumber DNC is checked }; insert conList; Opportunity opptest1 = new Opportunity(Name = 'Opp1', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test1']); Test.startTest(); insert opptest1; Test.stopTest(); System.assertEquals('Closed', opptest1.StageName); Opportunity opptest2 = new Opportunity(Name = 'Opp2', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test2']); Test.startTest(); insert opptest2; Test.stopTest(); System.assertEquals('Closed', opptest2.StageName); Opportunity opptest3 = new Opportunity(Name = 'Opp3', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test3']); Test.startTest(); insert opptest3; Test.stopTest(); System.assertEquals('Closed', opptest3.StageName); Opportunity opptest4 = new Opportunity(Name = 'Opp4', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test4']); Test.startTest(); insert opptest4; Test.stopTest(); System.assertNotEquals('Closed', opptest4.StageName); Opportunity opptest5 = new Opportunity(Name = 'Opp5', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test5']); Test.startTest(); insert opptest5; Test.stopTest(); System.assertEquals('Closed', opptest5.StageName); Opportunity opptest6 = new Opportunity(Name = 'Opp6', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test6']); Test.startTest(); insert opptest6; Test.stopTest(); System.assertEquals('Closed', opptest6.StageName); Opportunity opptest7 = new Opportunity(Name = 'Opp7', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today()); Test.startTest(); insert opptest7; Test.stopTest(); System.assertEquals('Closed', opptest7.StageName); } }
- Timothy Smith
- June 21, 2021
- Like
- 0
Illegal Assignment Errors
@isTest private class ContactDNCOpportunityTest { private static testMethod void testCloseOpps(){ //Create Account Account newAcc = FlowTestUtils.createHouseholdAccount(); insert newAcc; //Create Contacts List<Contact> conList = new List<Contact> { new Contact(FirstName='test1',LastName='tester',AccountId = newAcc.Id, Email = 'test1@testing.com', Phone = 1234567891, Phone_Status__c = 'Do Not Call'), //Has Phone Number - Do not call, Closed Opp new Contact(FirstName='test2',LastName='tester',AccountId = newAcc.Id, Email = 'test2@testing.com'), //Blank No Numbers Closed Opp new Contact(FirstName='test3',LastName='tester',AccountId = newAcc.Id, Email = 'test3@testing.com', Normalized_Work_Phone__c = 1234567891,Work_Phone_Status__c = 'Active'), // Has Work Number, Active, Do Not Close Opp new Contact(FirstName='test4',LastName='tester',AccountId = newAcc.Id, Email = 'test4@testing.com', Phone = 1234567891, Phone_Status__c = 'Active'), //Has Phone Number, Active, Do not Close Opp new Contact(FirstName='test5',LastName='tester',AccountId = newAcc.Id, Email = 'test5@testing.com', Normalized_Mobile_Phone__c = 1234567891, Mobile_Phone_Status__c = 'Do Not Call'), //Has mobile number, DNC, Close Opp new Contact(FirstName='test6',LastName='tester',AccountId = newAcc.Id, Email = 'test6@testing.com', Normalized_Work_Phone__c = 1234567891, Work_Phone_Status__c = 'Do Not Call') //Has Worknumber DNC is checked }; insert conList; Test.startTest(); Opportunity opptest1 = new Opportunity(Name = 'Opp1', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test1']); insert opptest1; Test.stopTest(); System.assertEquals('Closed', opptest1.StageName); Test.startTest(); Opportunity opptest2 = new Opportunity(Name = 'Opp2', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test2']); insert opptest2; Test.stopTest(); System.assertEquals('Closed', opptest2.StageName); Test.startTest(); Opportunity opptest3 = new Opportunity(Name = 'Opp3', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test3']); insert opptest3; Test.stopTest(); System.assertEquals('Closed', opptest3.StageName); Test.startTest(); Opportunity opptest4 = new Opportunity(Name = 'Opp4', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test4']); insert opptest4; Test.stopTest(); System.assertNotEquals('Closed', opptest4.StageName); Test.startTest(); Opportunity opptest5 = new Opportunity(Name = 'Opp5', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test5']); insert opptest5; Test.stopTest(); System.assertEquals('Closed', opptest5.StageName); Test.startTest(); Opportunity opptest6 = new Opportunity(Name = 'Opp6', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test6']); insert opptest6; Test.stopTest(); System.assertEquals('Closed', opptest6.StageName); Test.startTest(); Opportunity opptest7 = new Opportunity(Name = 'Opp7', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today()); insert opptest7; Test.stopTest(); System.assertEquals('Closed', opptest7.StageName); }; }
My Errors:
- Timothy Smith
- June 21, 2021
- Like
- 0
Error: 'Field does not exist: AccountId on Contact'
@isTest private class ContactDNCOpportunityTest { private static testMethod void testCloseOpps(){ //Create Account Account newAcc = FlowTestUtils.createHouseholdAccount(); insert newAcc; //Create Contacts List<Contact> conList = new List<Contact> { new Contact(FirstName='test1',LastName='tester',AccoutId = newAcc.Id, Email = 'test1@testing.com', Phone = 1234567891, Phone_Status__c = True, Work_Phone_Status__c = False, Mobile_Phone_Status__c = False), //Has Phone Number DNC is Checked new Contact(FirstName='test2',LastName='tester',AccoutId = newAcc.Id, Email = 'test2@testing.com', Phone_Status__c = False,Work_Phone_Status__c = False, Mobile_Phone_Status__c = False), //Blank No Numbers new Contact(FirstName='test3',LastName='tester',AccoutId = newAcc.Id, Email = 'test3@testing.com', Normalized_Work_Phone__c = 1234567891,Phone_Status__c = False, Work_Phone_Status__c = False, Mobile_Phone_Status__c = False), // Has Worknumber DNC not checked new Contact(FirstName='test4',LastName='tester',AccoutId = newAcc.Id, Email = 'test4@testing.com', Phone = 1234567891, Phone_Status__c = False, Work_Phone_Status__c = False, Mobile_Phone_Status__c = False), //Has Phone Number DNC not checked new Contact(FirstName='test5',LastName='tester',AccoutId = newAcc.Id, Email = 'test5@testing.com', Normalized_Mobile_Phone__c = 1234567891, Mobile_Phone_Status__c = True, Phone_Status__c = False,Work_Phone_Status__c = False), //Has mobile number DNC is checked new Contact(FirstName='test6',LastName='tester',AccoutId = newAcc.Id, Email = 'test6@testing.com', Normalized_Work_Phone__c = 1234567891, Phone_Status__c = False, Work_Phone_Status__c = True,Mobile_Phone_Status__c = False) //Has Worknumber DNC is checked }; insert conList; Test.startTest(); Opportunity opptest1 = new Opportunity(Name = 'Opp1', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test1']); insert opptest1; Test.stopTest(); System.assertEquals('Closed', opptest1.StageName); Test.startTest(); Opportunity opptest2 = new Opportunity(Name = 'Opp2', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test2']); insert opptest2; Test.stopTest(); System.assertEquals('Closed', opptest2.StageName); Test.startTest(); Opportunity opptest3 = new Opportunity(Name = 'Opp3', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test3']); insert opptest3; Test.stopTest(); System.assertEquals('Closed', opptest3.StageName); Test.startTest(); Opportunity opptest4 = new Opportunity(Name = 'Opp4', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test4']); insert opptest4; Test.stopTest(); System.assertNotEquals('Closed', opptest4.StageName); Test.startTest(); Opportunity opptest5 = new Opportunity(Name = 'Opp5', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test5']); insert opptest5; Test.stopTest(); System.assertEquals('Closed', opptest5.StageName); Test.startTest(); Opportunity opptest6 = new Opportunity(Name = 'Opp6', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test6']); insert opptest6; Test.stopTest(); System.assertEquals('Closed', opptest6.StageName); Test.startTest(); Opportunity opptest7 = new Opportunity(Name = 'Opp7', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today()); insert opptest7; Test.stopTest(); System.assertEquals('Closed', opptest7.StageName); }; }
- Timothy Smith
- June 21, 2021
- Like
- 0
Error: Method must have a body
@isTest private class ContactDNCTest { private static testMethod void testCloseOpps(){ //Create Account Account newAcc = FlowTestUtils.createHouseholdAccount(); insert newAcc; //Create Contacts List<Contact> conList = new List<Contact> { new Contact(FirstName='test1',LastName='tester',AccoutId = newAcc.Id, Email = 'test1@testing.com', Phone = 1234567891, Phone_Status__c = True, Work_Phone_Status__c = False, Mobile_Phone_Status__c = False), //Has Phone Number and Phone Status True new Contact(FirstName='test2',LastName='tester',AccoutId = newAcc.Id, Email = 'test2@tetsing.com', Phone_Status__c = False,Work_Phone_Status__c = False, Mobile_Phone_Status__c = False), // new Contact(FirstName='test3',LastName='tester',AccoutId = newAcc.Id, Email = 'test3@tetsing.com', Normalized_Work_Phone__c = 1234567891,Phone_Status__c = False, Work_Phone_Status__c = True, Mobile_Phone_Status__c = False), new Contact(FirstName='test4',LastName='tester',AccoutId = newAcc.Id, Email = 'test4@tetsing.com', Phone = 1234567891, Phone_Status__c = False, Work_Phone_Status__c = False, Mobile_Phone_Status__c = False), new Contact(FirstName='test5',LastName='tester',AccoutId = newAcc.Id, Email = 'test5@tetsing.com', Normalized_Mobile_Phone__c = 1234567891, Mobile_Phone_Status__c = True, Phone_Status__c = False,Work_Phone_Status__c = False), new Contact(FirstName='test6',LastName='tester',AccoutId = newAcc.Id, Email = 'test6@tetsing.com', Normalized_Work_Phone__c = 1234567891, Phone_Status__c = False, Work_Phone_Status__c = False,Mobile_Phone_Status__c = False) }; insert conList; //Create a List of Opportunities List<Opportunity> oppList = new List<Opportunity>{ new Opportunity(Name = 'Opp1', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = ['test1'], new Opportunity(Name = 'Opp2', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = ['test2'], new Opportunity(Name = 'Opp3', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = ['test3'], new Opportunity(Name = 'Opp4', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = ['test4'], new Opportunity(Name = 'Opp5', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = ['test5'], new Opportunity(Name = 'Opp7', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = ['test6'], new Opportunity(Name = 'Opp8', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today() }; insert oppList; } }
- Timothy Smith
- June 16, 2021
- Like
- 0
XML Parsing Error when Merging
This file has an XML parsing error: /opt/atlassian/pipelines/agent/build/force-app/main/default/objects/Task/listViews/Day_QAR_Last_Night_Reschedule_Queue.listView-meta.xml:
This same error repeats seven times
In VSCode:
<?xml version="1.0" encoding="UTF-8"?> <ListView xmlns="http://soap.sforce.com/2006/04/metadata"> <fullName>Day_QAR_Last_Night_Reschedule_Queue</fullName> <columns>Accept_Task__c</columns> <columns>SUBJECT</columns> <columns>WHO_NAME</columns> <columns>Territory__c</columns> <columns>WHAT_NAME</columns> <columns>DUE_DATE</columns> <columns>STATUS</columns> <columns>PRIORITY</columns> <columns>CORE.USERS.ALIAS</columns> <columns>Last_Called_By_DateTime__c</columns> <columns>Last_Called_By_Name__c</columns> <columns>Call_Outcome__c</columns> <filterScope>Everything</filterScope> <filters> <field>STATUS</field> <operation>equals</operation> <value>Open</value> </filters> <filters> <field>SUBJECT</field> <operation>equals</operation> <value>Reschedule Appointment</value> </filters> <filters> <field>DUE_DATE</field> <operation>equals</operation> <value>TODAY</value> </filters> <filters> <field>Call_Outcome__c</field> <operation>notEqual</operation> <value>Callback Later,Voice mail,Hang up,No Answer/No Contact,Voicemail Full</value> </filters> <filters> <field>CORE.USERS.FULL_NAME</field> <operation>equals</operation> <value>QAR Queue</value> </filters> <label>Day QAR Last Night Reschedule Queue</label> <sharedTo> <role>Marketing_Manager</role> <role>QAR</role> <role>QAR_Assistant_Manager</role> </sharedTo> </ListView>Any Ideas?
Thank you
- Timothy Smith
- June 15, 2021
- Like
- 0
Trigger, after first SOQL seems to stop executing without error.
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
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.
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
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
Unexpected file found in package directory: -Received when delploying with VSCode.
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
Edit Source Code of Record Page?
Opportunity -> Appointment__c -> Task
On the Task Object the request is to have the 'Related To' field which shows the Opportunity Name, to become a hyperlink to the Opportunity if the 'Related To' is an Opportunity Record. Can this be done by editing the Task Layout in VSCode/Source Code, or am I forced to create a custom Lighting Component for one field change? Thank you
I have a request to change the value of the 'Related To' field into a hyperlink back to the specified record (Opportunity).
- Timothy Smith
- July 01, 2021
- Like
- 0
Access variables of inserted data
At the bottom in my Assertion statements, I am trying to reach the StageName of the Opportunity. However I know that the variable ie (opptest1.StageName) is a reference before the insert and Stagename update. How do I access that specific Opportunity after the Insert?
@isTest private class ContactDNCOpportunityTest { private static testMethod void testCloseOpps(){ //Create Account Account newAcc = FlowTestUtils.createHouseholdAccount(); insert newAcc; //Create Contacts List<Contact> conList = new List<Contact> { new Contact(FirstName='test1',LastName='tester',AccountId = newAcc.Id, Email = 'test1@testing.com', Phone = '1234567891', Phone_Status__c = 'Do Not Call'), //Has Phone Number - Do not call, Closed Opp new Contact(FirstName='test2',LastName='tester',AccountId = newAcc.Id, Email = 'test2@testing.com'), //Blank No Numbers Closed Opp new Contact(FirstName='test3',LastName='tester',AccountId = newAcc.Id, Email = 'test3@testing.com', Normalized_Work_Phone__c = '1234567891',Work_Phone_Status__c = 'Do Not Call'), // Has Work Number, Active, Close Opp new Contact(FirstName='test4',LastName='tester',AccountId = newAcc.Id, Email = 'test4@testing.com', Phone = '1234567891', Phone_Status__c = 'Active'), //Has Phone Number, Active, Do not Close Opp new Contact(FirstName='test5',LastName='tester',AccountId = newAcc.Id, Email = 'test5@testing.com', Normalized_Mobile_Phone__c = '1234567891', Mobile_Phone_Status__c = 'Do Not Call'), //Has mobile number, DNC, Close Opp new Contact(FirstName='test6',LastName='tester',AccountId = newAcc.Id, Email = 'test6@testing.com', Normalized_Work_Phone__c = '1234567891', Work_Phone_Status__c = 'Do Not Call') //Has Worknumber DNC is checked }; insert conList; List<Opportunity> oppList = new List<Opportunity>(); Opportunity opptest1 = new Opportunity(Name = 'Opp1', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test1'].id); oppList.add(opptest1); Opportunity opptest2 = new Opportunity(Name = 'Opp2', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test2'].id); oppList.add(opptest2); Opportunity opptest3 = new Opportunity(Name = 'Opp3', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test3'].id); oppList.add(opptest3); Opportunity opptest4 = new Opportunity(Name = 'Opp4', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test4'].id); oppList.add(opptest4); Opportunity opptest5 = new Opportunity(Name = 'Opp5', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test5'].id); oppList.add(opptest5); Opportunity opptest6 = new Opportunity(Name = 'Opp6', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test6'].id); oppList.add(opptest6); Opportunity opptest7 = new Opportunity(Name = 'Opp7', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today()); oppList.add(opptest7); insert oppList; Test.StartTest(); update conList; Test.stopTest(); /* // Add your assert statements below here. System.assertEquals('Closed Lost', [SELECT Id FROM Opportunity WHERE Primary_Contact Name = 'test1'].id); System.assertEquals('Closed Lost', opptest2.StageName); System.assertEquals('Closed Lost', opptest3.StageName); System.assertEquals('Closed Lost', opptest4.StageName); System.assertEquals('Closed Lost', opptest5.StageName); System.assertEquals('Closed Lost', opptest6.StageName); System.assertEquals('Closed Lost', opptest7.StageName); */ } }
- Timothy Smith
- June 22, 2021
- Like
- 0
Illegal Assignment Errors
@isTest private class ContactDNCOpportunityTest { private static testMethod void testCloseOpps(){ //Create Account Account newAcc = FlowTestUtils.createHouseholdAccount(); insert newAcc; //Create Contacts List<Contact> conList = new List<Contact> { new Contact(FirstName='test1',LastName='tester',AccountId = newAcc.Id, Email = 'test1@testing.com', Phone = 1234567891, Phone_Status__c = 'Do Not Call'), //Has Phone Number - Do not call, Closed Opp new Contact(FirstName='test2',LastName='tester',AccountId = newAcc.Id, Email = 'test2@testing.com'), //Blank No Numbers Closed Opp new Contact(FirstName='test3',LastName='tester',AccountId = newAcc.Id, Email = 'test3@testing.com', Normalized_Work_Phone__c = 1234567891,Work_Phone_Status__c = 'Active'), // Has Work Number, Active, Do Not Close Opp new Contact(FirstName='test4',LastName='tester',AccountId = newAcc.Id, Email = 'test4@testing.com', Phone = 1234567891, Phone_Status__c = 'Active'), //Has Phone Number, Active, Do not Close Opp new Contact(FirstName='test5',LastName='tester',AccountId = newAcc.Id, Email = 'test5@testing.com', Normalized_Mobile_Phone__c = 1234567891, Mobile_Phone_Status__c = 'Do Not Call'), //Has mobile number, DNC, Close Opp new Contact(FirstName='test6',LastName='tester',AccountId = newAcc.Id, Email = 'test6@testing.com', Normalized_Work_Phone__c = 1234567891, Work_Phone_Status__c = 'Do Not Call') //Has Worknumber DNC is checked }; insert conList; Test.startTest(); Opportunity opptest1 = new Opportunity(Name = 'Opp1', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test1']); insert opptest1; Test.stopTest(); System.assertEquals('Closed', opptest1.StageName); Test.startTest(); Opportunity opptest2 = new Opportunity(Name = 'Opp2', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test2']); insert opptest2; Test.stopTest(); System.assertEquals('Closed', opptest2.StageName); Test.startTest(); Opportunity opptest3 = new Opportunity(Name = 'Opp3', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test3']); insert opptest3; Test.stopTest(); System.assertEquals('Closed', opptest3.StageName); Test.startTest(); Opportunity opptest4 = new Opportunity(Name = 'Opp4', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test4']); insert opptest4; Test.stopTest(); System.assertNotEquals('Closed', opptest4.StageName); Test.startTest(); Opportunity opptest5 = new Opportunity(Name = 'Opp5', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test5']); insert opptest5; Test.stopTest(); System.assertEquals('Closed', opptest5.StageName); Test.startTest(); Opportunity opptest6 = new Opportunity(Name = 'Opp6', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test6']); insert opptest6; Test.stopTest(); System.assertEquals('Closed', opptest6.StageName); Test.startTest(); Opportunity opptest7 = new Opportunity(Name = 'Opp7', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today()); insert opptest7; Test.stopTest(); System.assertEquals('Closed', opptest7.StageName); }; }
My Errors:
- Timothy Smith
- June 21, 2021
- Like
- 0
Trigger, after first SOQL seems to stop executing without error.
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.
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
`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
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
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
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?
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?
- Timothy Smith
- October 11, 2019
- Like
- 0
How to Access Account.Name field within SOQL using Aggregate
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
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
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