Hi I am having an Sobject list. While iterating through the Sobject list using FOR loop, I can only able to get the Id not all the fields of the Sobject. Can someone please help me to solve the issue.
Code:
String objectFields = 'AccountShare';
String recordId = 'AccountId';
String object1= 'AccountAccessLevel,AccountId,CaseAccessLevel,ContactAccessLevel,Id,IsDeleted,LastModifiedById,LastModifiedDate,OpportunityAccessLevel,RowCause,UserOrGroupId' ;
String str1= 'Select '+objectFields+' from '+object1+' where '+recordId+' = :nameValue ';
List<Sobject> sobjList = Database.query(str1);
for(Sobject sobj :sobjList ){
String s1=sobj.Id; // **working fine**
String S2= sobj.accountId; // **Error objectLists Compile Error: Field expression not allowed for generic SObject**
}
Need some urgent solution on it.