You need to sign in to do that
Don't have an account?

Counting the number of Events, then populating field on custom object
Hello,
This is my first post. I have a custom object, and I need to count the number of events attached to the custom object and update the event count on the custom object. Is this possible using an s-control? I have limited programming experience, but can understand code. I appreciate your help in advance.
This is my first post. I have a custom object, and I need to count the number of events attached to the custom object and update the event count on the custom object. Is this possible using an s-control? I have limited programming experience, but can understand code. I appreciate your help in advance.
Yes this is possible.
I would reccomend using the AJAX library from SFDC.
It will require that you can program in Javascript. You will need to perform a query looking for tasks and/or events with the "whatID" set to the "ID" of your custom object. Then count the results. If you are not yet a programmer this might be an opportunity to get into some code.
If you want to, please feel free to download the (free) Developer's Side Kick and have a look on the Schema Explorer - this will help you to see what fields relate the Task to your custom object (It'll probably be the WhatID). You can test this using the Datascope if you like, there is a free 14 day trial for that.
Good luck
Gareth.
If I can get the right records in the dynabean, then do a dynabean.length(array) I can write the contents of an array to a custom field on the test object record. Am I completely off-base?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script language="javascript" src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js" type="text/javascript"></script>
<script>
<!--
function initPage() {
sforceClient.registerInitCallback(setup);
sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_70}", true);
}
//Use this function as the entry point for your DHTML and JAVASCRIPT processing
function setup() {
var queryResult = sforceClient.query("Select Id FROM Event WHERE WhatId = '!Test_Object__c_Id', layoutResults);
}
function layoutResults(queryResult) {
if (queryResult.className == "Fault") {
alert("There was an error: " + queryResult.toString());
} else {
if (queryResult.size > 0) {
var output = "";
for (var i=0;i<queryResult.records.length;i++) {
var dynaBean = queryResult.records[i];
output += dynaBean.get("Id") + " " <br>";
}
var textNode = document.createTextNode(output);
document.getElementById("output").innerHTML = output;
} else {
var textNode = document.createTextNode("No records matched.");
}
}
}
//-->
</script>
</head>
<body onload="initPage()">
<div id="output"></div>
</body>
</html>
Code:
Just quickly looking at it I notice that you are missing the "{}" around !Test_Object__c_Id in the query.
-wkuehler