• LaceySnr
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

Hey Guys,

 

I'm trying to work out how I can return an array of a class in a webservice, I know I can do lists / arrays of sobjects and standard types, but if I have a class such as:

 

 

	global class CObject
	{
		string	ObjectName;
		double	Value;
	}

And I try and return a class which includes a list/array of those:

 

 

	global class GetObjectResult
	{
		webservice integer					NumResults;
		webservice boolean					Error;
		webservice string					ErrorMessage;
		webservice list<CObject>			        Objects;
		
		global GetObjectResult()
		{
			NumResults = 0;
			Error = false;
			ErrorMessage = '';
			Objects = new list<CObject>();
		}
	}

 

The web service method being:

 

	webservice static GetObjectResult GetObject(GetObjectRequest req)
	{
		GetObjectResult res = new GetObjectResult();
		
		
		if(req == null)
		{
			res.ErrorMessage = 'Invalid request.';
			res.Error = true;
			return res;
		}
		
		if(req.ObjectName == null)
		{
			res.ErrorMessage = 'ObjectName can not be null.';
			res.Error = true;
			return res;
		}
		
		string strNameMatch = '%' + req.ObjectName + '%';
		
		for(Basic_Object__c sObj : [select	Id, Name__c, Value__c
						from	Basic_Object__c
						where	Name__c like : strNameMatch
						limit	100])
		{
			CObject obj = new CObject();
			obj.ObjectName = sObj.Name__c;
			obj.Value = sObj.Value__c;
			res.Objects.add(obj);
		}

		res.NumResults = res.Objects.size();
		
		return res;
	}

 

 

Then I only get the name of the array / list member variable repeated n times:

 

 

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://soap.sforce.com/schemas/class/IPhoneWebServices">
   <soapenv:Body>
      <GetObjectResponse>
         <result>
            <Error>false</Error>
            <ErrorMessage/>
            <NumResults>3</NumResults>
            <Objects/>
            <Objects/>
            <Objects/>
         </result>
      </GetObjectResponse>
   </soapenv:Body>
</soapenv:Envelope>

 

Anyone know of a way to actually show my fields and values?

 

Cheers :)

 

Hey Guys,

 

I'm trying to work out how I can return an array of a class in a webservice, I know I can do lists / arrays of sobjects and standard types, but if I have a class such as:

 

 

	global class CObject
	{
		string	ObjectName;
		double	Value;
	}

And I try and return a class which includes a list/array of those:

 

 

	global class GetObjectResult
	{
		webservice integer					NumResults;
		webservice boolean					Error;
		webservice string					ErrorMessage;
		webservice list<CObject>			        Objects;
		
		global GetObjectResult()
		{
			NumResults = 0;
			Error = false;
			ErrorMessage = '';
			Objects = new list<CObject>();
		}
	}

 

The web service method being:

 

	webservice static GetObjectResult GetObject(GetObjectRequest req)
	{
		GetObjectResult res = new GetObjectResult();
		
		
		if(req == null)
		{
			res.ErrorMessage = 'Invalid request.';
			res.Error = true;
			return res;
		}
		
		if(req.ObjectName == null)
		{
			res.ErrorMessage = 'ObjectName can not be null.';
			res.Error = true;
			return res;
		}
		
		string strNameMatch = '%' + req.ObjectName + '%';
		
		for(Basic_Object__c sObj : [select	Id, Name__c, Value__c
						from	Basic_Object__c
						where	Name__c like : strNameMatch
						limit	100])
		{
			CObject obj = new CObject();
			obj.ObjectName = sObj.Name__c;
			obj.Value = sObj.Value__c;
			res.Objects.add(obj);
		}

		res.NumResults = res.Objects.size();
		
		return res;
	}

 

 

Then I only get the name of the array / list member variable repeated n times:

 

 

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://soap.sforce.com/schemas/class/IPhoneWebServices">
   <soapenv:Body>
      <GetObjectResponse>
         <result>
            <Error>false</Error>
            <ErrorMessage/>
            <NumResults>3</NumResults>
            <Objects/>
            <Objects/>
            <Objects/>
         </result>
      </GetObjectResponse>
   </soapenv:Body>
</soapenv:Envelope>

 

Anyone know of a way to actually show my fields and values?

 

Cheers :)