You need to sign in to do that
Don't have an account?
Sana123
I am new to salesforce . How can i write test classes for this code. Can someone please help me
public class SOQLquery {
public static void searchForAccount (){
List<Account> acctOfList = [SELECT Name,Website,Offer__c FROM Account ] ;
System.debug(acctOfList);
List<Account> acctOfList1 = [SELECT Name,Website,Offer__c FROM Account WHERE Name = 'Test' OR Name ='Testing'] ;
System.debug(acctOfList1);
List<Account> notAccts = [SELECT Name,Website,Offer__c FROM Account WHERE (Name != 'Test' OR Name !='Testing') AND Website != Null ] ;
System.debug(notAccts);
}
/**
*
* @description : Description of the childToParentSOQL
*
* @args :
*
* @return : void
*
* @revision Log : V1.0 - Created - 2021/06/22 - Anjana Sharma
*
*
**/
public static void childToParentSOQL(){
List<Contact> objContact =[SELECT Id, FirstName , LastName, Email,Phone, Account.Id, Account.Name , Account.Website FROM Contact] ;
System.debug(objContact);
List<Contact> objContacts =[SELECT Id, FirstName , LastName, Email,Phone, Account.Id, Account.Name , Account.Website FROM Contact WHERE Email != Null OR Phone != Null] ;
System.debug(objContacts);
List<Contact> listOfAccount =[SELECT Id, FirstName , LastName, Email,Phone, Account.Id, Account.Name , Account.Website FROM Contact WHERE Account.Id != Null OR Account.Name != 'Test'] ;
System.debug(listOfAccount);
List<Contact> listOfAccount1 =[SELECT Id, FirstName , LastName, Email,Phone, Account.Id, Account.Name , Account.Website FROM Contact WHERE LastName != Null OR Account.Name != 'Testing'] ;
System.debug(listOfAccount1);
}
public static void parentToChildSOQL(){
List<Account> accountList =[SELECT Id,Name, (SELECT Id, Name FROM Account_Contact_Childs__r) FROM Account];
for(Account account : accountList){
System.debug(account);
}
List<Contact> contactList =[SELECT Id, (SELECT Id, Name FROM Account_Contact_Childs__r) FROM Contact];
for(Contact contact : contactList){
System.debug(contact);
}
}
}
public static Map<Id, List<Contact>> getContactInformationUsingInlineSOQL(){
Map<Id, List<Contact>> contactMap = new Map<Id, List<Contact>>();
List<Account> lstContact =[SELECT Id ,(SELECT Name FROM Contacts) FROM Account];
for(Account objContact : lstContact ){
contactMap.put(objContact.id, objContact.Contacts);
System.debug(contactMap);
}
return contactMap;
}
public static Map<Id, List<Contact>> getContactInformationUsingSOQL(){
List<Account> lstAccount =[SELECT Id FROM Account ];
List<Contact> lstContact =[SELECT Id , Name FROM Contact WHERE AccountID IN :lstAccount];
Map<Id, List<Contact>> contactMap = new Map<Id, List<Contact>>();
for(Contact objContact : lstContact ){
contactMap.put(objContact.Id, new List<Contact>{objContact});
System.debug(contactMap);
}
return contactMap;
}
public static Map<Id, List<Contact>> getContactInformationForSpecificAccount(List<Account> acct){
List<Account> lstOfAccount = [SELECT Name FROM Account WHERE ID IN:acct];
List<Contact> lstOfContact = [SELECT Name FROM Contact WHERE AccountID IN :lstOfAccount];
Map<Id, List<Contact>> contactMap1 = new Map<Id, List<Contact>>();
for(Contact objContact : lstOfContact ){
contactMap1.put(objContact.ID, new List<Contact>{objContact});
System.debug(contactMap1);
}
return contactMap1;
}
public static void searchForAccount (){
List<Account> acctOfList = [SELECT Name,Website,Offer__c FROM Account ] ;
System.debug(acctOfList);
List<Account> acctOfList1 = [SELECT Name,Website,Offer__c FROM Account WHERE Name = 'Test' OR Name ='Testing'] ;
System.debug(acctOfList1);
List<Account> notAccts = [SELECT Name,Website,Offer__c FROM Account WHERE (Name != 'Test' OR Name !='Testing') AND Website != Null ] ;
System.debug(notAccts);
}
/**
*
* @description : Description of the childToParentSOQL
*
* @args :
*
* @return : void
*
* @revision Log : V1.0 - Created - 2021/06/22 - Anjana Sharma
*
*
**/
public static void childToParentSOQL(){
List<Contact> objContact =[SELECT Id, FirstName , LastName, Email,Phone, Account.Id, Account.Name , Account.Website FROM Contact] ;
System.debug(objContact);
List<Contact> objContacts =[SELECT Id, FirstName , LastName, Email,Phone, Account.Id, Account.Name , Account.Website FROM Contact WHERE Email != Null OR Phone != Null] ;
System.debug(objContacts);
List<Contact> listOfAccount =[SELECT Id, FirstName , LastName, Email,Phone, Account.Id, Account.Name , Account.Website FROM Contact WHERE Account.Id != Null OR Account.Name != 'Test'] ;
System.debug(listOfAccount);
List<Contact> listOfAccount1 =[SELECT Id, FirstName , LastName, Email,Phone, Account.Id, Account.Name , Account.Website FROM Contact WHERE LastName != Null OR Account.Name != 'Testing'] ;
System.debug(listOfAccount1);
}
public static void parentToChildSOQL(){
List<Account> accountList =[SELECT Id,Name, (SELECT Id, Name FROM Account_Contact_Childs__r) FROM Account];
for(Account account : accountList){
System.debug(account);
}
List<Contact> contactList =[SELECT Id, (SELECT Id, Name FROM Account_Contact_Childs__r) FROM Contact];
for(Contact contact : contactList){
System.debug(contact);
}
}
}
public static Map<Id, List<Contact>> getContactInformationUsingInlineSOQL(){
Map<Id, List<Contact>> contactMap = new Map<Id, List<Contact>>();
List<Account> lstContact =[SELECT Id ,(SELECT Name FROM Contacts) FROM Account];
for(Account objContact : lstContact ){
contactMap.put(objContact.id, objContact.Contacts);
System.debug(contactMap);
}
return contactMap;
}
public static Map<Id, List<Contact>> getContactInformationUsingSOQL(){
List<Account> lstAccount =[SELECT Id FROM Account ];
List<Contact> lstContact =[SELECT Id , Name FROM Contact WHERE AccountID IN :lstAccount];
Map<Id, List<Contact>> contactMap = new Map<Id, List<Contact>>();
for(Contact objContact : lstContact ){
contactMap.put(objContact.Id, new List<Contact>{objContact});
System.debug(contactMap);
}
return contactMap;
}
public static Map<Id, List<Contact>> getContactInformationForSpecificAccount(List<Account> acct){
List<Account> lstOfAccount = [SELECT Name FROM Account WHERE ID IN:acct];
List<Contact> lstOfContact = [SELECT Name FROM Contact WHERE AccountID IN :lstOfAccount];
Map<Id, List<Contact>> contactMap1 = new Map<Id, List<Contact>>();
for(Contact objContact : lstOfContact ){
contactMap1.put(objContact.ID, new List<Contact>{objContact});
System.debug(contactMap1);
}
return contactMap1;
}
Hi Anu,
Try this code:
Please Mark it as Best Answer if it helps.
Thanks
All Answers
Try Below Test Class
Made Small Change In Your Class
Which Is In Bold And Underlined Please Mark it As Best Answer If It Helps
Thank You!
Hi Anu,
Try this code:
Please Mark it as Best Answer if it helps.
Thanks