• Rajesh Dhawan
  • 45 Points
  • Member since 2014
  • Lead Consultant
  • HCL

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 4
Hi all, 

I have a problem with this challenge :

Create a Queueable Apex class that inserts the same Contact for each Account for a specific state. Write unit tests that achieve 100% code coverage for the class.
Create an Apex class called 'AddPrimaryContact' that implements the Queueable interface.
Create a constructor for the class that accepts as its first argument a Contact sObject and a second argument as a string for the State abbreviation.
The execute method must query for a maximum of 200 Accounts with the BillingState specified by the State abbreviation passed into the constructor and insert the Contact sObject record associated to each Account. Look at the sObject clone() method.
Create an Apex test class called 'AddPrimaryContactTest'.
In the test class, insert 50 Account records for BillingState "NY" and 50 Account records for BillingState "CA". Create an instance of the AddPrimaryContact class, enqueue the job and assert that a Contact record was inserted for each of the 50 Accounts with the BillingState of "CA".
The unit tests must cover all lines of code included in the AddPrimaryContact class, resulting in 100% code coverage.
Run your test class at least once (via 'Run All' tests the Developer Console) before attempting to verify this challenge.

I haven't 100% for my test class. 
 public class AddPrimaryContactTest {
     @isTest static void TestList(){
         List<Account> Teste = new List <Account>();
         for(Integer i=0;i<50;i++){
             Teste.add(new Account(BillingState = 'CA', name = 'Test'+i));
             for(Integer j=0;j<50;j++){
             Teste.add(new Account(BillingState = 'NY', name = 'Test'+j));
         insert Teste;
         Contact co = new Contact();
          String state = 'CA';
     AddPrimaryContact apc = new AddPrimaryContact(co, state);
         for (Account t:Teste){
             if( t.BillingState == 'CA'){
             	System.assertEquals(1, t.Number_of_contacts__c);
public class AddPrimaryContact implements Queueable{
    private Contact c;
    private String state;
    public  AddPrimaryContact(Contact c, String state){
        this.c = c;
        this.state = state;
     public void execute(QueueableContext context) {
        List<Account> ListAccount = [SELECT ID, Name FROM ACCOUNT WHERE BillingState = :state LIMIT 200];
         for (Account l:ListAccount){
             for (Contact co:l.Contacts){
                 c = co.clone(false,false,false,false);
                 insert c;


Anyone can help me please?
Web service callout failed: Unable to parse callout response. Apex type not found for element Name
I am getting the above error when i tries the query() SOAP API Function
partnerSoapSforceCom.soap con = new partnerSoapSforceCom.soap();
con .SessionHeader = new partnerSoapSforceCom.SessionHeader_element ();
partnerSoapSforceCom.loginResult  loginResult = new partnerSoapSforceCom.loginResult();
loginResult =con.login('********************','*****************************');
con.endpoint_x =loginResult.ServerUrl;
con.Sessionheader.sessionid = loginResult.sessionid;
partnerSoapSforceCom.queryResult qr = new partnerSoapSforceCom.queryResult ();
qr=con.queryAll('SELECT Id,Name FROM Contact Limit 1');

if query is with ID only its not throwing the error.I tried the same from SoapUI.It works fine.
Error:EXCEPTION: System.CalloutException: Web service callout failed: Unable to parse callout response. Apex type not found for element Name
  • July 14, 2014
  • Like
  • 0



I am new to Apex development and looking for some help with a simple trigger to delete erroneous opportunities created by an automated process.


Basically, we want to delete any opportunity that is created where the opportunity name = "..."


Thanks for any assistance!

  • March 09, 2012
  • Like
  • 0

List<Group> leadQueueRec = [Select Id, Name from Group where Name = 'LeadQueue'];
List<Lead>    leadRec = [Select Id, Name, OwnerId from Lead where Name='James'];
if(leadRec.size() > 0){
    leadrec[0].OwnerId = leadQueueRec[0].Id;
    update leadrec[0];


Above snippet of code I am able to run throgh System Log successfully.

But when I am writing same code in one actionFuction It is giving the Exception

DML currently not allowed
System.Exception: DML currently not allowed


So I am not getting the reason for this? Does anybody come across same error and knows what is the solution to handle this?