0

I want to write a query that will return multiply of two fields. Is it possible?

// Aggregate Query to collect Sum of all Combinations of Brand Name and Reporting Groups.           
    List<AggregateResult> arrAllDaysCRsResult = [SELECT Sum(Relative_Date_Calculated__c) totalRewards, Brand_Name__c, Reporting_Group__c, Contractor__c FROM Contractor_Rewards__c 
                                        WHERE Brand_Name_Calculated__c in:brandNameSet AND Contractor__c in:contactsMap.keyset() // AND Reporting_Group__c in:reportingGroupSet
                                        group by Brand_Name__c, Reporting_Group__c, Contractor__c ];  

here is my soql query and i want Relative_Date_Calculated__c* TRANS_AMT__c

3
  • Please do not change your post so radically that it becomes a completely new question. Instead, accept the given answer and ask a new question, linking back to the old one for reference if it helps provide context.
    – Adrian Larson
    May 1, 2017 at 17:27
  • Hey Adrian..!! Thank you for Your suggestion, you have edited my question two times...Let me inform 1st and then edit it,so i can handle it on my own level. May 1, 2017 at 17:31
  • 1
    Turning your question into a completely different question is a bit of an abuse of the system. If you do so again it will just get rolled back (again). If you want to make minor edits, that's fine. But please do not ask a completely different question here when there is already an answer which has been well received.
    – Adrian Larson
    May 1, 2017 at 17:35

1 Answer 1

3

As far as I know, it is not possible to multiply fields in SOQL but would be glad to be wrong about that.

Workaround would be to create a formula field like num1num2Multiple which will multiply these two fields ( Relative_Date_Calculated__c* TRANS_AMT__c).

Now get this Formula field in SOQL.

SELECT num1num2Multiple FROM Contractor_Rewards__c 

You can remove this field from pagelayout if you do not want to show it on UI

9
  • hello samir..!! Thank you for the reply but i didn't get what is num1 and num2?? Did you mean Relative_Date_Calculated__cTRANS_AMT__c OR (Relative_Date_Calculated__cTRANS_AMT__c)Multiple.. can you please clear my doubt..Thank you. Apr 28, 2017 at 13:25
  • 1
    They are sample fields.Assume num 1 is Relative_Date_Calculated__c and num 2 is TRANS_AMT__c and num1num2Multiple is Relative_Date_Calculated__c* TRANS_AMT__c
    – Samir
    Apr 28, 2017 at 13:27
  • It is giving me the error , Unknown error parsing query Apr 28, 2017 at 13:29
  • 1
    You can not multiply two fields in the query
    – Samir
    Apr 28, 2017 at 13:34
  • 1
    You can reference your formula field Relative_Date_Calculated__c in new formula field.No need to make changed in your code.
    – Samir
    Apr 28, 2017 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.