You need to sign in to do that
Don't have an account?
Ivan Winzer
Help with @isTest errors
So recently moved over to Person accounts in lightning and need to make an update to a class and trigger. however when i try to push the changes from sandbox to production i get a bunch of errors in regards to already established @istest and other classes in my production org and wondering if anyone can help. These are the errors im getting and the assocaited classes or test:
Run Failures:
GuestAccountPopulateTest.PositiveTest System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_EXECUTE_FLOW_TRIGGER, We can't save this record because the “New Guest” process failed. Give your Salesforce admin these details. Probably Limit Exceeded or 0 recipients
: []
Test_ContactWineClub.myUnitTest System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Account__c]: [Account__c]
Test_PrimaryAddressValidationTriger.testCreateShipToAddress System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, mainShipToAddessTrigger: execution of BeforeInsert
caused by: System.QueryException: List has no rows for assignment to SObject
Trigger.mainShipToAddessTrigger: line 9, column 1: []
Test_ShiptoAddressTrigger.testCreateShipToAddress System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, mainShipToAddessTrigger: execution of BeforeInsert
caused by: System.QueryException: List has no rows for assignment to SObject
Trigger.mainShipToAddessTrigger: line 9, column 1: []
WineClubMembershipAccountPopulateTest.PositiveTest System.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Business Customer may not use Person Customer field : WC Tenure: [WC Tenure]
Any help is greatly appreciated as we are having integration issues with missing data and unable to update my main class and trigger since the above are causing me errors when trying to deploy to production
Run Failures:
GuestAccountPopulateTest.PositiveTest System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_EXECUTE_FLOW_TRIGGER, We can't save this record because the “New Guest” process failed. Give your Salesforce admin these details. Probably Limit Exceeded or 0 recipients
: []
Test_ContactWineClub.myUnitTest System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Account__c]: [Account__c]
Test_PrimaryAddressValidationTriger.testCreateShipToAddress System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, mainShipToAddessTrigger: execution of BeforeInsert
caused by: System.QueryException: List has no rows for assignment to SObject
Trigger.mainShipToAddessTrigger: line 9, column 1: []
Test_ShiptoAddressTrigger.testCreateShipToAddress System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, mainShipToAddessTrigger: execution of BeforeInsert
caused by: System.QueryException: List has no rows for assignment to SObject
Trigger.mainShipToAddessTrigger: line 9, column 1: []
WineClubMembershipAccountPopulateTest.PositiveTest System.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Business Customer may not use Person Customer field : WC Tenure: [WC Tenure]
@isTest private class Test_ContactWineClub { static testMethod void myUnitTest() { date myDate = date.today(); Account a = new Account(Name = 'Test MainContactTrigger', RecordTypeID = '0121W000000UgfA'); // a.RecordType = 'Household'; insert a; Contact c = new Contact(AccountID = a.id, firstName = 'Test MainContactTrigger', lastName = 'Tester', email = 'testfake@gmail.com'); insert c; // System.debug('Contact record num: ' + [SELECT Id FROM Contact].size()); Wineclub_Membership__c wc = new Wineclub_Membership__c( Contact__c = c.id, Active__c = true , Wine_Club_Code__c = 'Collection 2 Bottle', Start_Date__c = myDate); insert wc; c = [select AccountId, Account.Name from Contact where id = :c.id limit 1]; System.assertEquals('Test MainContactTrigger', a.Name); System.assertEquals(1, [SELECT Id FROM Contact].size()); System.assertEquals(a.id, c.AccountId); } }
@isTest private class Test_PrimaryAddressValidationTriger { @isTest public static void testCreateShipToAddress(){ Account a = new Account(Name = 'Test PrimaryAddressValidation', RecordTypeID = '0121W000000UgfA'); insert a; Contact c = new Contact(AccountID = a.ID, firstName = 'Test PrimaryAddressValidation', lastName = 'Tester', email = 'fakington@gmail.com'); insert c; ShipTo_Address__c s1 = new ShipTo_Address__c( Contact__c = c.id, Address__c = '1919 Fakeone Way', City__c = 'Fakington', State__c = 'CA', Country__c = 'USA', ZIP__c = '00000', Primary_Billing_Address__c = true); insert s1; ShipTo_Address__c s2 = new ShipTo_Address__c( Contact__c = c.id, Address__c = '1600 Alrington Way', City__c = 'Oakland', State__c = 'CA', Country__c = 'USA', ZIP__c = '00000', Default_Shipping_Address__c = true); insert s2; c = [select AccountID,Account.Name from Contact where id = :c.id limit 1]; System.assertEquals('Test PrimaryAddressValidation', c.Account.Name); System.assertEquals(a.id, c.AccountID); } }
@isTest public with sharing class Test_ShiptoAddressTrigger { @isTest public static void testCreateShipToAddress(){ Account a = new Account(Name = 'Test MainShipToAddressTrigger', RecordTypeID = '01240000000UZ4V'); insert a; Contact c = new Contact(AccountID = a.ID, firstName = 'Test MainShipToAddressTrigger', lastName = 'Tester', email = 'fakington@gmail.com'); insert c; ShipTo_Address__c s1 = new ShipTo_Address__c( Contact__c = c.id, Address__c = '1919 Fakeone Way', City__c = 'Fakington', State__c = 'CA', Country__c = 'USA', ZIP__c = '00000', Primary_Billing_Address__c = true); insert s1; ShipTo_Address__c s2 = new ShipTo_Address__c( Contact__c = c.id, Address__c = '1919 Fakeone Way', City__c = 'Fakington', State__c = 'CA', Country__c = 'USA', ZIP__c = '00000', Default_Shipping_Address__c = true); insert s2; c = [select AccountId,Account.Name from Contact where id = :c.id limit 1]; System.assertEquals('Test MainShipToAddressTrigger', c.Account.Name); System.assertEquals(a.id, c.AccountId); } }
@isTest public class WineClubMembershipAccountPopulateTest { @testSetup static void setup(){ Account acc = new Account(); acc.Name = 'Test1'; insert acc; Contact con = new Contact(); con.AccountId = acc.id; con.lastName = 'Test1'; insert con; Wineclub_Membership__c wineClub = new Wineclub_Membership__C(); wineClub.Account__c = acc.id; wineClub.Contact__c = con.id; insert wineClub; } @isTest static void PositiveTest() { Test.startTest(); database.executeBatch(new WineClubMembershipAccountPopulate(), 200); Test.stopTest(); Wineclub_Membership__c wineClub = [SELECT Id, account__c, contact__c FROM Wineclub_Membership__c Limit 1]; System.assertNotEquals(null, wineClub.account__c); } }
Any help is greatly appreciated as we are having integration issues with missing data and unable to update my main class and trigger since the above are causing me errors when trying to deploy to production
GuestAccountPopulateTest.PositiveTest System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_EXECUTE_FLOW_TRIGGER, We can't save this record because the “New Guest” process failed. Give your Salesforce admin these details. Probably Limit Exceeded or 0 recipients
: [] --> this one is related to process builder and the name is “New Guest” please check for the criteria and correct the data.
Test_ContactWineClub.myUnitTest System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Account__c]: [Account__c] --> Here the required field Account__c is missing so please add the data to that field in your test class
Test_PrimaryAddressValidationTriger.testCreateShipToAddress System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, mainShipToAddessTrigger: execution of BeforeInsert
caused by: System.QueryException: List has no rows for assignment to SObject -->mainShipToAddessTrigger this trigger expecting the records but your test class is missing those.
Trigger.mainShipToAddessTrigger: line 9, column 1: []
WineClubMembershipAccountPopulateTest.PositiveTest System.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Business Customer may not use Person Customer field : WC Tenure: [WC Tenure] --> Business Customer may not use Person Customer field here the user is not having the access to that field.
Based on my comments you can correct the data and it will resolve your issue.
Test_ContactWineClubmyUnitTestSystem.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Unable to create/update fields: Name. Please check the security settings of this field and verify that it is read/write for your profile or permission set.: [Name]
Stack Trace: Class.Test_ContactWineClub.myUnitTest: line 31, column 1
Test_PrimaryAddressValidationTrigertestCreateShipToAddressSystem.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Unable to create/update fields: Name. Please check the security settings of this field and verify that it is read/write for your profile or permission set.: [Name]
Stack Trace: Class.Test_PrimaryAddressValidationTriger.testCreateShipToAddress: line 28, column 1
Test_ShiptoAddressTriggertestCreateShipToAddressSystem.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, mainShipToAddessTrigger: execution of BeforeInsert caused by: System.QueryException: List has no rows for assignment to SObject Trigger.mainShipToAddessTrigger: line 9, column 1: []
Stack Trace: Class.Test_ShiptoAddressTrigger.testCreateShipToAddress: line 19, column 1
WineClubMembershipAccountPopulateTestPositiveTestSystem.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Business Customer may not use Person Customer field : WC Tenure: [WC Tenure]
Stack Trace: Class.WineClubMembershipAccountPopulateTest.setup: line 25, column 1
And i wonder for the last issue how do i reflect in the test that i am only looking for a person account record type so the business customer accounts are not effected.
Ivan
check for the deployment user and while deploying the changes the test classes will run by taking that user Id.
Test_ContactWineClubmyUnitTestSystem.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Unable to create/update fields: Name. Please check the security settings of this field and verify that it is read/write for your profile or permission set.: [Name]
Stack Trace: Class.Test_ContactWineClub.myUnitTest: line 31, column 1 ==> [Name] go to field-level security and give access to the field for the user who is deploying the changes. or check for the code if there is any system.runAs() {--> then you need change the profile for the user you are inserting in the test class "Test_ContactWineClubmyUnitTest"}.
Test_ShiptoAddressTriggertestCreateShipToAddressSystem.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, mainShipToAddessTrigger: execution of BeforeInsert caused by: System.QueryException: List has no rows for assignment to SObject Trigger.mainShipToAddessTrigger: line 9, column 1: []
Stack Trace: Class.Test_ShiptoAddressTrigger.testCreateShipToAddress: line 19, column 1 --> for this test class plese add system.assert to check for the mainShipToAddess in this test class "Test_ShiptoAddressTriggertestCreateShipToAddress" then you will know where you are doing wrong with the data.
WineClubMembershipAccountPopulateTestPositiveTestSystem.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Business Customer may not use Person Customer field : WC Tenure: [WC Tenure]
Stack Trace: Class.WineClubMembershipAccountPopulateTest.setup: line 25, column 1 --> for this error my best suggestion is to change the code (test class) like the below
Profile pf= [Select Id from profile where Name='System Administrator'];
User u = new User(Alias = 'standt', Email='standarduser@testorg.com', EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', LocaleSidKey='en_US', ProfileId = p.Id, TimeZoneSidKey='America/Los_Angeles', UserName='standarduser@testorg.com');
insert u;
System.runAs(u) {
// past your test method data here.
}
follow the same for all the test methods in that class then it will resolve the issue.