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
Luigi MontanezLuigi Montanez 

Accessing child-to-parent SELECT value from SOQL

Hi,

I have this SOQL query for an inline s-control:

SELECT Opportunity.Amount, Opportunity.Name, Opportunity.Id
FROM OpportunityContactRole WHERE ContactId = '{!Contact.Id}'
AND Role = 'Raiser' AND Opportunity.Amount <> 0


Assuming the query result is called queryResult, I want to sum up the Opportunity.Amount values using the following code:

total = 0
// assign the results of the query to an array.
records = queryResult.getArray('records');

// iterate over the results and sum the total.
for(var n in records) {
var opp = records[n];
//Add the current premium's amount to the running total.
total += opp.getFloat('Opportunity.Amount');
}

When I run this, I get the error: 'Unable to parse float field: Opportunity.Amount'

The last line works fine if I have a query dealing with only Opportunities and try to getFloat('Amount') instead of getFloat('Opportunity.Amount'). But something about the Opportunity.Amount part breaks getFloat(), and I don't know how to work around it.

Thanks in advance.

cheenathcheenath
I think it should be:

for(var n in records) {
  var
opportunityRole = records[n];
  var opp = opportunityRole.Opportunity;
  total += opp.getFloat('Amount');
}



Luigi MontanezLuigi Montanez
Makes sense. Thanks for the tip! I got it this way:

total += opp.Opportunity.getFloat('Amount');
MJDMJD

I am having similiar problem with a Javascript button on my task records

I am just trying to convert a customer number field to float or integer.

 

var T1 = task.getInt('Task.T1__c');  Gives me "unable to parse int: Task.T1__c"

var T1 = task.getInt("T1__c"); Gives me "unable to parse int: T1__c"

var T1 = task.getInt({!Task.T1__c}); Gives me "unable to parse int: 123" 123 is the value of the field. 

 

I get the same results using the getFloat. 

 

Help!