+ Start a Discussion
SurpriseSurprise 

Apex problem

Hi All,

Below given is the simple web service.This web service has been written in apex and I am calling it from Apex as I am working on two salesforce orgs.I am calling getMessage () from my org and passing opportunity name as parameter and method queries salesforce database and then return the fetched record.Uptill now it has worked fine and it works fine with one record.It generated an esception that list has more tham one row for assignement.How do I make it work with multipe records.How do I send more than one record as return value to the calling method.Can somebody please help.

 

 

 

global class Greatone  
{  
//set<string> p=new set<string>();
    WebService static String GetMessage(string msg)  
    {  
      string g;
    
       //list<string> g =new list<string>();
       opportunity opp=[select id,name from opportunity where name=:msg];
       g=string.valueof(opp);     
          
        //for(opportunity last:opp)
         //{
         
         //g=string.valueof(opp);     
         //p.add(g);
                  
         //}
         return g;  
    }
     
   
}

Marko LamotMarko Lamot

Use

List<Opportunity> opp=[select id,name from opportunity where name=:msg];

instead of  Opportunity opp=... 

 

SurpriseSurprise

Thanks Marklamot,

 

My problem was more around how to return more than one record to the calling apex code.So that has been  resolved.I have used your suggestion and it worked.

 

From salesforce to salesforce ,Can I send list of records as arguments to the called webservcie or  is it possible that the called webservice returns a set or list of records to the called webservice.

 

 

Thanks Surprise.