You need to sign in to do that
Don't have an account?
sgss
Test class on account contact
Can anyone help in Test Class of following problem.? Consider all positive negative scenario.
SOQL query on Account and find all associated contact records of the Account which
contains the word 'John'. Print all Account and Contact records retrieved above
public class JohnClass {
public static void getAccountContact(){
List<Account> accountList = [SELECT
Id,
Name,
(SELECT
Id,
FirstName,
LastName
FROM
Contacts
WHERE
FirstName LIKE '%john%' OR LastName LIKE '%john%')
FROM
Account];
for(Account account : accountList) {
if(account.Contacts.isEmpty())
continue;
system.debug('Account : ' + account.Name);
for(Contact contact : account.Contacts) {
system.debug('Contact : ' + contact.FirstName + ' ' + contact.LastName);
}
}
}
}
SOQL query on Account and find all associated contact records of the Account which
contains the word 'John'. Print all Account and Contact records retrieved above
public class JohnClass {
public static void getAccountContact(){
List<Account> accountList = [SELECT
Id,
Name,
(SELECT
Id,
FirstName,
LastName
FROM
Contacts
WHERE
FirstName LIKE '%john%' OR LastName LIKE '%john%')
FROM
Account];
for(Account account : accountList) {
if(account.Contacts.isEmpty())
continue;
system.debug('Account : ' + account.Name);
for(Contact contact : account.Contacts) {
system.debug('Contact : ' + contact.FirstName + ' ' + contact.LastName);
}
}
}
}
Plz try this test class: Let me know if it works for you, and mark your ans.
Thanks
Niraj
Its good to know that it works for you.
Below is the test class considering the negative and positive scenario.
Hope this solution helps.
Thank You
Ajay Dubedi