1
public static List <Pricing_Lookup__c> getGrandTotal(){

    List<Pricing_Lookup__c> calculateTotal = [Select Name, (Select Name, Unit_Price__c From Activity_Lookup__r) From Pricing_Lookup__c ORDER BY Name ASC];

    Pricing_Lookup__c pricingLookup = new Pricing_Lookup__c();
    pricingLookup.Name = null;

    String[] pricinglookupName = new string[] {};

        for ( Pricing_Lookup__c activityTotal : [Select Name, (Select Unit_Price__c From Activity_Lookup__r) from Pricing_Lookup__c ORDER BY Name ASC] ){


            system.debug(activityTotal);

        }



    return null;
}

I'm trying to add up activitylookup's unit_price belong to PricinglookUp's Name and display it on existing dataTable.

I was able to get Name from pricinglookup and unitPirce from activitylookup.

But I'm not sure how to add unitpirces. (cant figure out syntax for unitpirce..)

Thanks in advance.

1

Follow this approach to sum up the Unit Prices

public static List <Pricing_Lookup__c> getGrandTotal(){

    List<Pricing_Lookup__c> lstPricing = [Select Name, (Select Name, Unit_Price__c From Activity_Lookup__r) 
        From Pricing_Lookup__c ORDER BY Name ASC];
        Decimail totalAmount = 0;
        for (Pricing_Lookup__c objPricing: lstPricing ){
            for(Activity_Lookup__c lookupObj : objPricing.Activity_Lookup__r)
            {
                totalAmount = totalAmount + lookupObj.Unit_Price__c;
            }            
        }

    return null;
}
  • Worked perfectly!!! Thank you!! @Santanu Boral – Logan H Aug 22 '18 at 8:44
0
    public static List <Pricing_Lookup__c> getGrandTotal(){

        List<Pricing_Lookup__c> calculateTotal = [Select Name, (Select Name, Unit_Price__c From Activity_Lookup__r) From Pricing_Lookup__c ORDER BY Name ASC];

        Pricing_Lookup__c pricingLookup = new Pricing_Lookup__c();
        pricingLookup.Name = null;

        String[] pricinglookupName = new string[] {};

            for ( Pricing_Lookup__c activityTotal : [Select Name, (Select Unit_Price__c From Activity_Lookup__r) from Pricing_Lookup__c ORDER BY Name ASC] ){
                 for(Activity_Lookup__c a :activityTotal.Activity_Lookup__r ){
               //add Unit Price here 

             }

            }



        return null;
    }
  • thanks @vignesh I added this code, but im getting illegal conversion from integer to list and issue with the variable..., integer actTotal = 0; String[] pricinglookupName = new string[] {}; for ( Pricing_Lookup__c activityTotal : [Select Name, (Select Unit_Price__c From Activity_Lookup__r) from Pricing_Lookup__c ORDER BY Name ASC] ){ for(Activity_Lookup__c a :activityTotal.Activity_Lookup__r ){ actTotal = actTotal + Unit_Price__c; } return actTotal; } – Logan H Aug 22 '18 at 8:24

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.