function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
James Roberts 32James Roberts 32 

Method does not exist or incorrect signature: void put(String, Id) from the type Map<Id,Task>

I received this error when trying to create a Test Class for testing my Apex Controller that is part of a Lightning component described here:

https://developer.salesforce.com/docs/atlas.en-us.salesforce_vpm_guide.meta/salesforce_vpm_guide/vpm_admin_pause_cmp_record.htm

Here is my Test Class:

@isTest
public class Test_interviewsbyRecord 
{
    public TestMethod static void TestTask()
    {
        Task t = new Task();
        t.subject = 'ApexTest';
        t.ActivityDate= date.today();
        t.Status = 'Open';
        t.OwnerId = '00561000001r8ztAAA';
        insert t;
        
        List <Task> ls = [Select Id from Task where Subject = 'ApexTest'];
        
           Map <id, Task> inputs = new Map<id, Task>();
        inputs.put('TaskID',t.Id);
            
        Flow.Interview.Activity_Escalation_Flow myFlow = new Flow.Interview.Activity_Escalation_Flow(inputs);
        myFlow.start();
       
    }


The test class is created a new task and then initiating the Flow (Activity_Escalation_Flow) that is running on my Tasks. The only Variable needed for the Flow is that Task ID, which is contained in the Variable !TaskID. I don't seem to be mapping it correctly to the Input.
Best Answer chosen by James Roberts 32
Yogeshwar TailorYogeshwar Tailor
Hi James,

Please use the  below code with 100% Coverage and pass.
 
@isTest(SeeAllData=true)
public class Test_interviewsbyRecord 
{
    public TestMethod static void TestTask()
    {
        Task t = new Task();
        t.subject = 'ApexTest';
        t.ActivityDate= date.today();
        t.Status = 'Open';
        t.OwnerId = UserInfo.getUserId();
        insert t;
        
        List <Task> ls = [Select Id from Task where Subject = 'ApexTest'];
        
        Map <id, Object> inputs = new Map<id, Object>();
        inputs.put(t.id,t);
        
        Flow.Interview.Activity_Escalation_Flow myFlow = new Flow.Interview.Activity_Escalation_Flow(inputs);               myFlow.start();

        FlowInterview interview = [Select Id from FlowInterview limit 1];
        
        interviewsByRecordController.getInterviews(t.id);
        interviewsByRecordController.deleteInterview(interview.id);
       
    }
}

Before that i have paused the flow. Check the highlight content in code which i have change.

below url might be helpful for you.

https://developer.salesforce.com/docs/atlas.en-us.salesforce_vpm_guide.meta/salesforce_vpm_guide/vpm_admin_pause.htm

Let me know if you get any other issues in that.

Best,
Yogesh

All Answers

Yogeshwar TailorYogeshwar Tailor
Hi James,

Use like below..

Map <id, Task> inputs = new Map<id, Task>();
inputs.put(t.id,t);


Or 

 Map <String, Task> inputs = new Map<String, Task>();
 inputs.put('TaskID',t);


In your code you are assigning 'TaskID' string which should be id according to your map.

Let me know if you get the any issue still.

Thanks,
Yogesh
James Roberts 32James Roberts 32
Thanks Yogesh, test class now saves, but it doesn't give me code coverage of my Apex Controller:

public class interviewsByRecordController {

    @AuraEnabled
    public static List<FlowRecordRelation> getInterviews(Id recordId) {
        return [ SELECT 
                    ParentId, Parent.InterviewLabel, Parent.PauseLabel, 
                    Parent.CurrentElement, Parent.CreatedDate, Parent.Owner.Name 
                FROM FlowRecordRelation 
                WHERE RelatedRecordId = :recordId ];
    }

    @AuraEnabled
    public static FlowInterview deleteInterview(Id interviewId) {
        FlowInterview interview = [Select Id from FlowInterview Where Id = :interviewId];
        delete interview;
        return interview;
    }
}
Yogeshwar TailorYogeshwar Tailor

Hi James,

Write these in your test class.

  interviewsByRecordController.getInterviews(t.id);
  interviewsByRecordController.deleteInterview('pass your interview id here');


Let me know if you get any problem.

Best,
Yogesh
James Roberts 32James Roberts 32
Thanks Yogesh - I get this error when running the test class:

System.FlowException: This error occurred when the flow tried to look up records: 
Subject, Id FROM Task WHERE ((Id = '{Subject=ApexTest, ActivityDate=2019-02-13
                              ^
ERROR at Row:1:Column:213
invalid ID field: {Subject=ApexTest, ActivityDate=2019-02-13 00:00:00, Status=Open, OwnerId=00561000001r8ztAAA, Id=00Tq000000VNJIQEA5}. You can look up ExceptionCode values in the <a href='https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_concepts_core_data_objects.htm#'>SOAP API Developer Guide .

Here is the test class in full. 

@isTest
public class Test_interviewsbyRecord 
{
    public TestMethod static void TestTask()
    {
        Task t = new Task();
        t.subject = 'ApexTest';
        t.ActivityDate= date.today();
        t.Status = 'Open';
        t.OwnerId = '00561000001r8ztAAA';
        insert t;
        
        List <Task> ls = [Select Id from Task where Subject = 'ApexTest'];
        
         Map <String, Task> inputs = new Map<String, Task>();
         inputs.put('TaskID',t);

        Flow.Interview.Activity_Escalation_Flow myFlow = new Flow.Interview.Activity_Escalation_Flow(inputs);
        myFlow.start();
        
        interviewsByRecordController.getInterviews(t.id);
        interviewsByRecordController.deleteInterview('myFlow');

    }
}
Yogeshwar TailorYogeshwar Tailor
Hi James,

I tried below code it it was giving 71% coverage with pass
 
@isTest
public class Test_interviewsbyRecord 
{
    public TestMethod static void TestTask()
    {
        Task t = new Task();
        t.subject = 'ApexTest';
        t.ActivityDate= date.today();
        t.Status = 'Open';
        t.OwnerId = UserInfo.getUserId();
        insert t;
        
        List <Task> ls = [Select Id from Task where Subject = 'ApexTest'];
        
        Map <id, Object> inputs = new Map<id, Object>();
        inputs.put(t.id,t);
        
        Flow.Interview.Activity_Escalation_Flow myFlow = new Flow.Interview.Activity_Escalation_Flow(inputs);
        myFlow.start();
       
        interviewsByRecordController.getInterviews(t.id);
        //interviewsByRecordController.deleteInterview('Pass your paused flow id'); //pass here your paused flow id
       
    }

  in your above code you have passed the string myFlow in method  interviewsByRecordController.deleteInterview('myFlow');  

  
instead of myFlow you have to pass the paused flow id.

  let me know if you get any other problem.

Best,
Yogesh

 
James Roberts 32James Roberts 32
Thanks Yogesh, but I am not sure how I find the Paused Flow ID? Surely the ID is unique and generated when the Activity Escalation Flow is started in the earlier steps? So it needs to be a reference? 
Yogeshwar TailorYogeshwar Tailor
Hi James,

Please use the  below code with 100% Coverage and pass.
 
@isTest(SeeAllData=true)
public class Test_interviewsbyRecord 
{
    public TestMethod static void TestTask()
    {
        Task t = new Task();
        t.subject = 'ApexTest';
        t.ActivityDate= date.today();
        t.Status = 'Open';
        t.OwnerId = UserInfo.getUserId();
        insert t;
        
        List <Task> ls = [Select Id from Task where Subject = 'ApexTest'];
        
        Map <id, Object> inputs = new Map<id, Object>();
        inputs.put(t.id,t);
        
        Flow.Interview.Activity_Escalation_Flow myFlow = new Flow.Interview.Activity_Escalation_Flow(inputs);               myFlow.start();

        FlowInterview interview = [Select Id from FlowInterview limit 1];
        
        interviewsByRecordController.getInterviews(t.id);
        interviewsByRecordController.deleteInterview(interview.id);
       
    }
}

Before that i have paused the flow. Check the highlight content in code which i have change.

below url might be helpful for you.

https://developer.salesforce.com/docs/atlas.en-us.salesforce_vpm_guide.meta/salesforce_vpm_guide/vpm_admin_pause.htm

Let me know if you get any other issues in that.

Best,
Yogesh
This was selected as the best answer
James Roberts 32James Roberts 32
Hi Yogesh, I am still getting an error:

System.FlowException: This error occurred when the flow tried to look up records: 
Subject, Id FROM Task WHERE ((Id = '{Subject=ApexTest, ActivityDate=2019-02-14
                              ^
ERROR at Row:1:Column:213
invalid ID field: {Subject=ApexTest, ActivityDate=2019-02-14 00:00:00, Status=Open, OwnerId=00561000003NlHwAAK, Id=00Tq000000VOILgEAP}. You can look up ExceptionCode values in the <a href='https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_concepts_core_data_objects.htm#'>SOAP API Developer Guide .


Here is the test class now:
@isTest(SeeAllData=true)
public class Test_interviewsbyRecord 
{
    public TestMethod static void TestTask()
    {
        Task t = new Task();
        t.subject = 'ApexTest';
        t.ActivityDate= date.today();
        t.Status = 'Open';
        t.OwnerId = UserInfo.getUserId();
        insert t;
        
        List <Task> ls = [Select Id from Task where Subject = 'ApexTest'];
        
        Map <String, Task> inputs = new Map<String, Task>();
         inputs.put('TaskID',t);
        
        Flow.Interview.Activity_Escalation_Flow myFlow = new Flow.Interview.Activity_Escalation_Flow(inputs);               
        myFlow.start();

        FlowInterview interview = [Select Id from FlowInterview limit 1];
        
        interviewsByRecordController.getInterviews(t.id);
        interviewsByRecordController.deleteInterview(interview.id);
        }
}

Thanks James
Yogeshwar TailorYogeshwar Tailor
Hi James,

Seems your inputs(Map) have some problem.

Change it's type..

 Map <String, Task> inputs = new Map<String, Task>();
 inputs.put('TaskID',t);


to 

Map <id, Task> inputs = new Map<id, Task>();
inputs.put(t.id,t);


Let me know if you get any error..

Thanks
Yogesh


 
James Roberts 32James Roberts 32
Hi Yogesh, 

I then have this error when saving the class:

Constructor not defined: [Flow.Interview.Activity_Escalation_Flow].<Constructor>(Map<Id,Task>) Line 18.

Thanks, 
James
Yogeshwar TailorYogeshwar Tailor
Hi James,

Please share the screen of your flow. What are the variables are there?
Anyway try once below line also.

Map <String, Id> inputs = new Map<String, Id>();
inputs.put('TaskID',t.id);


Thanks,
Yogesh
James Roberts 32James Roberts 32
Thanks Yogesh - there was an additional static variable in the Flow that is not used that I had forgotten about. I deleted it and now I have full code coverage!

Thanks so much for your help!
Yogeshwar TailorYogeshwar Tailor
Cool James....!

Please,Mark the thread solved.

Thanks,
Yogesh