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
TotalNoviceTotalNovice 

Custom button to update calc field

My goal is to calculate seats left for a class by subtracting number of registered enrolees from facility capacity.
 
Can I use following code in S-Control (Javascript snippet) to attach it to a custom button which will update Seats Left field on the class page?
 
<SCRIPT language="javascript">
SforceCommand cmd = new SforceCommand("select Count(distinct Contact__c) from SFDC_Enrollment__c where Class__c =" + {!SFDC_Class__c.Id}+ " AND Status__c = 'Registered'");
int ret = cmd.ExecuteQuery();
cmd.Text = "update SFDC_Class__c Set Seats_Available__c = Max_Capacity__c - " + ret + " where Class__c = " + {!SFDC_Class__c.Id};
cmd.ExecuteNonQuery();
</SCRIPT>
DevAngelDevAngel
Wow, so that's what soql would look like in ado!

SOQL only supports query.  The ajax toolkit can what you want, but you'll have to adhere to the semantics of the Apex API and not, unfortunately, the ADO api.

Cheers