You need to sign in to do that
Don't have an account?
JWikk
list - convert to string?
is there a way to convert a list of sobjects into a string? I don't really care about the format, just that the field values can be string searched. Something like this:
List<sobject> pparcels = database.query('select ...'); String relatedMatches = pparcels.toString(); //toString doesn't exist if (relatedMatches.indexOf(affectedIds[i]) > -1) { ... }
I don't think there is a way to do this in a simple way.
But why are you trying to cast and entire list to a single String?
If it is for a search or something like that you can achieve it by soql or sosl.
Please provide more details about what you are trying to do to see if there is a better way to do this.
Ignacio.
I don’t understand the usage of converting list of Sobject to a string. It will be difficult for you to process later.
Salesforce use “;” as separator so you can do as given below :
String strSobjects = null;
for(int i=0;i<lstSobject.size();i++)
{
If(strSobjects == null)
{
strSobjects = lstSobject[i];
}
Else
{
strSobjects = strSobjects + “;”+lstSobject[i];
}
}
Hello,
I am trying to do the same but getting an error.
Illegal assignment from SOBJECT:priroty_wise_sla__c to String
My Apex class is
public class PWS {
List<priroty_wise_sla__c> results;
public priroty_wise_sla__c o{get;set;}
public PWS(ApexPages.StandardController stdcontroller) {
this.o= (priroty_wise_sla__c)stdController.getRecord();
}
public List<priroty_wise_sla__c> getResults() {
return results;
}
public PageReference dosearch()
{
results=[SELECT CUSTOMER_NAME__c,priority__c, Minute__c,hour__c,day__c from priroty_wise_sla__c where priority__c=:o.priority__c and CUSTOMER_NAME__c=:o.CUSTOMER_NAME__c];
String strSobjects = null;
for(integer i=0;i<results.size();i++)
{
strSobjects =results[i];
{
}
Else
{
strSobjects = strSobjects + ';'+results[i];
}
}
return null;
}
}
Suppose :
List<Sobject> scopeAcc = new ......(with values in it )
for(sObject so : scopeAcc)
{
System.debug('Scope check' + so);
String CA_id = so.id; // assignation
System.debug( 'sObject to String conversion : ' + CA_id ) ;
}
In case you never found the solution you can now use the JSON serialise method:
string JSONString = JSON.serialize(li_TurnoverTargetstoUpdate);
list<TurnoverTarget__c> li_TurnoverTargetstoUpdate = (list<TurnoverTarget__c>) JSON.deserialize(JSONString, list<TurnoverTarget__c>.class);
Very useful in passing a list of records from a trigger to a future method for updating
String temp = string.valueOf(o);