I have an apex class, which is the first block of code below.

I'm trying to have a test class create the lead, and use the leadrotator class, but I keep getting the "Save error: Method does not exist or incorrect signature: leadrotator.rotateLead(SOBJECT:Lead)"

Any thoughts?

global class leadRotator{

    //General Process
    //1--Person pushes Lead Rotator Button
    //2--Needed from Lead: Territory, lead object/ID
    //3--Query all Lead Rotator Users in the territory of the lead taking Outside rep flag into consideration 
    //4--Pull in the user/id and lead rotator user id of the rep with the lowest leads rotated to them since the last time it was cleared
    //5--Create entry into Rotated Leads table using current user for "rotated by", user from comment 4 for "rotated to",
    //6--using lead from comment 2 for the lead reference, rotated date = today()
    //7--Increment the Leads_Rotated_since_last_clear__c field on the lead rotator user found in comment 4
    //8--Assign the lead to the rep identified in comment 4

    webservice static string rotateLead(list<id> leadsToRotate){
        //declare variables
        string strTerritoryFromLead;
        string strLeadRotatorUser;
        lead leadFromID;
        boolean boolOutsideRepFromLead;
        string strUserName = Userinfo.getFirstName() + ' ' + userinfo.getLastName();
        Lead_Rotator_Users__c LeadRotatorUser;
        list<Rotated_Lead__c> NewRotatedLeads = new list<Rotated_Lead__c>();
        list<lead> LeadsToUpdate = new list<lead>();
        string returnString;
        lead[] leads = [
            select id, Territory__c, F1000_Headquarters_lead__c
            from lead
            where ID in :leadsToRotate

        //loop through the leads in the list returned by the method
        for (lead l : leads){ 

            //Take ID from page, and assign to a lead variable
            //leadFromID = [select ID,Territory__c,F1000_Headquarters_lead__c from lead where id=:l];

            //assign varables values from the lead
            strTerritoryFromLead = l.Territory__c;

                returnString = 'Error in processing some of the leads, please check the address for State and zip.'; 

            boolOutsideRepFromLead = l.F1000_Headquarters_lead__c;

            system.debug('territory variable: '+ strTerritoryFromLead); 
            system.debug('f1000 flag on lead: ' + boolOutsideRepFromLead); 
            system.debug('lead ID: ' + l.id); 
            system.debug('strUserName: ' + strUserName);

            LeadRotatorUser = 
            //Query to determine next person to rotate to
            SELECT Id,Name,Outside_Rep__c,Territory__c, Leads_Rotated_since_last_clear__c,Rep_Name__c FROM Lead_Rotator_Users__c 
            WHERE Outside_Rep__c = :boolOutsideRepFromLead AND Territory__c = :strTerritoryFromLead 
            ORDER BY Leads_Rotated_since_last_clear__c ASC NULLS FIRST LIMIT 1

            Rotated_Lead__c rl = new Rotated_Lead__c(
                Lead__c =l.id, 
                Lead_Rotated_by__c = strUserName, 
                Rep_Rotated_To_ID__c = LeadRotatorUser.id
                );//Create lead to insert into the Rotated Lead Table
            system.debug('RL = ' + rl);

            //insert rl;//insert to the rotated lead table

            if(Leadrotatoruser.Leads_Rotated_since_last_clear__c == null){
            Leadrotatoruser.Leads_Rotated_since_last_clear__c = 1;  
            Leadrotatoruser.Leads_Rotated_since_last_clear__c ++; //increment the counter on the lead rotator user
            update LeadRotatorUser; //update the lead rotator user

            l.ownerID = LeadRotatorUser.Rep_Name__c;
            l.Lead_Rotator_Used__c = true;


        }//end loop through leads in the list returned by the method
            update leadsToUpdate;
            insert NewRotatedLeads; 
        } catch (dmlException e){
            system.debug('Error: ' + e);


        if (string.isblank(returnString)){
        return 'success';
            return returnString;
    }//rotateLead Method end

    webservice static string clearLeadRotatorUsers(list<id> ids){
        list<Lead_Rotator_users__c> usersToUpdate = new list<Lead_Rotator_users__c>();

         Lead_Rotator_users__c[] usersToClear = [
            select id, Leads_Rotated_since_last_clear__c
            from Lead_Rotator_users__c
            where ID in :ids

        for(Lead_Rotator_users__c u : usersToClear){
        u.Leads_Rotated_since_last_clear__c = 0;
        u.last_clear_date__c = system.now();
            update usersToUpdate;
            return 'success';

        }catch (dmlException e){
            return 'e';


} //End Class

And here is my test Class:

private class LeadRotatorTestClass {

    static testMethod void myUnitTest() {

       lead l = new lead(LastName='Jack Skellington',Email='test@test.com', company='Test Co.', Phone='5555555555', status='Open', Leadsource='Inbound Call', State='OR');
       System.debug('Owner ' + l.Ownerid);

       // Insert lead
       insert l;

       // set to reassign
       l = [SELECT ownerid FROM Lead WHERE Id =:l.Id];

      //lead_rotator__c lr = new lead_rotator__c();
       string result;
       //update lead
       result = leadrotator.rotateLead(l);

       System.debug('Owner after trigger fired' + l.ownerid);
       system.debug('Result = ' + result);


You're passing in a lead into the web service, but the method is expecting a type of List Id - so you need to pass that in for the test to work.

So you can just do something like:

List<Id> webIds = new List<Id> ();
result = leadrotator.rotateLead(webIds);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.