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
Lisa SeldenLisa Selden 

Custom Buttom to Log Activity for All Contacts in Account

Hello, I am trying to create a custom button for all contacts in an account. I have the code below but this is calling for apex which is not a feature for my organization. Can this be written for Javascript? Thanks in advance! 


01{!REQUIRESCRIPT("/soap/ajax/34.0/connection.js")}
02{!REQUIRESCRIPT("/soap/ajax/34.0/apex.js")}
03 
04var url = '/{!Account.Id}';
05 
06var myquery = "Select Id, Name from Contact Where AccountId = '{!Account.Id}'";
07result = sforce.connection.query(myquery);
08records = result.getArray("records");
09 
10var taskArr = [];
11for(var i=0; i < records.length;i++)
12{
13var task = new sforce.SObject("Task");;
14task.WhoId = records[i].Id;
15task.WhatId = '{!Account.Id}';
16taskArr.push(task);
17}
18 
19var results = sforce.connection.create(taskArr);
20if (results[0].getBoolean("success")) {
21window.parent.open(url, "_self");
22} else {
23alert("Failed to create Task " + results[0]);
24}
Daniel BallingerDaniel Ballinger
What Organisation type do you have? You might find you are limited in Javascript functionality as well.