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
MiddhaMiddha 

Circular Object Graph detected

Hi All, I have a webservice written in APEX which returns a complex object. This complext object is a List of Object which itself has another list of object. we can say 2D arrays.

 

While i am trying to consume it from a Java client it throws this error: 

 

"Circular Object Graph detected during serialization, you can not have circular object references in an Apex WebService response."

 

My class is: 

 

 

global class SampleService
{
    global class  ObjectFieldInformation
    {
        WebService Integer fieldSerialNumber;
    }
	
    global class  ObjectInformation
    {
        WebService List<ObjectFieldInformation> objectFieldInformationList;
    }
   
    
    global class CallsResponse
    {
        WebService List<ObjectInformation> callList;
        WebService String something;
    }

    WebService static CallsResponse getComplexObjects()
    {
    	FindCallsResponse  response = new FindCallsResponse();
        
        List<ObjectInformation> responseCallList =  new List<ObjectInformation>();
        ObjectFieldInformation objResultFieldInfo;
        ObjectInformation objCallInfo = new ObjectInformation();
        
        for(Integer i=0;i<5;i++)
        {	
               	List<ObjectFieldInformation> callData = new List<ObjectFieldInformation>();
		        for(Integer j=0;j<5;j++)
		        {	
	        		objResultFieldInfo = new ObjectFieldInformation();
		                callData.add(objResultFieldInfo);
		    	}
		    	
	        objCallInfo.objectFieldInformationList = callData;
	        responseCallList.add(objCallInfo);
        }	
    	 response.callList = responseCallList;
    	 return response;
    }
}

Please advise.

/G

 

 

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell

You have the same instance of objcallInfo inserted into the responseCallList array multiple times.

All Answers

SuperfellSuperfell

You have the same instance of objcallInfo inserted into the responseCallList array multiple times.

This was selected as the best answer
MiddhaMiddha

It worked Simon, Thank a lot.

ospehnerospehner

Hi All,

 

I have the same error in a, Apex webservice I developed. Can you show us what did you change in your code to fix this issue?

 

Thanks,

 

Olivier Spehner

 

 

ScreamScream

It's an ugly workaround, but you can call .clone() on the objects before you return them.

 

Putting the same object into a list twice really shouldn't be a crime, and clearly is not a "circular" reference.