• Hiline
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 2
    Replies
I'm trying to show the sorted aggregate results on a VF page.  One of the wrapper class properties "SipPct" is calcuated by using the two aggregate result fields.  Is there an way to sort the results by "SipPct"?   Below is controller code:

<pre>
public with sharing class TestController {
    public Summary[] Summaries { get; set; }
    public TestController() {
        AggregateResult[] results = [
            SELECT Opportunity.Owner.Name, Avg(Opportunity.Owner.SIP__c), sum(TotalPrice)
            FROM OpportunityLineItem
            WHERE Opportunity.CloseDate = THIS_YEAR and
            Group by Opportunity.Owner.Name
        ];
        Summaries = new List<Summary>();
        for (AggregateResult ar : results) {
            Summaries.add(new Summary(ar));
        }
      
    }

    // wrapper class to hold aggregate data
    public class Summary {
        public Double Sip { get; private set; }
        public String Name { get; private set; }
        public Double TotalPrice { get; private set; }
        public Double SipPct { get; private set; }

        public Summary(AggregateResult ar) {
            Name = (String) ar.get('Name');
            Sip = (Double) ar.get('expr0');
            TotalPrice = (Double) ar.get('expr1');
            SipPct = TotalPrice / Sip;
        }
  }
}
</pre>
  • December 26, 2013
  • Like
  • 0

Hello,

 

I have two custom lookup fields in my Case object:  User_Contact__c (User lookup)  and Opportunity_Name__c (Opportunity lookup).  I wrote a trigger to update the User_Contact__c to the Opportunity owner ID from the  Opportunity_Name__c field.  Below is my trigger code:

 

trigger Case_OpptyAttached on Case (before insert, before update) {
    
    for (case c : trigger.new) {
    
        if (c.User_Contact__c != c.Opportunity_Name__r.OwnerId) {
        
            c.User_Contact__c = c.Opportunity_Name__r.OwnerId;
        }
    }
}

 

 

When I update the case record, the custom User lookup field is blank.  Is my apex syntax incorrect?

 

Thank you so much.

 

David

  • September 13, 2012
  • Like
  • 0

Hello,

I'm trying to create trigger on the Opportunity object to update the child Opportunity Product records with the Opportunity Owner's department number, which is one of the fields in the User object.  I'm getting the following compile error:

 

Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST<OpportunityLineItem> at line 24 column 14

 

Here's the code I have.

trigger OpportunityUpdateDept on Opportunity (after update) {
    
    for( Opportunity parent: Trigger.new)
    {
    
        List<OpportunityLineItem> children = [ SELECT Department_Number__c from 
                                               OpportunityLineItem where Opportunity.id = :parent.Id];

        list <User> currentOwner = [Select User.Department_Number__c
                                            from User
                                            where User.id = :parent.ownerid];                                                       
        
        List<OpportunityLineItem> childrenToUpdate = new List<OpportunityLineItem>();
        
        for(OpportunityLineItem thischild: children )
        {
           if( thischild.Department_Number__c !=  currentOwner[0].Department_Number__c)
           {
               thischild.Department_Number__c =  currentOwner[0].Department_Number__c;
               childrenToUpdate.add(thischild);
           }
        }
        
        if( !childrenToUpdate.isEmpty)
        {
           update childrenToUpdate;
        }
    
    }                       
}

 

I'm not exactly sure what is causing the error.  If I remove the if statement that checks if childrentToUpdate.isEmpty, then it works.  But I want to be able to skip the update if its not necessary.  Any assistance with this issue is very much appreciated.

 

Thanks!

Hi, I'm new to apex.  I was wondering if there is way to use an apex trigger to change the way Salesforce amortizes revenue.  For example, if an opportunity product revenue is entered for $6800 for a 12 month period, it will automatically allocate $566.00 for each month, and load the remainder in the 12th month.  However, what I would prefer is that its broken down evenly with decimals as $566.66 for the first 11 months, and the final month gets the extra change ($566.74).

 

Would this be possible to achieve with an apex trigger?  Any assistance on this matter is greatly appreciated.

Hello,

 

I have two custom lookup fields in my Case object:  User_Contact__c (User lookup)  and Opportunity_Name__c (Opportunity lookup).  I wrote a trigger to update the User_Contact__c to the Opportunity owner ID from the  Opportunity_Name__c field.  Below is my trigger code:

 

trigger Case_OpptyAttached on Case (before insert, before update) {
    
    for (case c : trigger.new) {
    
        if (c.User_Contact__c != c.Opportunity_Name__r.OwnerId) {
        
            c.User_Contact__c = c.Opportunity_Name__r.OwnerId;
        }
    }
}

 

 

When I update the case record, the custom User lookup field is blank.  Is my apex syntax incorrect?

 

Thank you so much.

 

David

  • September 13, 2012
  • Like
  • 0

Hello,

I'm trying to create trigger on the Opportunity object to update the child Opportunity Product records with the Opportunity Owner's department number, which is one of the fields in the User object.  I'm getting the following compile error:

 

Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST<OpportunityLineItem> at line 24 column 14

 

Here's the code I have.

trigger OpportunityUpdateDept on Opportunity (after update) {
    
    for( Opportunity parent: Trigger.new)
    {
    
        List<OpportunityLineItem> children = [ SELECT Department_Number__c from 
                                               OpportunityLineItem where Opportunity.id = :parent.Id];

        list <User> currentOwner = [Select User.Department_Number__c
                                            from User
                                            where User.id = :parent.ownerid];                                                       
        
        List<OpportunityLineItem> childrenToUpdate = new List<OpportunityLineItem>();
        
        for(OpportunityLineItem thischild: children )
        {
           if( thischild.Department_Number__c !=  currentOwner[0].Department_Number__c)
           {
               thischild.Department_Number__c =  currentOwner[0].Department_Number__c;
               childrenToUpdate.add(thischild);
           }
        }
        
        if( !childrenToUpdate.isEmpty)
        {
           update childrenToUpdate;
        }
    
    }                       
}

 

I'm not exactly sure what is causing the error.  If I remove the if statement that checks if childrentToUpdate.isEmpty, then it works.  But I want to be able to skip the update if its not necessary.  Any assistance with this issue is very much appreciated.

 

Thanks!