+ Start a Discussion
Guillaume MéheustGuillaume Méheust 

'Using Future Methods'  Trailhead Issue

Hello,

When I'm trying to Check Challenge, I receive this king of message : "The 'Number_Of_Contacts__c' field does not exist on the Account object."

I've double/triple checked if this field was present and ... it is.
I don't understand since all the test are goods.

Could you help me with this issue ?

Regards,
Best Answer chosen by Guillaume Méheust
Mahesh DMahesh D
Please consider below points:

==> check the permissions / FLS for that field.
==> Check the API Name 

Regards,
Mahesh

All Answers

Mahesh DMahesh D
Please consider below points:

==> check the permissions / FLS for that field.
==> Check the API Name 

Regards,
Mahesh
This was selected as the best answer
SAHG-SFDCSAHG-SFDC
global 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;
}
}

HI Use this code
SAHG-SFDCSAHG-SFDC
Make sure that the new field has __c Appended and its named right as per the challenge requirement
Conor DowneyConor Downey
Hi,

Can you tell me why its SELECT Id FROM Contacts? What is Contacts? The table is Contact so why is Cotnacts used here?
Mahesh DMahesh D
Hi Conor,

Its a Child Relationship and look into the below links:

Relationship Queries:
 
If Job_Application__c is the child Object and Review__c is the parent object then
List<Job_Application__c> jaList = [Select Id, Name, Review__c, Review__r.Name from Job_Application__c];

If Review__c is the child Object and Job_Application__c is the parent object then
List<Review__c> rList = [Select Id, Name, Job_Application__c, Job_Application__r.Name from Review__c];

Also look into the below links for more information about Relationship Queries:

https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_understanding.htm

https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships.htm

https://developer.salesforce.com/page/A_Deeper_look_at_SOQL_and_Relationship_Queries_on_Force.com

https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_lookup.htm

https://developer.salesforce.com/blogs/developer-relations/2013/05/basic-soql-relationship-queries.html


Please do let me know if it helps you.

Regards,
Mahesh

 
Kellan ScheiberKellan Scheiber
I am getting the same error message and I have updated all field level securities and am still getting the same message. Not sure what else to do. Have renamed numerous times both API and UI and still no luck
SOHAN SINGHSOHAN SINGH
Hi Kellan,

If you have namespace created on your org, you'll see this error even if you've setup this field correctly.

In order to resolve this you can setup a trailhead hands on org, as you can not delete the namespace in your org and then associate it with your trailhead account to complete this trailhead module.

Here is how you can check if you've namespace setup on your developer org:

1. Click on setup >> search for packages in quick find >> click on package and you'll see namespace information if set or it'll show none.
2. Create a new developer org >> now from your existing trailhead account >> click on manage my hands on org >> click on connect to an org and verify your new developer org.
3. Once verfied click on check challenge

You shoule be able to complete it.

Thanks
Ashok Kumar NayakAshok Kumar Nayak

Look for this 
User-added image
And select the org in which you developed your code.

Sample Class:-

Public class AccountProcessor {
  @future
  public static void countContacts(List<Id> recordIds) {
    List<Account> accounts = [Select Id,Name,(select Id from Contacts) from Account Where Id IN :recordIds];
    for(Account a : accounts)
    {
      a.Number_Of_Contacts__c=a.Contacts.size();
    }
    update accounts;
  }
}

Test Class:-
@isTest
private class AccountProcessorTest {

@IsTest static void countContactsTest() {
Test.startTest();
Account a = new Account(Name='ABCD');
insert a;
List<Id> AcId = new List<Id>();
Contact c = new Contact(LastName='ABCD',AccountId=a.Id);
insert c;
for(Account acc : [select id from Account where id=:a.Id])
{
    AcId.add(acc.id);
}
AccountProcessor.countContacts(AcId);
Test.stopTest();
}

}

MouSMouS
You should enter "Number_Of_Contacts" to Field Label
※“Number_Of_Contacts__c” is wrong