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
THustonTHuston 

Update QueryResult MessageElement for QueryMore

How do I update the QueryResult in an SObject when I need to queryMore()?

I need to store the main SObject as my app queries and if the subSelect ! isDone then update the main SObject _any with the updated QueryResult.

 

essentially:

( (QueryResult)currentSObject.get_any()[loc].getObjectValue()).setRecords(qryR.getRecords());

 

I can't justoverwrite the ObjectValue as this throws a SOAPException

newME = existingME;
newME.setObjectValue(qryR);
newAny[loc] = newME;

 

 

Below seems to work to update the children, but then the values cannot be read back out.

The any element loses all the other settings.

 

currentSObject = getMainQueryRow(index);

MessageElement mel = sOB.get_any()[QRLocation];

if ( mel.getObjectValue().getClass().getSimpleName().equalsIgnoreCase( "QueryResult" ) ){

QueryResult qryR = (QueryResult) mel.getObjectValue();

if ( needMore ) {

//steps above are simplified to show how I got to the problem area

 

qryR = getQueryMoreQueryResult( qryR.getQueryLocator() );
MessageElement [] newAny = currentSObject.get_any();
MessageElement newME;
newME = new MessageElement("", mel.getName());
newME.setObjectValue( qryR );                                        
Element e = newME.getAsDOM();
e.removeAttribute("xsi:type");
e.removeAttribute("xmlns:ns1");
e.removeAttribute("xmlns:xsd");
e.removeAttribute("xmlns:xsi");
newME = new MessageElement(e);

                                       
newAny[QRLocation] = newME;

} }

Best Answer chosen by Admin (Salesforce Developers) 
THustonTHuston

sorted.

 

You just have to throw away the Children before you set the new QueryResult.

 

qryR = getQueryMoreQueryResult( qryR.getQueryLocator() );
MessageElement [] newAny = currentSObject.get_any();
MessageElement newME = currentSObject.get_any()[loc];
newME.removeContents();
newME.setObjectValue(qryR);

newAny[loc] = newME;