+ Start a Discussion
golugolu 

passing parameters from one method to another apex

public static void createCommunicatOHistory(List<Id> activityIds, ){
       
        
    }
    
    public static List<Id> createSalesforceActivities(List<Id> recordIdSet ,String message, Datetime scheduleDateTime, String status){
        List<Task> lstTask = new List<Task>();
        for(String id: recordIdSet){
            Task taskObj = new Task();
            taskObj.ActivityDate = Date.valueOf(scheduleDateTime);
            taskObj.Status = status;
            taskObj.Description = message;
            taskObj.WhoId = id;
            
            lstTask.add(taskObj); 
        }
        insert lstTask;
        List <id> activityIds = new List<Id>();
        if(lstTask.size()>0){
            for(Task t : lstTask){
                activityIds.add(t.id);
            }
        }
        return activityIds;
    }

Hi,
I want to pass the activityIds returned as a parameter to createCommunicatOHistory method. How can i do it?
Best Answer chosen by golu
Ramesh DepaiahRamesh Depaiah
@Golu if it's static then just call
createCommunicatOHistory(activityIds);

All Answers

Ramesh DepaiahRamesh Depaiah
Hi @golu
public static Void createSalesforceActivities(List<Id> recordIdSet ,String message, Datetime scheduleDateTime, String status){
        List<Task> lstTask = new List<Task>();
        for(String id: recordIdSet){
            Task taskObj = new Task();
            taskObj.ActivityDate = Date.valueOf(scheduleDateTime);
            taskObj.Status = status;
            taskObj.Description = message;
            taskObj.WhoId = id;
            
            lstTask.add(taskObj); 
        }
        insert lstTask;
        List <id> activityIds = new List<Id>();
        if(lstTask.size()>0){
            for(Task t : lstTask){
                activityIds.add(t.id);
            }
        }

        this.createCommunicatOHistory(activityIds);
    }

I hope you find the above solution helpful. If it does mark as best answer to help others too.
Thanks,
Ramesh D


 
golugolu
@ramesh this cannot be referred in static context
Ramesh DepaiahRamesh Depaiah
@Golu if it's static then just call
createCommunicatOHistory(activityIds);
This was selected as the best answer
Ajay K DubediAjay K Dubedi
Hi Golu,
Try the below code it works fine.
public class TaskData {
    public static void createCommunicatOHistory(List<Id> activityIds){
       System.debug('Activity id'+activityIds);
    }
    public static List<Id> createSalesforceActivities(List<Id> recordIdSet ,String message, Datetime scheduleDateTime, String status){
        List<Task> lstTask = new List<Task>();
        for(String id: recordIdSet){
            Task taskObj = new Task();
            taskObj.ActivityDate = Date.valueOf(scheduleDateTime);
            taskObj.Status = status;
            taskObj.Description = message;
            taskObj.WhoId = id;
            
            lstTask.add(taskObj);
        }
        insert lstTask;
        List <id> activityIds = new List<Id>();
        if(lstTask.size()>0){
            for(Task t : lstTask){
                activityIds.add(t.id);
            }
        }
        createCommunicatOHistory(activityIds);
        //System.debug('Activity id'+activityIds);
        return activityIds;
    }
}
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi