0

Actually I am trying to provide the search and update mechanism by the way of remote function here. Now I done the search function and I have some struggle to another half of update function.

My task is I updated the ownerId field of task record it's to be selected by the page my search option is to be shown the records by the given date on the datepicker as per the query.

Now I form the update process on the followingly by the code here I try to pass the which records are having the selected checkbox then we take the id values of that rows.that's my plan But I failed now.So that's why I here for help from you guys.

My code is followingly, controller:

public class TaskOwnerUpdate {

    public String dueDate { get; set; }
    public Set<Id> selectedTaskIdSet {get; set;}
    String ownerIdValue {get; set;}
    String selectedColumnValue {get; set;}
    public static List<Task> taskList { get; set;}
    public TaskOwnerUpdate() { } // empty constructor
    public List<Task>selectedtaskList {get; set;}
    //public String dueDate1;
    //public List<accountwrapper> updateTaskList = new List<accountwrapper>();

    public Task getOwnerIdTask() {

        return [SELECT  OwnerId FROM TASK LIMIT 1];
    }

    @RemoteAction
    public static List<Task> getTask (String dueDate) {

        system.debug('dueDate value is------>'+dueDate);
        List<String> stList = dueDate.split('"');
        system.debug('stList value---->'+stList);
        List<String>s1 = stList[0].split(',');
        system.debug('stList[0] value is---->'+stList[0]);
        system.debug('stList[1] value is---->'+stList[1]);
        List<String> splitList = stList[1].split('/');
        system.debug('splitList value is---->'+splitList);
        String dueDate1 = splitList[2]+'-'+splitList[0]+'-'+splitList[1]; 
        taskList = [SELECT Id, Priority, Status, ActivityDate, OwnerId
                   FROM Task WHERE ActivityDate >= :Date.valueOf(dueDate1)];
        system.debug('taskList- value is------>'+taskList);
        return taskList;        

    }

    @RemoteAction 
    public static List<Task> getupdateTask(String OwnerIdValue, String selectedColumnValue) {

        system.debug('OwnerId value is----->'+ownerIdValue);
        system.debug('selectedColumnValue value is---->'+selectedColumnValue);

        //here if I get the the required column value on string I can query that Id value and update the ownerId field here

        if (ownerIdValue == 'Mohan Raj') {

            ownerIdValue = '005280000044bwDAAQ';
        }
        if (ownerIdValue == 'mohan raj') {

            ownerIdValue = '005280000045vqiAAA';
        }
        if (ownerIdValue == 'mohan001 raj') {

            ownerIdValue = '005280000045vqiAAA';
        }
        List<Task> updateTaskList = new List<Task>();
        //userList.clear();
        return updateTaskList;
        //return null;
    }

Page:

<apex:page controller="TaskOwnerUpdate">
    <apex:form >
    <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"/>
    <apex:includeScript value="https://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"/>

    <apex:sectionHeader title="Task Ownership Update"/>

    <apex:pageBlock title="Tasks">
 <!---- Section to draw search field for account-------> 
    <apex:pageBlockSection title="Search Tasks" columns="2">
        <apex:pageBlockSectionItem >
            <!----Task DueDate(YYYY-MM-DD) :---->
            <!---<input type = "text" id = "accountNameToSearch" />---->
            <apex:inputText value="{!dueDate}" size="10" id="demo" onfocus="DatePicker.pickDate(false, this , false)">dueDate</apex:inputText>
            <apex:inputField value="{!OwnerIdTask.OwnerId}" id="owner"></apex:inputField>
            <!---<button onclick="getAccount();return false;">Get Task</button>
            <button>Update</button>---->
        </apex:pageBlockSectionItem>               
        </apex:pageBlockSection>
        <apex:pageBlockSection >
            <button onclick="getTask();return false;">Get Task</button>
            <button onclick="getUpdate();return false;" id = "button">Update</button>
        </apex:pageBlockSection>
    <!----<apex:outputPanel id="output">
    <apex:actionFunction action="{!getSelectable}" name="getSelectable" reRender="output"/>

    </apex:outputPanel>------>
 <!-- result section for showing matching accounts ------->
    <apex:pageBlockSection title="Matching Tasks !" columns="1">
    <!-- 
    Created Empty table using the CSS styles of visualforce pageBlockTable 
    This gives same look and feel ------>

    <table cellspacing="0" cellpadding="0" border="0" id="searchResults" class="list ">
        <colgroup span="2"></colgroup>
        <thead class="rich-table-thead">
            <tr class="headerRow ">
                <th colspan="1" scope="col" class="headerRow">Select</th> 
                <th colspan="1" scope="col" class="headerRow">Id</th>
                <th colspan="1" scope="col" class="headerRow">Priority</th>
                <th colspan="1" scope="col" class="headerRow">Status</th>
                <th colspan="1" scope="col" class="headerRow">ActivityDate</th>
                <th colspan="1" scope="col" class="headerRow">OwnerId</th>
                <!--<th colspan="1" scope="col" class="headerRow"> Number of Employees</th> ---->                               
            </tr>
        </thead>
    <!-- table body left empty for populating via row template using jquery-------> 
        <tbody />
    </table>
    </apex:pageBlockSection>
    </apex:pageBlock>

<!-- 
Create a named jquery template 
This template represents just a result row, with binding variables for each queried field from account.----->

    <script id="resultTableRowTemplate" type="text/x-jquery-tmpl">
        <tr onfocus="if (window.hiOn){hiOn(this);}" onblur="if (window.hiOff){hiOff(this);}" onmouseout="if (window.hiOff){hiOff(this);} " onmouseover="if (window.hiOn){hiOn(this);} " class="dataRow even  first">
        <td class="datacel">${Select}<input type = "checkbox"/></td>
        <td class="Idvalue">${Id}</td>
        <td class="dataCell">${Priority}</td>
        <td class="dataCell">${Status}</td>
        <td class="dataCell">${ActivityDate}</td> 
        <td class="datacell">${OwnerId}</td>      
        <!---<td class="dataCell">${NumberOfEmployees}</td>------>   
        </tr>           
    </script>

    <script type="text/javascript">
    // if you are inside some component
    // use jquery nonConflict
    // var t$ = jQuery.noConflict();
    console.log("check call correct");

    function getTask() {
        var dueDate = $('[id$=":demo"]').val();//$('#demo').val();
        console.log("check data",dueDate);
        // clear previous results, if any
        $("#searchResults tbody").html('');

        // The Spring-11 gift from force.com. Javascript remoting fires here
        // Please note "abhinav" if my org wide namespace prefix
        // testremotingcontroller is the Apex controller
        // searchAccounts is Apex Controller method demarcated with @RemoteAction annotation.
        // DEPRECATED -     abhinav.testremotingcontroller.searchAccounts( accountName, ...) 
        // NEW - summer'12 approach for calling'

        dueDate = JSON.stringify(dueDate);
        Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.TaskOwnerUpdate.getTask}',
                       dueDate, function(result, event){  
                       console.log("due date",dueDate);          
            if (event.status && event.result) {  
              $.each(event.result, function () {                
                 // for each result, apply it to template and append generated markup
                 // to the results table body.
                 $("#resultTableRowTemplate" ).tmpl(this).appendTo( "#searchResults tbody" );
              }
             );            
            } else {
               alert(event.message);
            }
        }, {escape:true});
    }
    </script>

    <script type="text/javascript">
        console.log("check update correct");
       /* 
        function callfun(taskid) {
            console.log("taskid:::::", taskid);
            //var idval2 = ${Id}.value;
            //console.log("id val2", idval2);           

        }*/


        $(function () {

          $('.datacel').click(function() {
            var allData = $(this).parent().parent().first().text();
            console.log("allData value is>>>>",allData);
            //alert(allData);
          });

          $('input:not(#button)').click(function () {
            t = $(this).attr('id');

            text = $('.time' + t).text();
            //alert(text);
          });

          $('#button').click(function (e) {
            e.preventDefault();
            var trs = $('table tr');
            var values = trs.first().find('td');
           // var idr = $('#Idvalue').val();
           // console.log("idr value",idr);
            var values1 = $('table tr td :checkbox:checked').map(function () {

             /*return $(this).closest('tr').find('td').text() + "=="
             + values.eq($(this).parent().index()).text();*/
             console.log("id val",$(this).parent().find('td').eq(1).text());
             return $(this).closest('td').find('td').eq(1).text() ;

            }).get(); 

            console.log("values1",values1);
            getUpdate(values1);
            console.log("after passing vales1", values1);
            console.log("values1",values1);
            return values1;

            });

            //alert(values1);
            //console.log("values1",values1);
            //return values1;

            //getUpdate(values1);

          });    

        function getUpdate(values1) { 
            var taskRecord = String(values1);
            //var stp1 = taskRecord[i].substring(0,18);
            //console.log('stp1 value>>>>',stp1);
            console.log('data type>>>>',typeof(taskRecord));
            console.log("task record value is>>>",taskRecord);
            var ownerIdValue = $('[id$=":owner"]').val();
            console.log("ownerId value is >>>>",ownerIdValue);
            console.log("values1 >>>>",values1);
            Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.TaskOwnerUpdate.getupdateTask}',
                       ownerIdValue, taskRecord, function(result, event){  
                       console.log("ownerIdValue is followingly >>>",ownerIdValue);
                       console.log("values1 >>>>",values1);         
            if (event.status && event.result) {  
              $.each(event.result, function () {                
                 // for each result, apply it to template and append generated markup
                 // to the results table body.
                 $("#resultTableRowTemplate" ).tmpl(this).appendTo( "#searchResults tbody" );
              }
             );            
            } else {
               alert(event.message);
            }
            }, {buffer: false, escape: true, timeout: 30000});

            }

    </script>
</apex:form>
</apex:page>

here I have the table My requirements is 1) I don't know to how get the taskId from (selected checkbox's rows)my datatable where I after checked the check box's on the datatable.

for any answer's thanks in advance

5
  • 1
    Instead of posting whole code, maybe would be good idea to put small snippet of workable code which has exact problem. By that chances of getting help would be increased. On a side note, IDs should never be hardcoded!
    – Raul
    Jan 31 '17 at 15:51
  • @RahulSharma sorry for that i don't know how to provide snippet and I follow your your advice .can you know that pls know to me
    – MohanRaj
    Jan 31 '17 at 15:52
  • For your problem, collect the Ids through jQuery and pass them to controller method maybe by an apex:actionFunction
    – Raul
    Jan 31 '17 at 15:53
  • but I don't know to how to take the selected checkbox's rows task id to take on here sir..
    – MohanRaj
    Jan 31 '17 at 15:54
  • I try to take that column as followingly my code it's given undefined on my all attempt.So that's why i need help sir.
    – MohanRaj
    Jan 31 '17 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.