+ Start a Discussion
SurpriseSurprise 

Apex and web services

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;  
    }
     
   
}

Mohith Kumar ShrivastavaMohith Kumar Shrivastava
global class Greatone  {  

    WebService static String GetMessage(string msg){  
    
     List <Id> oppIds=new List <Id> ();

       List<opportunity> opp=[select id,name from opportunity where name=:msg ];  
          
        for(opportunity last:opp) {
         oppIds.add(last.id);
       }
         return oppIds;  
    }
     
   
}

 This must work correctly.You can also use map query for more optimization of the code