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

JS Onclick Button: Query to update other child records? (Detail Page Button)
Is it possible to update multiple records from a detail page button with the help of a query? I know it's possible to do this with a list, but here's the scenario:
User recommends child record - changes a status and a boolean. Other child records also need to have their boolean(s) toggled to true. However, the button is on the detail page - NOT a list.
The following works great:
{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")} var newRecords = []; var thisP = new sforce.SObject("Proposal__c"); thisP.id = "{!Proposal__c.Id}"; thisP.Status__c = "Awarded"; thisP.test__c = true; newRecords.push(thisP); result = sforce.connection.update(newRecords); location.reload(true);
However, I'm trying to introduce this, where Ideally i'd like to update other child records (with the same parent (Order__c) lookup)
{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")} var newRecords = []; var otherP = sforce.connection.query("Select Id from Proposal__c where Order__c = '{!Proposal__c.OrderId__c}' "); otherP.test__c = true; newRecords.push(otherP); //Add all other records to array? var thisP = new sforce.SObject("Proposal__c"); thisP.id = "{!Proposal__c.Id}"; thisP.Status__c = "Awarded"; thisP.test__c = true; newRecords.push(thisP); //Add current detail page record to array result = sforce.connection.update(newRecords); location.reload(true);
Actually, I had posted this in the wrong board - I got much more clarification in the AJAX board - here is the working solution. This is targetted for a customer portal user - and there is a custom prefix in the URL (hence the need for the serverUrl line)
Basically, for all child records for the same parent, i want a boolean toggled upon click (including one that button click is originating from).
However, for ONLY the record where the button click is originating, I want a picklist value change.
All Answers
Hi tsalb,
This looks like a good candidate for an after update trigger written in Apex code. This code is not tested, so should have some bugs, but this is the general approach. Note the <TestField__c> in the code. I don't know what fields to compare to determine if the trigger should fire. I assume you don't want it to fire unless certain fields have changed.
In your js, are you certain that you are only returning a single object from your query?
Cheers,
Actually, I had posted this in the wrong board - I got much more clarification in the AJAX board - here is the working solution. This is targetted for a customer portal user - and there is a custom prefix in the URL (hence the need for the serverUrl line)
Basically, for all child records for the same parent, i want a boolean toggled upon click (including one that button click is originating from).
However, for ONLY the record where the button click is originating, I want a picklist value change.