You need to sign in to do that
Don't have an account?
Brittanie
Test with Error: System.QueryException: List has no rows for assignment to SObject
My trigger works great but...
After 80 drafts of the test I can't get it to work.... I need to make about 4 more triggers similar to this so this one test is kinda of crucial to recreate it for the others.
Currently getting the following error:
Error Message System.QueryException: List has no rows for assignment to SObject Stack Trace Class.UpdateAcctContactDecliningTestClass.myUnitTest: line 22, column 1
@isTest private class UpdateAcctContactDecliningTestClass { static testMethod void myUnitTest(){ Account accts = new Account (Contact_Declining__c = Null); System.debug('Created Account with Id: ' + accts.id); // fill in all other required fields fields Opportunity o = new Opportunity(AccountId=accts.Id,Primary_Contact__c = '003000000001NjA'); o.Primary_Contact__c = '003000000001NjA'; Test.startTest(); //verify if the trigger did the job System.assertEquals(o.Primary_Contact__c,[SELECT Contact_Declining__c FROM Account WHERE Id = :accts.Id].Contact_Declining__c ); update accts; Test.stopTest(); } }
trigger UpdateAcctContactDeclining on Opportunity (before insert, before update) { //map to hold the account id and the corresponding related opportunity Map<Id,Opportunity> mapAccIdToOpp=new Map<Id,Opportunity>(); List<Id> AccountsToUpdate = new List<Id>{}; // Find accounts to update for(Opportunity o: Trigger.new){ if (o.AccountId != Null) { AccountsToUpdate.add(o.AccountId); } // Update the accounts Account[] accts = [SELECT Id, Contact_Declining__c FROM Account WHERE Id IN :AccountsToUpdate]; for(Account a: accts){ a.Contact_Declining__c = o.Primary_Contact__c ; } update accts; //do the update } }
Brittanie again in trouble ?
Seems like I have seen the test class somewhere
Anyways you never inserted test data in your class and that was the mistake
try this
If it complains about required fields, I guess you are aware about what to do right?
I appreciate your patients as I try and learn APEX as when I was hired I was hired to run and maintain with minor changes and am having to learn a ton of code to achieve the requested changes to the (very messy) system I inherited and as many can tell my only coding experience was with HTML a good 10-15 years ago :)
I manage to update that but realized I have filters on both the look up on the Opportunity and the lookup on the Account. How and where do I add that to the test.
Account lookup field to contact (Contact_Declining__c) filter:
Filter Criteria
Opportunity lookup field to contact (Primary_Contact__c) filter:
Filter Criteria
Its really hard to understand from what you have given.
may be a lil more detail api name,value etc.
You just have to set apt value according to the filter thats it
Field Label: Person Accepting/Declining Meeting
Object Name: Account:
Field Name: Contact_Declining
Data Type: Lookup
API Name: Contact_Declining__c
Filter Criteria: Person Accepting/Declining Meeting: Account Name IDEQUALSAccount: Account ID
Field Label: Primary Contact
Object Name: Opportunity
Field Name: Primary_Contact
Data Type: Lookup
API Name: Primary_Contact__c
Filter Criteria: Primary Contact: Account Name IDEQUALSOpportunity: Account Name ID
I thought it would be some kind of IF statement but not really sure how to write that and where exactly to put it. I'm assuming that there would be one under Account and one under Opportunity in the test.... I have looked at the boards and through the API sites and can't figure out how to do this.
So realized I missed the fields for opportunity... so I added them... struggled with how to format the date... got that... and now I can't seem to get around this error despite closedate being clearly listed and all internet searched lead to a dead in.
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [CloseDate]: [CloseDate]
o.closeDate = System.today();
o.closeDate = System.today()); = error message and won't save:
Error: Compile Error: Invalid field initializer: o.closeDate at line 31 column 4
CloseDate = System.today()); = error message when test fails:
System.DmlException: Upsert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [CloseDate]: [CloseDate]
I am starting to need one of those bang head here right on my desk sort of things.
Please repost ur code
Seems good what is the error you are getting ?
Post exact line and error
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [CloseDate]: [CloseDate]