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
Rajesh Kumar MaharanaRajesh Kumar Maharana 

Create task object records based on contact names in the multi-select picklist

I have created custom multipicklist jQuery. In the multipicklist I have shown the contact names. Whenever I select the contact names, it is showing contact names in the label. It is also counting no.of contacts I have selected.
Activity Objective==> Wherever you see Activity Objective in the VFP, I have added the codes for the multi-picklist.
ISSUE: whenever I select the contact names (either 1 or more than 1) from the multi-picklist and click on save. It will save the record, but in the name field in the Task object will be blank. If I have selected 1 0r more than 1 contact names, it will create single record in the Task object and the name field will be blank.
REQUIREMENT: Now I want that, how many contact names I have selected from the multi-picklist. That many records will be created in the Task Object.
Already in the controller, record creation code is written. It is checking the contact name isChecked=true, then it will create the record.
In my code, it is taking isChecked=false. So it is not able to creat
<apex:page standardController="Task" id="thePageId" extensions="NewTaskCtrl" tabStyle="Task" action="{!loadNewTask}">
    <apex:outPutPanel id="myMSG">
        <apex:pageMessages id="msg" />
    </apex:outPutPanel>  
    <apex:slds />
    <apex:form id="newTaskPage">
             <!-- CDN links for the multiple picklist  -->
                <meta charset="utf-8" />
                <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
                <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
                <link href="https://www.jqueryscript.net/css/jquerysctipttop.css?v3" rel="stylesheet" type="text/css" />
                <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"/>
                <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>                
                <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
                <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
                <script src="https://cdn.jsdelivr.net/npm/@dashboardcode/bsmultiselect@0.5.40/dist/js/BsMultiSelect.min.js"></script>              
                <!-- / Activity Objective - New picklist code-->

                <apex:actionFunction action="{!filterFields}" name="filterFields" reRender="myMSG,taskInfo" >
                    <apex:param value="" name="tType" />
                </apex:actionFunction>
                <apex:sectionHeader title="Task" subtitle="New Task"/>
                <apex:inputHidden value="{!inputValue}" id="theHiddenInput"/>
                <div class="slds-card">
                    <div class="slds-card__header slds-grid slds-border_bottom slds-p-bottom_small" style="background-color: #fafaf9;">
                        <div class="slds-media slds-media_center slds-has-flexi-truncate">
                            <div class="slds-media__body">
                                <h2 class="slds-card__header-title slds-text-heading_small">
                                    Task Edit
                                </h2>
                            </div>
                            <div class="slds-no-flex">
                                <apex:commandButton action="{!performSave}" title="Save" value="Save" styleClass="slds-button slds-button_brand"/>
                                <apex:commandButton action="{!cancel}" title="Cancel" value="Cancel" styleClass="slds-button slds-button_neutral"/>
                            </div>
                        </div>
                    </div>
                    <div class="slds-card__body slds-p-horizontal_small">
                        <div class="slds-m-bottom_small slds-p-around_xx-small" style="background-color: #fafaf9;"><strong>Related To</strong></div> 
                        <div class="slds-form slds-form_horizontal">
                            <div>
                                <div style="max-width: 600px;">
                                    <apex:outputPanel styleClass="relatedToSection">
                                        <div class="slds-form-element">
                                            <apex:outputLabel value="Account" styleClass="slds-form-element__label"/>
                                            <div class="slds-form-element__control slds-m-top_xxx-small">
                                                <apex:outputField value="{!taskObjectParent.WhatId}" title="This will contain Related Account" label="Account" />
                                            </div>
                                        </div>

                                        <apex:pageBlock id="OfficeContactList">
                                            <!--  rendered="{!IF((taskObjectParent.Id = null),true,false)}"  -->
                                            <apex:outputPanel style="display:none" styleclass="taskContactMultiList">


                                                <div class="slds-form-element">
                                                    <apex:outputLabel value="Select Contact to create task" styleClass="slds-form-element__label" id="con12"/>
                                                    <div class="slds-form-element__control"  style="padding-right: 82px;">
                                                        <!-- Activity Objective  -->
                                                        <!-- Show the multiple picklist values and binding-->
                                                        <div class="container">
                                                            <select name="contactNames" id="example" class="form-control" multiple="multiple" onChange="countSelectedCheckbox()">
                                                                <apex:repeat value="{!avaiableContactlList}" var="con" id="conTable">
                                                                    <option value="{!con.isChecked}" id="opt">{!con.Name}</option> <!---value is changed -->
                                                                </apex:repeat>
                                                            </select>    
                                                        </div>
                                                        <!-- / Activity Objective -->

                                                        Total Number of Selected record :<span style="font-weight:bold" id="selContactSize">0</span>
                                                    </div>
                                                </div>

                                            </apex:outputPanel>

                                        </apex:pageBlock>     

                                    <div class="slds-form-element">
                                        <apex:outputLabel value="Topics Discussed" styleClass="slds-form-element__label"/>
                                        <apex:outputPanel id="refreshing">
                                            <div class="slds-form-element__control"  style="padding-right: 82px;">
                                                <div class="slds-scrollable_y slds-m-top_x-small slds-m-bottom_small slds-p-around_x-small" style="max-height: 90px; border: 1px solid #dddbda; border-radius: .25rem;">
                                                    <table>

                                                        <apex:repeat value="{!avaiableTopicList}" var="topic">
                                                            <tr>
                                                                <td width="20" class="slds-p-bottom_x-small">
                                                                    <span class="slds-checkbox slds-checkbox_standalone">
                                                                        <apex:inputCheckbox value="{!topic.isChecked}" onclick="selectAllCheckboxes('topicCheckBoxId')"  id="topicCheckBoxId"/>
                                                                        <span class="slds-checkbox_faux"></span>
                                                                    </span>
                                                                </td>
                                                                <td class="slds-p-bottom_x-small">
                                                                    <label>
                                                                        {!topic.Name}
                                                                    </label>
                                                                </td>
                                                            </tr>
                                                        </apex:repeat> 
                                                    </table>

                                                </div>
                                                Total Number of Selected record :<span style="font-weight:bold" id="selTopicSize">{!totalAvaiableTopic}</span> 
                                            </div>
                                        </apex:outputPanel>
                                    </div>

                                </div>
                            </div>


                        </div> 

                    </div>
                    <div class="slds-card__footer slds-text-align_right">
                        <apex:commandButton action="{!performSave}" title="Save" value="Save" styleClass="slds-button slds-button_brand"/>
                        <apex:commandButton action="{!cancel}" title="Cancel" value="Cancel" styleClass="slds-button slds-button_neutral"/>  
                    </div>
                </div>
                <script>
                function setFocusOnLoad() {}

                function toggleComponent(taskType,componentToToggle,taskId){
                    console.log('taskId : '+taskId);
                    //filterFields();
                    if(taskId == 'NULL' || taskId == ''){
                        var contactComponent = document.getElementsByClassName(componentToToggle)[0];
                        var selectedValue = taskType.value;
                        console.log(componentToToggle);
                        if(selectedValue == 'Physician-to-Physician Visit' || selectedValue == 'Sports Medicine' ){
                            contactComponent.style.display ='block';

                        }else{
                            contactComponent.style.display ='none';
                        }
                    }else{
                        var contactComponent = document.getElementsByClassName(componentToToggle)[0];
                        var selectedValue = taskType.value;
                        console.log(componentToToggle);
                        var oldTaskType =  String(document.getElementById('thePageId:newTaskPage:theHiddenInput').value);

                        if((oldTaskType != 'Physician-to-Physician Visit' && selectedValue == 'Physician-to-Physician Visit') || (oldTaskType != 'Sports Medicine' && selectedValue == 'Sports Medicine')){
                            contactComponent.style.display ='block';

                        }else{ 
                            contactComponent.style.display ='none';
                        }
                    }
                    //alert(taskType.value);
                    filterFields(taskType.value);
                }

                function selectAllCheckboxes(receivedInputID){
                    var inputCheckBox = document.getElementsByTagName("input");
                    var totalCount = 0;
                    for(var i=0; i<inputCheckBox.length; i++){
                        if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){
                            if(inputCheckBox[i].checked == true){
                                //alert("inputCheckBox[i].checked==>>"+inputCheckBox[i].checked);
                                totalCount = totalCount + 1;
                            }
                        }
                    }

                    //console.log('====>' + totalCount);
                    if(receivedInputID=='contactCheckBoxId'){
                        document.getElementById('selContactSize').innerHTML = totalCount;
                    }else if(receivedInputID=='goalCheckBoxId'){
                        document.getElementById('setGoalsLength').innerHTML = totalCount;
                    }else if(receivedInputID=='topicCheckBoxId'){
                        document.getElementById('selTopicSize').innerHTML = totalCount;
                    }

                }


                // Js file to show the multiple picklist.
                $("select[multiple='multiple']").bsMultiSelect();

                // code to calculate the count of selected picklist values
                **function countSelectedCheckbox(){
                    var totalCount = $("select#example>option:selected").length;
                    document.getElementById('selContactSize').innerHTML = totalCount;
                    }
                </script>
    </apex:form>
</apex:page>

e the record. Due to limitation, not able to upload whole code.
Rajesh Kumar MaharanaRajesh Kumar Maharana
//Above is the VFP. Below is the controller
// Controller

public class NewTaskCtrl {

    public Task taskObjectParent{get;set;}
    private Task tempTask;
    private String whoId;
    private String whatId;
    private String recordId;
    private String retURL;
    private String close;
    // these three variables will set when log a call button will clicked on activity history
    private String title;
    private String tsk5;
    private String followup;
    public String inputValue{get;set;}  
	public List<MultiSelect> avaiableContactlList {get;set;}
	public List<MultiSelect> avaiableGoalList {get;set;}
	public List<MultiSelect> avaiableTopicList {get;set;}
    public boolean isNAOProfile{get;set;}
	public Integer totalAvaiableGoal {get;set;}
	public Integer totalAvaiableTopic {get;set;}

    public NewTaskCtrl(ApexPages.StandardController stdController) {
		totalAvaiableGoal = 0;
		totalAvaiableTopic = 0;
		//this.taskObjectParent = (Task)stdController.getRecord();
		tempTask=new Task();
		taskObjectParent=new Task();
        whatId = ApexPages.currentPage().getParameters().get('what_id');
        whoId = ApexPages.currentPage().getParameters().get('who_id');
        recordId = ApexPages.currentPage().getParameters().get('id');
        close = ApexPages.currentPage().getParameters().get('close');
        retURL = ApexPages.currentPage().getParameters().get('retURL');
        
        title = ApexPages.currentPage().getParameters().get('title');
        tsk5 = ApexPages.currentPage().getParameters().get('tsk5');
        followup = ApexPages.currentPage().getParameters().get('followup');
        
        CheckProfile();
    }
    
    
    
    public void CheckProfile(){
        isNAOProfile=false;
        //If Logged in user prfile is NAO profile then replace picklist value like below
        //Get looged in user profile
        User objUser=[select profile.Name from user where id=:UserInfo.getUserId()];
        if(objUser!=null && objUser.profile.Name=='NAO Profile'){
            isNAOProfile=true;
        }
    }

    public void filterFields() {
        //Get Profile Name of logged in user
        string profileName=[select profile.Name from user where id=:UserInfo.getUserId()].profile.Name;
        System.debug('taskObjectParent.type------------'+taskObjectParent.type);

        
		avaiableGoalList = new List<MultiSelect>();
		avaiableTopicList = new List<MultiSelect>();
        if(taskObjectParent.type == 'Sports Medicine') {	

              avaiableTopicList.add(new MultiSelect(false, '2 Day Athlete Guarantee', null));
			avaiableTopicList.add(new MultiSelect(false, 'Athletic Training Protocols', null));
			avaiableTopicList.add(new MultiSelect(false, 'Divisions', null));
            avaiableTopicList.add(new MultiSelect(false, 'Events', null));
            avaiableTopicList.add(new MultiSelect(false, 'Hospitals', null));
            avaiableTopicList.add(new MultiSelect(false, 'Issue Resolution', null));
            avaiableTopicList.add(new MultiSelect(false, 'Material Request', null));
			avaiableTopicList.add(new MultiSelect(false, 'Medical Coverage', null));
            avaiableTopicList.add(new MultiSelect(false, 'New Clinic', null));
            avaiableTopicList.add(new MultiSelect(false, 'New Physicians', null));
            avaiableTopicList.add(new MultiSelect(false, 'Quality Outcomes', null));
            avaiableTopicList.add(new MultiSelect(false, 'Referral Process', null));
			avaiableTopicList.add(new MultiSelect(false, 'Sports Injury Clinics', null));
			avaiableTopicList.add(new MultiSelect(false, 'Sponsorships', null));
            avaiableTopicList.add(new MultiSelect(false, 'Team Physicals', null));
			
			avaiableGoalList.add(new MultiSelect(false, 'Establishing New Relationships', null));
			avaiableGoalList.add(new MultiSelect(false, 'Maintaining Relationship', null));
			avaiableGoalList.add(new MultiSelect(false, 'Service Update', null));
        }
        else {
                        
          			avaiableTopicList.add(new MultiSelect(false, 'Account Maintenance', null));
			avaiableTopicList.add(new MultiSelect(false, 'Co-Management', null));
			avaiableTopicList.add(new MultiSelect(false, 'Material Request', null));
			avaiableTopicList.add(new MultiSelect(false, 'Referral Process', null));
			avaiableTopicList.add(new MultiSelect(false, 'Divisions', null));
			avaiableTopicList.add(new MultiSelect(false, 'Events', null));
            avaiableTopicList.add(new MultiSelect(false, 'Issue Resolution', null));
            avaiableTopicList.add(new MultiSelect(false, 'New Provider', null));
			avaiableTopicList.add(new MultiSelect(false, 'Urgent Ortho/Walk-In', null));

            for( Schema.PicklistEntry f : Task.Goal_of_Activity__c.getDescribe().getPicklistValues()) {
                 if(isNAOProfile==true){
                    if(f.getValue()!='CORE Referral Manager Training'){
						avaiableGoalList.add(new MultiSelect(false, f.getLabel(), null));
                    }
                 }
                 else{
					avaiableGoalList.add(new MultiSelect(false, f.getLabel(), null));
                 }
            }
        }
        
        //For Goal
		system.debug(taskObjectParent.Id + ' =====> ' + taskObjectParent.Goal_of_Activity__c);
		if(string.isNotBlank(taskObjectParent.Goal_of_Activity__c)){
			for(MultiSelect goal : avaiableGoalList){
				for(string str:taskObjectParent.Goal_of_Activity__c.split(';')){
					if(goal.Name == str.trim()){
						goal.isChecked = true;
					}
				}
			}
			totalAvaiableGoal = taskObjectParent.Goal_of_Activity__c.split(';').size();
		}
		
        system.debug('avaiableGoalList--111------------->' + avaiableGoalList);    

        /*if(isNAOProfile==true){
			avaiableTopicList = new List<MultiSelect>();
			avaiableTopicList.add(new MultiSelect(false, 'Account Maintenance', null));
			avaiableTopicList.add(new MultiSelect(false, 'Divisions', null));
			avaiableTopicList.add(new MultiSelect(false, 'Events', null));
			avaiableTopicList.add(new MultiSelect(false, 'Issue Resolution', null));
			avaiableTopicList.add(new MultiSelect(false, 'NAO Material Request', null));
			avaiableTopicList.add(new MultiSelect(false, 'New Clinic', null));
			avaiableTopicList.add(new MultiSelect(false, 'New Physician', null));
			avaiableTopicList.add(new MultiSelect(false, 'NAO Referral Process', null));
			avaiableTopicList.add(new MultiSelect(false, 'Quality Outcomes', null));
			avaiableTopicList.add(new MultiSelect(false, 'Urgent Ortho', null));
			
        }*/
        
        //For Topics        
		system.debug(taskObjectParent.Id + ' =====> ' + taskObjectParent.Topics_Discussed__c);
		if(string.isNotBlank(taskObjectParent.Topics_Discussed__c)){
			for(MultiSelect goal : avaiableTopicList){
				for(string str:taskObjectParent.Topics_Discussed__c.split(';')){
					if(goal.Name == str.trim()){
						goal.isChecked = true;
					}
				}
			}
			totalAvaiableTopic = taskObjectParent.Topics_Discussed__c.split(';').size();
		}
		system.debug('avaiableTopicList--2222------------->' + avaiableTopicList);
		
    }
    
    
    // Task cannot be created from contact. Button hidden
    public PageReference loadNewTask(){
      try{
        
        taskObjectParent=new Task();
        //Assign default value
        taskObjectParent.ActivityDate=Date.Today();
        if(recordId != null){ 
          List<Task> taskList = [select whatId,whoId,ActivityDate ,Priority ,Status,
          Activity_Cost__c,OwnerId,Visit_Duration__c,Description,Goal_of_Activity__c ,
          Topics_Discussed__c,Subject, Type 
          from task where id=:recordId limit 1];
          
          if(taskList!= null && taskList.size()>0)
          {
            taskObjectParent=taskList[0];
            whatId = taskList[0].whatId;
            whoId = taskList[0].whoId;
            inputValue = taskList[0].Type;    
          }
        }
        if((whatId != null && !whatId.startsWith('001')) || (whoId!=null && !whoId.startsWith('003'))){
          PageReference refObject = new PageReference('/00T/e');
          refObject.getParameters().putAll(ApexPages.currentPage().getParameters());
          refObject.getParameters().put('nooverride', '1');
          refObject.setRedirect(true);
          return refObject;
        }else{
		  
		  avaiableContactlList = new List<MultiSelect>();
          filterFields();
          
          //We do not create task through contact 
          if(whatId != null && whatId.startsWith('001')){
            //get Account Id to fileter contact based on profile
            
            Set<string> setAccountId=new Set<string>();
            if(Test.isRunningTest()){
                setAccountId.add(whatId);  
            }
            string labelActId=Label.Core_Account_Id;
            if(isNAOProfile==true){
                 labelActId=Label.NAO_Account_Id;           
            } 
            if(string.isNotBlank(labelActId)){
                for(string st:labelActId.split(',')){
                    setAccountId.add(st);
                }
                for(Contact contactObject : [Select id,Name,Email, AccountId From Contact where  
                                 RecordType.Name='Internal Provider' AND Inactive__c = false  order by Name]){

				  avaiableContactlList.add(new MultiSelect(false, contactobject.Name, contactObject.Id));
                }
            }
            taskObjectParent.WhatId = whatId;
            taskObjectParent.OwnerId = Userinfo.getUserId();
          }
          if(close != null && close =='1'){
            taskObjectParent.Status = 'Completed';
          }
          // when task is created from log a call
          System.debug('title > '+ title + 'followup > '+ followup + 'tsk5 > '+ tsk5);
          if(title != null && title =='Referral Meeting' && followup !=null && followup == '1' && tsk5 != null && tsk5 == 'Referral Meeting'){
            taskObjectParent.Status = 'Completed';
            taskObjectParent.Type = title;
          }
          return null;
        }
        //return null;
      }catch(Exception e){
        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.FATAL,e.getMessage()));
        return null;
      }
    }
    
   
    // for all activity objectives except 'Physician to physician visit' contact is not required.
    public PageReference performSave(){
        System.debug('############');
      try{
        string retId=ApexPages.currentPage().getParameters().get('retURL');
        system.debug('retId------------>' + retId);
        system.debug('recordId------------>' + recordId);
        if(string.isBlank(retId)==null || retId==null){
          retId=recordId;
        }
        system.debug('retId111------------>' + retId);        
        if(string.isBlank(retId)){
            if(string.isNotblank(whatId)){
                retId=whatId;
            }
            if(string.isNotblank(whoId)){
                retId=whoId;
            }
        }
        system.debug('retId222------------>' + retId);
        //String retId = ApexPages.currentPage().getParameters().get('retURL');
		boolean isContactSelected = false;
		for(MultiSelect conObj : avaiableContactlList){
			System.debug('---conObj_1--'+conObj);
            if(conObj.isChecked){
                System.debug('---conObj_2--'+conObj);
				isContactSelected = true;
				break;
			}
		}
        List<Task> tasksToBeSaved = new List<Task>();
        if(recordId == null){			  
              if((taskObjectParent.Type == 'Physician-to-Physician Visit' || taskObjectParent.Type == 'Sports Medicine') && isContactSelected == true){
                for(MultiSelect conObj : avaiableContactlList){
				  if(conObj.isChecked){
					  Task taskObject = createTask(taskObjectParent,conObj.Value);

					  taskObject.Topics_Discussed__c = '';
					  taskObject.Goal_of_Activity__c = '';
						
					  for(MultiSelect sltVal : avaiableTopicList){
						if(sltVal.isChecked){
							taskObject.Topics_Discussed__c += sltVal.Name + ';';
						}
					  }
					  
					  for(MultiSelect sltVal : avaiableGoalList){
						if(sltVal.isChecked){
							taskObject.Goal_of_Activity__c += sltVal.Name + ';';
						}
					  }
					   
					  tasksToBeSaved.add(taskObject);
				  }
                }
              }else{
                Task taskObject = createTask(taskObjectParent,null);
                
                taskObject.Topics_Discussed__c = '';
                taskObject.Goal_of_Activity__c = '';
                
				for(MultiSelect sltVal : avaiableTopicList){
					if(sltVal.isChecked){
						taskObject.Topics_Discussed__c += sltVal.Name + ';';
					}
				}
                
				for(MultiSelect sltVal : avaiableGoalList){
					if(sltVal.isChecked){
						taskObject.Goal_of_Activity__c += sltVal.Name + ';';
					}
				}
                
                tasksToBeSaved.add(taskObject);
              }
          
            
          system.debug(' >>>>>   ===    '+tasksToBeSaved);
          upsert tasksToBeSaved;
		  
		  system.debug(' >>>>> ------'+tasksToBeSaved);
          system.debug('retId44------------>' + retId);
          System.debug(' Current Url -- '+ApexPages.currentPage().getHeaders().get('Origin'));
          System.debug('  >  >>  > >> >  '+Apexpages.currentPage().getUrl());
          //PageReference pg = new PageReference('/'+ApexPages.currentPage().getParameters().get('retURL'));
          //PageReference pg = new PageReference('/'+retId);
          System.debug(' >>  > > >  299  = = =     '+retId);
          PageReference pg = new PageReference(retId);
          pg.setRedirect(true);
          return pg;
        }else{
          
          
          if(((taskObjectParent.Type == 'Physician-to-Physician Visit' && inputValue != 'Physician-to-Physician Visit' ) || (taskObjectParent.Type == 'Sports Medicine' && inputValue  != 'Sports Medicine')) && isContactSelected == true){
            for(MultiSelect conObj : avaiableContactlList){
				if(conObj.isChecked){
				   Task taskObject = createTask(taskObjectParent,conObj.Value);
				   
				   taskObject.Topics_Discussed__c = '';
				   taskObject.Goal_of_Activity__c = '';
					
				   	for(MultiSelect sltVal : avaiableTopicList){
						if(sltVal.isChecked){
							taskObject.Topics_Discussed__c += sltVal.Name + ';';
						}
					}
					
				   for(MultiSelect sltVal : avaiableGoalList){
						if(sltVal.isChecked){
							taskObject.Goal_of_Activity__c += sltVal.Name + ';';
						}
					}
				   tasksToBeSaved.add(taskObject);
			   }
            }
          }else{
            taskObjectParent.Subject = taskObjectParent.Type;

            taskObjectParent.Topics_Discussed__c = '';
            taskObjectParent.Goal_of_Activity__c = '';
            
			for(MultiSelect sltVal : avaiableTopicList){
				if(sltVal.isChecked){
					taskObjectParent.Topics_Discussed__c += sltVal.Name + ';';
				}
			}
            
			for(MultiSelect sltVal : avaiableGoalList){
				if(sltVal.isChecked){
					taskObjectParent.Goal_of_Activity__c += sltVal.Name + ';';
				}
			}
            
            upsert taskObjectParent;
          }
          
		  System.debug('=:tasksToBeSaved:=' +tasksToBeSaved);
          if(!tasksToBeSaved.isEmpty()){
            upsert tasksToBeSaved;
          }
          
          //PageReference pg = new PageReference('/'+ApexPages.currentPage().getParameters().get('retURL'));
          //PageReference pg = new PageReference('/'+retId);
          PageReference pg = new PageReference(retId);
          System.debug(' >>  > > >  342 = = =     '+retId);
          pg.setRedirect(true);
          return pg;
        }
      }catch(Exception e){
        System.debug(e);
        return null;
      }
      //return null;
    }
    private Task createTask(Task taskObjectParent1,String contactIdStr){
		Task taskObject = new Task();
		if((taskObjectParent.Type == 'Physician-to-Physician Visit' && inputValue != 'Physician-to-Physician Visit') || (taskObjectParent.Type == 'Sports Medicine' && inputValue  != 'Sports Medicine')){
		
		}else{
		  taskObject.Id = taskObjectParent1.Id; 
		}
		taskObject.Type = taskObjectParent1.Type;
		//taskObject.Subject = taskObjectParent1.Type;
		taskObject.whatId = taskObjectParent1.whatId;
		taskObject.whoId = contactIdStr;
		taskObject.OwnerId = taskObjectParent1.OwnerId;
		taskObject.Description = taskObjectParent1.Description;
		taskObject.ActivityDate = taskObjectParent1.ActivityDate;
		taskObject.Status = taskObjectParent1.Status;
		taskObject.Priority = taskObjectParent1.Priority;
		taskObject.Goal_of_Activity__c = taskObjectParent1.Goal_of_Activity__c;
		taskObject.Topics_Discussed__c = taskObjectParent1.Topics_Discussed__c;
		taskObject.Visit_Duration__c = taskObjectParent1.Visit_Duration__c;
		taskObject.Activity_Cost__c = taskObjectParent1.Activity_Cost__c;
		return taskObject;
    }
    
    //store the selected contact names
    List<String> list_ContactNames{get;set;}
    String strContactName {get;set;}
    Boolean bolSelectedCheckBox {get;set;}
    public void StoreSelectedContacts(){
        System.debug('---method called---');
        System.debug('---strContactName---'+strContactName);
        System.debug('--bolCheckBox--'+bolSelectedCheckBox);
        
    }

	//Wrapper class
	public class MultiSelect{
		public boolean isChecked{get;set;}
		public String Name{get;set;}
		public Id Value{get;set;}
		public MultiSelect(boolean isChecked, String Name, Id Value){
			this.isChecked = isChecked;
			this.Name = Name;
			this.Value = Value;
		}
	}
}

 
SUPRAKASH MarandiSUPRAKASH Marandi
I want to fetch the records of Accounts,contacts https://alllyricszone.in/
Mark StvenMark Stven
Can i use this code in my chemical (https://researchemicalsforsale.com) website?