Skip to main content Join us at TDX in San Francisco or on Salesforce+ on March 5-6 for the Developer Conference for the AI Agent Era. Register now.

#Trailhead Challenges2,393 discussing

Hands-on challenges are the “secret sauce” of Trailhead. Before searching for solutions to superbadge challenges, review the Salesforce Certification Program Agreement and Policies.

Hello I am currently working on a side project to practice SOQL Query. My task was to Write a class to insert 3 contacts with account Id = Id of Dickenson Plc. I have spend hours looking over my code and I don't know what I am doing wrong. The code runs but when I go in my salesforce no contacts have been inserted. Can someone please help me? Also as stated before i had to query the account id that I wanted which was account that is already in salesforce but the contacts accountid should all be related to the same id.

Screenshot 2024-12-27 at 5.10.40 PM.png

 

#Trailhead Challenges

4 answers
  1. Dec 27, 2024, 11:31 PM

    Hi @Alexis Williams ,

     

    Try this

     

    Public class ContactInsertion {

    public static void insert Contact(){

    List<Contact> addContact = new List<Contact>();

    Integer i =1;

    List<Account> accList =[select Id From Account where Name ='Dickenson plic'];

    for (i=1;i<=3;i++){

    Contact newCon = new Contact();

    newCon.FirstName = 'Lisa' + i;

    newCon.LastName = 'Doe' + i;

    newCon.AccountId = accList[0].Id;

    addContact.add(newCon);

    }

    insert addContact;

    }

    }

0/9000

I copy and pasted a few times straight from the lesson, but keep getting this Field_Integrity_Exception message on a failed save.

I am new to writing SOQL and SQL, so some guidance would be much appreciated.

 

https://trailhead.salesforce.com/content/learn/projects/transform-sql-queries-to-soql-queries-in-a-lightning-app/display-books-with-their-authors

Screenshot 2024-08-19 at 4.30.16 PM.png

 

#Trailhead Challenges

0/9000

Kindly assist in this challenge. I have executed the ContactAndLeadSearch Class code successfully without errors  but encountered an error when Checking the Challenge though my debug window showed a successful compilation.

 

The problem and my debug window is shown below: 

 

Create an Apex class that returns both contacts and leads based on a parameter.

To pass this challenge, create an Apex class that returns both contacts and leads that have first or last name matching the incoming parameter.

  • The Apex class must be called ContactAndLeadSearch and be in the public scope
  • The Apex class must have a public static method called searchContactsAndLeads
    • The method must accept an incoming string as a parameter
    • The method should then find any contact or lead that matches the string as part of either the first or last name
    • The method should finally use a return type of List<List< sObject>>
  • NOTE: Because SOSL indexes data for searching, you must create a Contact record and Lead record before checking this challenge. Both records must have the last name Smith. The challenge uses these records for the SOSL search

 

ContactAndLeadSearch Error.PNG

0/9000