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

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);
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 );


for(integer i =0;i<fieldList.size();i++)

String Query = 'SELECT ';
for(integer i =0;i<fieldList.size();i++)
Query += fieldList.get(i) + ',';

Query = Query.subString(0,Query.length()-1);
Query += ' FROM ' + objectName ;
query += ' WHERE ID= \''+ID+'\''; // modify as needed

sobject s1= Database.Query(Query);



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