+ Start a Discussion
Pramodh KumarPramodh Kumar 

Not recognizing the Namespace in the trailhead challanges

I completed the challenge Asynchronous Apex Using Future Methods trailhead but it is not recognizing the fields I created because of the namespace. If anyone has the same issue and resolved this problem, please suggest me what to do with this scenario.



Thanks
Pramodh
Best Answer chosen by Pramodh Kumar
SandhyaSandhya (Salesforce Developers) 
Hi Pramodh,

I do not think having a namespace, fields are not recognized as I have namespace enabled(i.e., lightning) in my org and can clear the challenge.

Please recheck the names of the fields you have created.

Below is the code for your reference.
 
public class AccountProcessor 
{
  @future
  public static void countContacts(Set<id> setId) 
  {
      List<Account> lstAccount = [select id,Number_of_Contacts__c , (select id from contacts ) from account where id in :setId ];
      for( Account acc : lstAccount )
      {
          List<Contact> lstCont = acc.contacts ;
          
          acc.Number_of_Contacts__c = lstCont.size();
      }
      update lstAccount;
  }
}
 
@IsTest
public class AccountProcessorTest {
    public static testmethod void TestAccountProcessorTest() 
    {
        Account a = new Account();
        a.Name = 'Test Account';
        Insert a;

        Contact cont = New Contact();
        cont.FirstName ='Bob';
        cont.LastName ='Masters';
        cont.AccountId = a.Id;
        Insert cont;
        
        set<Id> setAccId = new Set<ID>();
        setAccId.add(a.id);
 
        Test.startTest();
            AccountProcessor.countContacts(setAccId);
        Test.stopTest();
        
        Account ACC = [select Number_of_Contacts__c from Account where id = :a.id LIMIT 1];
        System.assertEquals ( Integer.valueOf(ACC.Number_of_Contacts__c) ,1);
  }
  
}
Moreover, also you can try doing this challenge in new trailhead playground.

Hope this helps you! If you need further help, please post the error you are facing.

If this helps you, please mark it as solved.

Thanks and Regards
Sandhya

 

All Answers

SandhyaSandhya (Salesforce Developers) 
Hi Pramodh,

I do not think having a namespace, fields are not recognized as I have namespace enabled(i.e., lightning) in my org and can clear the challenge.

Please recheck the names of the fields you have created.

Below is the code for your reference.
 
public class AccountProcessor 
{
  @future
  public static void countContacts(Set<id> setId) 
  {
      List<Account> lstAccount = [select id,Number_of_Contacts__c , (select id from contacts ) from account where id in :setId ];
      for( Account acc : lstAccount )
      {
          List<Contact> lstCont = acc.contacts ;
          
          acc.Number_of_Contacts__c = lstCont.size();
      }
      update lstAccount;
  }
}
 
@IsTest
public class AccountProcessorTest {
    public static testmethod void TestAccountProcessorTest() 
    {
        Account a = new Account();
        a.Name = 'Test Account';
        Insert a;

        Contact cont = New Contact();
        cont.FirstName ='Bob';
        cont.LastName ='Masters';
        cont.AccountId = a.Id;
        Insert cont;
        
        set<Id> setAccId = new Set<ID>();
        setAccId.add(a.id);
 
        Test.startTest();
            AccountProcessor.countContacts(setAccId);
        Test.stopTest();
        
        Account ACC = [select Number_of_Contacts__c from Account where id = :a.id LIMIT 1];
        System.assertEquals ( Integer.valueOf(ACC.Number_of_Contacts__c) ,1);
  }
  
}
Moreover, also you can try doing this challenge in new trailhead playground.

Hope this helps you! If you need further help, please post the error you are facing.

If this helps you, please mark it as solved.

Thanks and Regards
Sandhya

 
This was selected as the best answer
Pramodh KumarPramodh Kumar
thanks for the reply I used different org and finished the challenge.