0

I'm working on Salesforce Apex web service to create record. Below is the apex web service class that I have written:

global class createCloudRecord {

    global class projectInputs{
        webService Integer ProjectID;
        webService String ProjectName;
    }

    webService static Boolean createSFRecords(List<projectInputs> inputs) {

        cv__Designation__c desg = new cv__Designation__c();
        desg.cv__Active__c = true;
        desg.cv__Default__c = false;
        desg.cv__Description__c = 'Test Desc';
        desg.OwnerId = '002B0000000K9soIAD';
        desg.Name = inputs[0].ProjectName;
        desg.cv__ExternalId__c = string.valueof(inputs[0].ProjectID);

        insert desg;

        return true;
    }
}

It's working fine and creating records on SF cloud via SOAP API call. Now I have to written the test class for above web service with code coverage of min 75%.

Below is the code that I have written for my test class:

@isTest 
private class createCloudRecordTest {

    static testMethod void testCreateSFRecords() {
         createCloudRecord.projectInputs project = new createCloudRecord.projectInputs();
         project.ProjectID = 12345;
         project.ProjectName = 'TestProject';


        createCloudRecord.createSFRecords(project);
    }
}

But this is showing an error for this line createCloudRecord.createSFRecords(project);:

Error: Compile Error: Method does not exist or incorrect signature. Anyone has any idea how can I make this working.

Thanks!

2
  • 1
    Can you please share code of createDesignationCampaign class
    – Peeyush
    Commented Jan 19, 2016 at 9:34
  • Updated my question that's a typo. Commented Jan 19, 2016 at 9:35

1 Answer 1

1

In your web service method you are passing list as the parameter where as in your test class it is just a single record:

@isTest 
private class createCloudRecordTest {

    static testMethod void testCreateSFRecords() {
         createCloudRecord.projectInputs project = new createCloudRecord.projectInputs();
         project.ProjectID = 12345;
         project.ProjectName = 'TestProject';
         list<createCloudRecord.projectInputs> projects = new list<createCloudRecord.projectInputs>();
         projects.add(project);

        createCloudRecord.createSFRecords(projects);
    }
}
3
  • Hmm. Let me try this and get back to you! Commented Jan 19, 2016 at 9:40
  • Thank you so much @Nitin. It's working fine now and I got 100% code coverage. Have a great day! Commented Jan 19, 2016 at 9:46
  • Happy to help :)
    – Nitin
    Commented Jan 19, 2016 at 9:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .