You need to sign in to do that
Don't have an account?
Too many script statements: 200001 - URGENT have to release app in a week.
Hi,
I have hit yet another roadblock while developing an app in flex thats calling a webservice method in my apex class.
In my webservice method I am
- getting unique ids for contacts. and
- based on those ids getting contacts and accounts and opps
I am hitting the limit for too many script statements executed and over here my date params are just for 3 months.
Is there a way to overcome this limit or can this be further refactored (if possible - just point me in the right direction) or if theres another alternative way to appraoch this.
Any help would be greatly appreciated
heres my code for the webservice method :
Webservice static List<GenericObject> getConAccOpps(String startDateString , String startMonthString , String startYearString, String endDateString , String endMonthString , String endYearString , String scoreThreshold) { List<GenericObject> result = new List<GenericObject>(); setDates(startDateString , startMonthString , startYearString, endDateString , endMonthString , endYearString); //List<Key_Event__c> conKEs = new List<Key_Event__c>(); List<String> contactIds = getUniqueContactIds(); List<String> accountIds = new List<String>(); Map<String , Account> accMap = new Map<String , Account>(); For(Contact con : [Select c.Appt_Scheduled_Date__c, c.OwnerId,c.AccountId, c.Email, c.Phone, c.HasOptedOutOfEmail, c.Account.Name, c.Contact_Status__c,c.Title_type__c , c.Id, c.Key_Events_Total_Score__c,c.Title, c.MailingPostalCode, c.Webinar_Date__c, c.Account.Annual_Revenue_Range__c, c.Webinar_Status__c ,c.Account.Type,c.MailingState, c.Name from Contact c Where c.Id IN : contactIds And c.Key_Events_Total_Score__c >=: Integer.valueOf(scoreThreshold) Order by Contact_Status__c]) { if(accMap.get(con.AccountId) == null) { accMap.put(con.AccountId, con.Account); accountIds.add(con.AccountId); } result.add(new GenericObject(con,null,null)); } System.debug('DML statements ' + Limits.getDmlStatements()); if(accountIds.size() > 0) { System.debug('num of acc ids :' + accountIds.size()); For(Account acc : [Select a.OwnerId,a.Owner.Name, a.Second_Account_Owner__c, a.Second_Account_Owner__r.Name, a.Id, a.Annual_Revenue_Range__c,a.Key_Event_Score__c,a.BillingPostalCode, a.BillingState, a.Industry, a.Name, a.Type, (Select AccountId, CreatedDate, Field, NewValue, OldValue From Histories Where CreatedDate >=: startDate And CreatedDate <=: endDate And Field =: 'Type' Order By CreatedDate DESC) from Account a where a.Id IN : accountIds]) { result.add(new GenericObject(null,acc,null)); } For(Opportunity oppObject : [Select o.AccountId,o.Account.Name, o.RecordTypeId,o.RecordType.Name, o.Name, o.Total_Amount__c,o.Amount, o.License_Amount__c, o.Maintenance_Amount__c,o.Professional_Services_Amount__c, o.Total_Licence_Amount__c, o.Total_Maintenance_Amount__c, o.Total_Services_Amount__c, o.Type ,o.Account.Type,o.OwnerId,o.Owner.Name,o.PROPHIX_Stage__c,o.StageName,o.CloseDate,o.CreatedDate from Opportunity o where o.AccountId IN : accountIds]) { result.add(new GenericObject(null,null,oppObject)); } } return result; } private static List<String> getUniqueContactIds() { List<String> uniqueIds = new List<String>(); Map<String,Key_Event__c> uniqueContactsMap = new Map<String , Key_Event__c>(); For(Key_Event__c obj :[Select k.Contact__c, k.CreatedDate, k.Id, k.Lead_Created_Date__c, k.Name from Key_Event__c k Where k.Lead_Created_Date__c >= : startDate And k.Lead_Created_Date__c <= : endDate]) { //keyEvents.add(obj); if(uniqueContactsMap.get(obj.Contact__c) == null) { uniqueContactsMap.put(obj.Contact__c, obj); uniqueIds.add(obj.Contact__c); } } return uniqueIds; }