Scenario: I am working on a button which should create a new Sprint__c child record with Record Type "Sprint Deployment" which will be automatically linked (via lookup) to the Sprint__c record that I pressed the button from, which is a standard "Sprint" Record Type.
The Kicker: I want to auto-generate the name of the new child record to contain the child record number, based on how many child records already exist for that parent. (Example: If there are already 5 child records on the parent record, I want to name the new record "Sprint Deployment 6" (5 being the current, +1 for the new).
I am attempting this by:
SOQL Querying the RecordType "Sprint Deployment" for the Sprint__c Object (limit 1), and then getting the Id of item [0] in the array. I am doing this via SOQL Query so that the button will work between Orgs without modification. (This works as expected and returns the RecordTypeId into the 'recordType' variable.
SOQL Querying the Sprint__c object WHERE RecordTypeId =
recordType
variable and Related_To__c (lookup) =sprintId
variable.
I am receiving the following error when pressing the button:
missing ) after argument list
From my Stack searches, I am aware that this is generally a syntax error commonly caused by not escaping " or ' characters, but I have tried to escape them in various different ways and keep coming up with the same error. Can someone please help me with the correct syntax for this query?
Query where Error Occurs:
var deploymentQuery = sforce.connection.query("SELECT Id FROM Sprint__c WHERE RecordTypeId = '"+recordType"' AND Related_To__c = '"+sprintId"'");
Full Code Snippet as it exists currently (lots of alerts for debug) and incomplete code since this error is blocking me:
{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/22.0/apex.js" )}
var connection = sforce.connection;
var newSprint = new sforce.SObject("Sprint__c");
var recordTypeQuery = sforce.connection.query("SELECT Id FROM RecordType WHERE Name = 'Sprint Deployment' AND SObjectType = 'Sprint__c' limit 1");
var recordTypeQueryResult = recordTypeQuery.getArray("records");
var recordType = recordTypeQueryResult[0].Id;
var sprintId = "{!Sprint__c.Id}";
var deploymentQuery = sforce.connection.query("SELECT Id FROM Sprint__c WHERE RecordTypeId = '"+recordType"' AND Related_To__c = '" +sprintId"'");
alert(deploymentQuery);
var deploymentQueryResult = deploymentQuery.getArray("records");
alert(deploymentQueryResult);
var deploymentQueryLength = deploymentQueryResult.length;
alert(deploymentQueryLength);