• Steve Max
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 3
    Replies

The following 2 classes are breaching governor limits.  Any ideas how I can reduce the number of rows returned at once while achieving the same result?

 

     private void RetrieveUserKPIData()
    {       
        //Retrieve the collection of USER_KPI Records
        //IMPLEMENT BATCH CREATION HERE AS REQUIRED
        for (   User_Month_KPI__c[] UserKPIs :
                                            [
                                            select  
                                                u.OwnerId,
                                                u.active_accounts_actual__c,
                                                u.APNrent_month_revenue_actual__c,
                                                u.revenue_new_accounts_actual__c,
                                                u.new_accounts_signed_actual__c,
                                                u.APN_Month__c,
                                                u.APN_Year__c,
                                                u.Month_Start_date__c,
                                                u.Month_End_date__c,
                                                u.avg_rev_per_account_actual__c,
                                                u.IPI_bookings_count__c,
                                                u.Id
                                            from    User_Month_KPI__c u
                                            where   u.APN_Year__c = :APNYear
                                            and     u.APN_Month__c = :APNMonth
                                            ] )
        {
            for (User_Month_KPI__c UserKPI : UserKPIs)
            {
                this.getCurrentSet().put(UserKPI.OwnerId,UserKPI);
                UserKPI.Month_Start_date__c = APNMonthStartDate;
                UserKPI.Month_End_date__c = APNMonthEndDate;
                
                Records++;
            }
        }
        
        CurrentSet=0;
    }


    public BulkAccountKPIs (UserKPICollectionClass pUKP)
    {
            pUKP.SetToStart();
            Map <Id,User_Month_KPI__c> KM;
            
            while ( (KM = pUKP.getCurrentSetIncrement()) !=  null)
            {
                Set<Id> UserIds = KM.keySet();
                
                for (Id Uid : UserIds)
                {
                    User_Month_KPI__c K = KM.get(Uid);
                    K.avg_rev_per_account_actual__c = 0;
                    K.Total_Number_Accounts__c = 0;
                    K.Total_Account_Revenue__c = 0;                    
                }
                
                for (Account[] accounts : [select
                                    t.Rating,
                                    t.OwnerId,
                                    t.Sales_Current_Month__c,
                                    t.CreatedDate,
                                    t.Active__c
                            from Account t
                            where t.OwnerId in :UserIds]
                            )
                {
                    for (Account account : accounts)
                    {
                        User_Month_KPI__c K = KM.get(account.OwnerId);
                        Processed++;
                        
                        K.Total_Number_Accounts__c++;                        
                        
                        if (account.Active__c == true)
                        {
                            TotalActive++;
                               TotalSalesCurrentMonth = TotalSalesCurrentMonth + account.Sales_Current_Month__c;
                            
                        }
            }
                }

                for (Id Uid : UserIds)
                {
                    User_Month_KPI__c K = KM.get(Uid);
                    if (K.Total_Number_Accounts__c != 0)
                    {
                        
                        K.avg_revenue_per_new_acc_actual__c = 0;
                        if (
                                   (K.revenue_new_accounts_actual__c > 0)
                                && (K.new_accounts_signed_actual__c >0)
                                && (K.revenue_new_accounts_actual__c != null)
                                && (K.new_accounts_signed_actual__c != null)
                            )
                         {
                            K.avg_revenue_per_new_acc_actual__c =
                                K.revenue_new_accounts_actual__c / K.new_accounts_signed_actual__c;
                         }
                         
                         K.avg_rev_per_account_actual__c = 0;
                        if (
                                    (K.APNrent_month_revenue_actual__c > 0)
                                && (K.APNrent_month_revenue_actual__c != null)
                            )
                         {
                            K.avg_rev_per_account_actual__c =
                                TotalSalesCurrentMonth / TotalActive;
                         }
                    }
                }
                
            }
    }

It won't work on updated code.  How do I refresh/reset the Deploy Wizard?

I have tried batching by filtering results by a range called "nameRange".  I can paste the code into the System Log window with some hard coded values for the dates, and it seems to work fine.  When I test in the Sandbox, I hit the query governor limit.  Any ideas?

 

 

 

        String[] nameRange = new String[]{'KT 045000','KT 050000','KT 055000','KT 060000','KT 065000'};
 
        For (Integer i=0; i < nameRange.size()-1;i++)
        {
            for (   User_Month_KPI__c[] UserKPIs :
                                                [
                                                select  
                                                    u.OwnerId,
                                                    u.active_accounts_actual__c,
                                                    u.APNrent_month_revenue_actual__c,
                                                    u.revenue_new_accounts_actual__c,
                                                    u.new_accounts_signed_actual__c,
                                                    u.APN_Month__c,
                                                    u.APN_Year__c,
                                                    u.Month_Start_date__c,
                                                    u.Month_End_date__c,
                                                    u.avg_rev_per_account_actual__c,
                                                    u.IPI_bookings_count__c,
                                                    u.Id
                                                from    User_Month_KPI__c u
                                                where   u.APN_Year__c = :APNYear
                                                and     u.APN_Month__c = :APNMonth
                                                and u.Name >= :nameRange[i]
                                                and u.Name < :nameRange[i+1]
                                                limit 500] )
            {   
                for (User_Month_KPI__c UserKPI : UserKPIs)
                {
                    this.getCurrentSet().put(UserKPI.OwnerId,UserKPI);
                    UserKPI.Month_Start_date__c = APNMonthStartDate;
                    UserKPI.Month_End_date__c = APNMonthEndDate;
                    
                    Records++;
                    
                        
                } // End FOR
                
            } // End FOR
            
        } // End FOR
        
        CurrentSet = 0;

Message Edited by Steve Max on 06-22-2009 04:43 PM

 I am trying to generate classes from a WSDL file produced by a vendor.  I get an error message when I try to generate classes from the WSDL code:

 

Error: Unable to find schema for element; {http://atex.com/StaticDataWebService/}NodeType

 

The WSDL file is too large to include in this message.  Any suggestions?

I am trying to call a third party Web Service.  I have generated Apex classes from a WSDL file.  I am getting the following error message:

External Account Number: Web service callout failed: Unexpected element. Parser was expecting element 'http://schemas.xmlsoap.org/soap/envelope/:Envelope' but found ':html'

I think it's because I am not persisting a cookie.  I got it working in VB.

The following VB code works

Sub Main()

Dim service As New Service

service.CookieContainer = New System.Net.CookieContainer

service.Login()

...

service.Logout()

End Sub

 

Here is the corresponding code in Java (using Apache Axis)

public static void main(String[] args)

{

UseSessionsServiceLocator locator = new UseSessionsServiceLocator();

locator.setMaintainSession(true);

ServiceSoap service = locator.getServiceSoap();

service.login();

...

service.logout();

}

 

How do I achieve this in Apex?  Below is what I have so far:

global class getAccountCyber {

     webservice static String getCyberAccount() {

          String exAccNo='Acme Hotel';

          try {

               AtexEnterpriseWeb.ServiceSoap ss = new AtexEnterpriseWeb.ServiceSoap();

               // I THINK I NEED A COOKIE OBJECT IN HERE! BUT WHICH ONE?

               ss.Login();

               // ...

               ss.Logout();

          } catch (exception e) {

               exAccNo = e.getMessage();

               System.debug(e.getMessage());

          }

     return exAccNo;

     }

}

 

Kind regards (and thanks in advance),

Max

 



Message Edited by Steve Max on 11-05-2008 09:12 PM

Message Edited by Steve Max on 11-05-2008 09:14 PM

Part of my code returns a list of opportunities that will often return > 500 rows. Not a problem, except when Itry to deploy the code, and the function is called in the test script, it fails because it breaks the test governor limits.

 

To avoid this seems to require a messy coding exercise to check if the code is running in a test scenario, and limit accordingly - is there an easier way I am missing to get past this problem?

For external webservice callouts there is a read timeout of 10 seconds. Is there a way to change this timeout?