• smammadov2017
  • NEWBIE
  • 0 Points
  • Member since 2020


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi there!

I was hoping to get a helping hand on the following error: "System.AssertException: Assertion Failed: Expected: 1, Actual 0"

I would appreciate if you could help and explain how you got there, I'm still learning.

My Apex Class:
public with sharing class AccountSearchController {
    @AuraEnabled
    public static List<Account> searchAccounts( String searchTerm ) {
        List<Account> accounts = new List<Account>();
        if ( String.isNotBlank( searchTerm ) 	&& searchTerm.length() > 1 ) {
            List<List<SObject>> searchResults = [
                FIND :searchTerm
                RETURNING Account(
                    Id, Name, Phone, Website,
                    BillingStreet, BillingCity,
                    BillingState, BillingPostalCode
                    ORDER BY Name
                    LIMIT 10
                )
            ];
            accounts = searchResults[0];
        }
        return accounts;
    }
}

My Apex Test Class:
 
@isTest
private class AccountSearchControllerTest {

@isTest static void accList(){

            Account acc = new Account();  
	        acc.Phone = '6475553314';  
	        acc.Name  = 'Account Name New';  
	        acc.Website = 'mywebpage.com';  
	        acc.BillingStreet    = '999 Bloor Street East';  
            acc.BillingCity    = 'Toronto';  
            acc.BillingState    = 'Ontario';  
            acc.BillingPostalCode    = 'M4S3B9';  
	        insert acc;  

    Test.startTest();

    List<Account> accs = AccountSearchController.searchAccounts('Account Name New');
    System.assertEquals(1, accs.size());
    System.assertEquals('Account Name New', accs[0].Name);       

    Account a2=[Select Id, Name, Phone, Website, BillingStreet, BillingCity, BillingState, BillingPostalCode From Account Where Name='Account Name New' LIMIT 1];

    System.assert(a2!=null); 

    Test.stopTest();           
  }    
}
Thank you
/*Write a trigger that creates two identical Contacts whenever an Account is created. Make sure both Contacts are associated with the Account. Use any values for the fields on the Contacts - just make sure to use variables when populating the fields of each Contact to make sure they are identical.*/

I am not able to associate contacts with Account , this is my code

trigger IdenticalContact on Account (before insert) {          for (Account a : trigger.new)     {         List<contact> cont = new List<contact> ();         for (integer i=0 ; i<2; i++)         {             contact newContact            = new contact();             newContact.AccountId          = a.id;             newContact.LastName           = 'kritpa';             newContact.FirstName          = 'ptName';             cont.add(newContact);         }      insert cont;     }