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

Troubleshooting help
I'm trying to write what I thought was a simple script to first search for some accounts meeting specified criteria and then update some fields on the contact objects that are related to those accounts. My code is not throwing errors, but also not updating the Contact fields. I'm hoping one of the experts here can easily spot something I've missed. Thanks in advance. It may not be much, but most everything I've learned about s-controls has come from this forumn. My code is below:
function updateObjects()
{
{
//query to get accounts associated with contacts
var queryResult = sforceClient.query("Select ID From Account where OwnerId = '{!$User.Id}' and Account_Status__c = 'Open'")
//move results into readable format
var account = queryResult.records[0];
var account = queryResult.records[0];
// assign attribs to variables
var sfaccount2 = account.get("ID");
var sfaccount = new Date ();
var sfaccount1 = "Active";
var sfaccount2 = account.get("ID");
var sfaccount = new Date ();
var sfaccount1 = "Active";
var queryResult2 = sforceClient.query("Select ID, Automated_Date__c, Automation_Status__c From Contact where AccountId = " + sfaccount2 + "")
//new array to hold results of updates
var updateObjects = new Array();
var updateObjects = new Array();
// go through list of lhaccounts to update sfaccounts
for (var i=0;i<queryResult2.size;i++)
{
var lhaccount = queryResult2.records[i];
lhaccount.set("Automated_Date__c", sfaccount);
lhaccount.set("Automation_Status__c", sfaccount1);
for (var i=0;i<queryResult2.size;i++)
{
var lhaccount = queryResult2.records[i];
lhaccount.set("Automated_Date__c", sfaccount);
lhaccount.set("Automation_Status__c", sfaccount1);
// push updated record into new array for update process
updateObjects.push(lhaccount);
}
updateObjects.push(lhaccount);
}
// submit new array with updated contacts
var saveResults = sforceClient.Update(updateObjects)[0];
parent.window.close();
}
var saveResults = sforceClient.Update(updateObjects)[0];
parent.window.close();
}
that could be your issue, if not, I am sure there are plenty of talented folks here that will spot other things...
Further below is my attempt to create 9.0 converted code. It doesn't work. I'm not sure what else I may be missing but I'm certain I cannot figure out what the initpage function is suppose to look like. Any help would be greatly appreciated.
Test Beta Code:
Attempt at converting to 9.0 Code:
Thanks for posting the code. However, I am still not getting exactly what you are trying to do. According to what you wrote you want to update a field on the account with the subject line from the most recent activity.
However, at no point do you go out to the tasks or events object to get a list of those activities.
So what I will do is provide a quick bit of code to at least get you querying for your accounts and displaying the results to the page. With this code you should be able to get pointed in the right direction.
Code:
and that will be executed on a click. The code should search the most recent task for each account, grab that
task's subject, and populate the Last Activity Subject field on the account. This code should update multiple
accounts with a single click and only show a pop-up window that will close when the code is done running. After
hours of reading documentation and piecing together pieces of code from you and others I have developed the
code below. It has two issues that I know about (but maybe more).
1) I'm having problems grabbing the Task Subject field with "var Subject=records.get("Subject");" How should I
be referencing a child field?
2) The code throws the following error in Firebug. Anyone know what is causing this error?:
uncaught exception: {faultcode:'sf:INVALID_FIELD', faultstring:'INVALID_FIELD: No such column 'Tasks' on entity
'account'. ', detail:{fault:{exceptionCode:'INVALID_FIELD', exceptionMessage:'No such column 'Tasks' on entity
'account'. ', row:'-1', column:'-1', }, }, }
_invoke("update", [Object name=sObjects value=[3] isArray=true], true, UNDEFINED, [Object ns=urn:partner.soap.
sforce.com, Object ns=sobject.partner.soap.sforce.com prefix=ns1], "/services/Soap/u/9.0", "urn:partner.soap.
sforce.com", "sobject.partner.soap.sforce.com")
My Code:
<html>
<head>
<script src="/soap/ajax/9.0/connection.js"></script>
<script src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js" type="text/javascript"></script>
<script language="javascript">
function do_code()
{
var qrdr = sforce.connection.query("SELECT Id, Last_Activity_Subject__c, Name, (SELECT Id, Subject FROM
Tasks order by ActivityDate desc limit 1) FROM Account where Account_Status__c = 'Automated' and
OwnerID = '{!$User.Id}'");
var updateObjects = new Array();
for (var i = 0; i < qrdr.getArray("records").length; i++)
{
var records = qrdr.records[i];
var Subject=records.get("Subject");
records.set("Last_Activity_Subject__c", Subject);
updateObjects.push(records);
}
var saveResults = sforce.connection.update(updateObjects)[0];
parent.window.close();
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body onLoad="do_code();">
</body>
</html>
Okay. I believe I understand what you're trying to do. Your code has some errors and I don't know if the code I have below will work but it should get you close.
Code:
In order to troubleshoot, I added some stuff to display the results of the save request in the popped window. When you get this to work you can simply call the window.close() function and eliminate that code.
syntax you used in the many examples I've seen and it all seems to work great. For those following at
home I just had to tweak sforce.connection.Update to sforce.connection.update. There is still one issue.
In line:
accountUpdate.General_Notes__c = sqlResults[i].Subject;
The code just does not seem to recognize Subject because it is part of the child query. If I replace it
with a field from the parent portion of the query it works fine. I put alerts on alert(sqlResults) and it
shows that the variable is grabbing the children fields. However, the alert(sqlResults[i].Subject) says that
sqlResults[i].Subject is undefined. I've tried sqlResults[i].Task.Subject and sqlResults[i].Tasks.Subject
but neither worked.
Any ideas?