+ Start a Discussion
Jim Parker 7Jim Parker 7 

Invalid Initial Value Type List for List - Compile Error

Getting a compile error - Invalid Initial Value Type List for List.  Line 14 (commented below).  In essence, I have a trigger on dsfs__DocuSign_Status__c.  dsfs__DocuSign_Status__c has a field dsfs__Case__c which is an ID of a case.  Anytime the trigger occurs, I want to set the "Status" field on the case identified by dsfs__Case__c to newStatus.  Any thoughts on what I am doing wrong?
public class DocusignStatusUtil {
    public static void updateCaseStatus (List<dsfs__DocuSign_Status__c> envelopes, String newStatus) {
        try {
                Set<Id> st_ParentId = new Set<Id>();
                 for(dsfs__DocuSign_Status__c envelopesEvaluated : envelopes)
                     {
                       st_ParentId.add(envelopesEvaluated.dsfs__Case__c);
                     }

			List<Id> relatedCasesMap;
            if(st_ParentId!=null && !st_ParentId.isEmpty())
               {
//this is where the error is
                	relatedCasesMap = new List<Id>([SELECT Id 
													FROM Case
													WHERE Id IN :st_ParentId limit 1]); 
               }
               
															 
			for (dsfs__DocuSign_Status__c envelopesEvaluated : envelopes) 
            {
               if(relatedCasesMap!=null && relatedCasesMap.containsKey(envelopesEvaluated.dsfs__Case__c))
                  {
                     
				relatedCasesMap.get(envelopesEvaluated.dsfs__Case__c).Status = newStatus;
				
		          }
             }
           

			if(relatedCasesMap!=null && relatedCasesMap.values()!=null)
			   update relatedCasesMap.values();
        
        } catch (Exception e) {
            System.debug('Issue with the Horizon Case Update: ' + e.getMessage());
        }
    }
}


 
Best Answer chosen by Jim Parker 7
rajat Maheshwari 6rajat Maheshwari 6

Hi Jim,

Below is code snippet, It will help you :)

public class DocusignStatusUtil {
    public static void updateCaseStatus (List<dsfs__DocuSign_Status__c> envelopes, String newStatus) {
        try {
                Set<Id> st_ParentId = new Set<Id>();
                 for(dsfs__DocuSign_Status__c envelopesEvaluated : envelopes)
                     {
                       st_ParentId.add(envelopesEvaluated.dsfs__Case__c);
                     }

			Map<Id,Case> relatedCasesMap;
            if(st_ParentId!=null && !st_ParentId.isEmpty())
               {
//this is where the error is
                	relatedCasesMap = new Map<Id,Case>([SELECT Id,Status
													FROM Case
													WHERE Id IN :st_ParentId ]); 
               }
               
															 
			for (dsfs__DocuSign_Status__c envelopesEvaluated : envelopes) 
            {
               if(relatedCasesMap!=null && relatedCasesMap.containsKey(envelopesEvaluated.dsfs__Case__c))
                  {
                     
				relatedCasesMap.get(envelopesEvaluated.dsfs__Case__c).Status = newStatus;
				
		          }
             }
           

			if(relatedCasesMap!=null && relatedCasesMap.values()!=null)
			   update relatedCasesMap.values();
        
        } catch (Exception e) {
            System.debug('Issue with the Horizon Case Update: ' + e.getMessage());
        }
    }
}


Please let me know, the result after utilize this code

 

Thanks
Rajat Maheshwari
rajatzmaheshwari@gmail.com

All Answers

JLA.ovhJLA.ovh
The variable name is relatedCasesMap while the declaration is a List. Quite confusing.
Your SELECT query will not return a List<Id> as your declaration, but a List<Case>
That is why you get this error. Change your variable declaration to List<Case>, or even better to Map<Id,Case>
rajat Maheshwari 6rajat Maheshwari 6

Hi Jim,

Below is code snippet, It will help you :)

public class DocusignStatusUtil {
    public static void updateCaseStatus (List<dsfs__DocuSign_Status__c> envelopes, String newStatus) {
        try {
                Set<Id> st_ParentId = new Set<Id>();
                 for(dsfs__DocuSign_Status__c envelopesEvaluated : envelopes)
                     {
                       st_ParentId.add(envelopesEvaluated.dsfs__Case__c);
                     }

			Map<Id,Case> relatedCasesMap;
            if(st_ParentId!=null && !st_ParentId.isEmpty())
               {
//this is where the error is
                	relatedCasesMap = new Map<Id,Case>([SELECT Id,Status
													FROM Case
													WHERE Id IN :st_ParentId ]); 
               }
               
															 
			for (dsfs__DocuSign_Status__c envelopesEvaluated : envelopes) 
            {
               if(relatedCasesMap!=null && relatedCasesMap.containsKey(envelopesEvaluated.dsfs__Case__c))
                  {
                     
				relatedCasesMap.get(envelopesEvaluated.dsfs__Case__c).Status = newStatus;
				
		          }
             }
           

			if(relatedCasesMap!=null && relatedCasesMap.values()!=null)
			   update relatedCasesMap.values();
        
        } catch (Exception e) {
            System.debug('Issue with the Horizon Case Update: ' + e.getMessage());
        }
    }
}


Please let me know, the result after utilize this code

 

Thanks
Rajat Maheshwari
rajatzmaheshwari@gmail.com

This was selected as the best answer