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
Vadivel MuruganVadivel Murugan 

caused by: System.StringException: Invalid id:

Hi,

I have implemented my below code has in future Method. But When I have done 'Mass Edit' for list view that time the Error has occurred in  System.StringException: Invalid id: at highlighted line.

 Private void UpdateVisitComplete(Map<Id,Service_Sheet_STD__c> newReActMap){

        String RSIdCollection;       
        for(Service_Sheet_STD__c rs:newReActMap.values()){
                if(String.valueOf(rs.id)!=Null){
                RSIdCollection=((RSIdCollection==NULL||RSIdCollection=='')?rs.id:RSIdCollection+','+rs.Id);    // The error has been occured this line.
                }
    }
        if(RSIdCollection!=NULL && ShouldIRun.CanIRun()) Future_UpdateVisitComplete(RSIdCollection);
        
    }
/*============== UpdateVisitComplete-FUture Method ======*/
 @future
Private static void Future_UpdateVisitComplete(String RSIdStringCollection){  
        
        Map<Id,Service_Sheet_STD__c> newReActMap;
        ShouldIRun.StopTrigger(); 
        List<String> rsIds=RSIdStringCollection.split(',',0);
        
        newReActMap =New Map<Id,Service_Sheet_STD__c>([SELECT id, Visit__c,Close_Visit__c,Fire_Extinguisher_Service_complete__c  from Service_Sheet_STD__c where ID IN:rsIds]);


        //Variable Declaration
        List<id> visitIds=new List<id>();
        for(Service_Sheet_STD__c rs:newReActMap.values()){
            if(rs.Visit__c!=NULL)
                visitIds.add(rs.visit__c);
        }
        System.debug('--------'+visitIds);
        //to get a list of Visits 
        List<Visits__c> visitList=[select id,Visit_Complete__c from Visits__c where ID IN:visitIds ];
        System.debug('--------'+visitList);
        for(Service_Sheet_STD__c rs:newReActMap.values()){
            for(Visits__c  vt :visitList){
                if(rs.Visit__c == vt.Id && rs.Close_Visit__c=='Yes' && rs.Fire_Extinguisher_Service_complete__c){
                    //assign  Visit Complete Field
                     vt.Visit_Complete__c =true;
               }
           }
        }
        try{
            if(visitList.size()>0){
            update visitList;     //update the Visits
            }    
        }Catch(Exception e){
            String msg=e.getMessage();
            for(Service_Sheet_STD__c ss:newReActMap.values()){
                ss.addError(msg);
            }
        }

}

If anyone know, Please suggest how to rectify this problem.
Amit Chaudhary 8Amit Chaudhary 8
Please try below code.
If(RSIdCollection==NULL || RSIdCollection=='' )
 {
	RSIdCollection = String.ValueOf(rs.id);
 }
 else
 {
	RSIdCollection = RSIdCollection + ','+String.ValueOf(rs.id);
 }

 
Arun KumarArun Kumar
Use Blank function like below:
 
If(String.isBlank(RSIdCollection) ) { RSIdCollection = String.ValueOf(rs.id); }
else { RSIdCollection = RSIdCollection + ','+String.ValueOf(rs.id); }