function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sean_kSean_k 

Apex Select Query

Hi,
I developed a small method using Apex to query opportunity object based on account id.
Apex class looks like the following
 
global class OpportunityInfo
{
 webService static Opportunity[] getOpportunityInformation(String accountId)
 {
  Integer x=0;
  Opportunity[] opportunityResults = new Opportunity[]{};
  for(Opportunity[] oppArray : [Select o.Name, o.Close_Date__c, o.OwnerId, o.Owner.Name from Opportunity o where o.AccountId = :accountId order by  o.Close_Date__c desc LIMIT 10000])
  {
   for (x=0; x < oppArray.size(); x++)
   {
    opportunityResults.add(oppArray[x]);
   }
  }
  System.debug('getOpportunityInformation web service found [' + opportunityResults.size() + '] Opportunity records ');  
  return opportunityResults; 
 }
 static testMethod void getOpportunitiesTest() {
  getOpportunityInformation('0017000000Lfw1sAAB');
 }
}
 
when I run the UnitTest using the RunTest button, It says the query got 0 records. But there few Opportunities for this Account.
Here are the test results:
 
 *** Beginning Test 1: OpportunityInfo.static testMethod void getOpportunitiesTest()
20080109204034.774:Class.OpportunityInfo.getOpportunityInformation: line 9, column 6: SelectLoop:LIST:SOBJECT:Opportunity
20080109204034.774:Class.OpportunityInfo.getOpportunityInformation: line 9, column 35: SOQL query with 0 rows finished in 8 ms
20080109204034.774:Class.OpportunityInfo.getOpportunityInformation: line 16, column 6: getOpportunityInformation web service found [0] Opportunity records
20080109204034.774:Class.OpportunityInfo.getOpportunitiesTest: line 22, column 9: returning LIST:SOBJECT:Opportunity from method webService static LIST:SOBJECT:Opportunity getOpportunityInformation(String) in 9 ms
20080109204034.774:Class.OpportunityInfo: line 20, column 28: returning from end of method static testMethod void getOpportunitiesTest() in 9 ms
Cumulative resource usage:
Resource usage for namespace: (default)
Number of SOQL queries: 1 out of 100
Number of query rows: 0 out of 500
Number of DML statements: 0 out of 100
Number of DML rows: 0 out of 500
Number of transaction control statements: 0 out of 0
Number of script statements: 6 out of 200000
Maximum heap size: 0 out of 500000
Number of callouts: 0 out of 10
Number of Email Invocations: 0 out of 10
Total email recipients queued to be sent : 0
*** Ending Test OpportunityInfo.static testMethod void getOpportunitiesTest()
 
This code is tested in Enterprise Edition(Sandbox).
I tested In Developer Edition this works fine
 
Is there anything I am missing in EE?
 
Thanks,
Sean
 
 


Message Edited by Sean_k on 01-09-2008 01:45 PM
Vijay RautVijay Raut
Hi,

I think, the Account Id which you have passed in your test method, is Account Id from your developer org (Hence working on dev).

But on EE, you might not having record with that Id. Hence it returning you zero opportunitity.

Regards
V.R.