You need to sign in to do that
Don't have an account?
Sobject Query
how to get the each field vlaue .when we are using the sobject
hi here am getting the values of an object but i want only one field value
how can get only one fileld using the soject.
and i want that field to update another string
By using the id we have got the object name and getting all the field valuees
accId = '001900000092EV2';
String prefix= accId.subString(0,3);
String objectName = objectMap.get(prefix);
system.debug('&&&&&&&'+objectName);
Map<String, Schema.SObjectField> desResult = Schema.getGlobalDescribe().get(objectName).getDescribe().Fields.getMap();
system.debug('desResult '+desResult );
List<String> fieldList = new List<String>();
system.debug('fieldList '+fieldList );
fieldList.addAll(desResult.keySet());
for(integer i =0;i<fieldList.size();i++)
System.debug(fieldList[i]);
String Query = 'SELECT ';
for(integer i =0;i<fieldList.size();i++)
Query += fieldList.get(i) + ',';
Query = Query.subString(0,Query.length()-1);
system.debug('+++++++++++'+query);
Query += ' FROM ' + objectName ;
query += ' WHERE ID= \''+ID+'\''; // modify as needed
sobject s1= Database.Query(Query);
system.debug('*&&&&&&&&&*'+s1);
you're using a describe method to get all fields, if you only want a limited selection of fields, you can use a basic soql select statement as "Select field from sobject"
to assign a field value from your result object to a string variable :
string X = s1.FIELDNAME;
This is pretty basic apex, if you're having thouble with these things, you may want to consider going through the apex workbook