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
ECL47ECL47 

Javascript to create tasks using custom object and related contact

We are using the Activity Manager app by VersatileCapitalist to mass create tasks.

We have buttons to mass create tasks on the contact views (where whoid=contact id), and on a custom Property object (pba__Property__c)  views (where whatid=property id) - Both buttons are below.

On the Property object, we have a contact lookup field for the Property Owner (PropertyOwner__c). We would like to be able to mass create tasks from the Property view with the whoid=PropertyOwner__c.  The app has all of the functionality that we need, I am not sure how to pull/set the contact ids from the property view.

I am pretty new to code, so any help would be appreciated.

Custom Contact Button
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
var records = {!GETRECORDIDS( $ObjectType.Contact)};
var returnURL = window.location.href;
if(records != null && records != ''){
mywin = window.open('/apex/activities__createTasks?Ids='+records+'&retURL='+returnURL+'&type=whoid' , '_top',
'height=400,width=600,status=yes,toolbar=no,menubar=no,location=no,center=yes,resizable=no');
mywin.focus();
}else{
alert('Please select atleast one record.');
}

Custom Property Button
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
var records = {!GETRECORDIDS( $ObjectType.pba__Property__c)};
var returnURL = window.location.href;
if(records != null && records != ''){
mywin = window.open('/apex/activities__createTasks?Ids='+records+'&retURL='+returnURL+'&type=whatId' , '_top',
'height=400,width=600,status=yes,toolbar=no,menubar=no,location=no,center=yes,resizable=no');
mywin.focus();
}else{
alert('Please select atleast one record.');
}


Ashish_SFDCAshish_SFDC
Hi , 


How to create Task using Apex in Salesforce?
Sample Code:

    Task T = new Task();
    T.Type = 'Email';
    T.Description = ''; //string
    T.OwnerId = ''; //user id
    T.WhatId = ''; //record id
     insert T;


Regards,
Ashish
ECL47ECL47
Thanks for your response, but by question was how to pull/set the contact ids from the property view, not how to create the task - that functionality is already taken care of.