You need to sign in to do that
Don't have an account?
Jagadesh
Fieldsets in apex
Hi,
I have a requirement where in im using Fieldsets.Here using fieldsets i have constructed the query and the database.query(query) working (conRec in the given code) fine,Now i would want to know the data that is returned,(i.e.,the data in each field of the fieldset ).
Could someone help me here. My code is as follows:
Global class DataValidationNew{
Webservice static boolean dataValidate(Id conId){
String Query='SELECT ';
List<Schema.FieldSetMember> fieldList=SObjectType.Contact.FieldSets.test_field_set.getFields();
for(Schema.FieldSetMember f : fieldList) {
Query = Query+f.getFieldPath() +',';
}
Query=Query+'Id from Contact where id=:conId';
Contact conRec=Database.query(Query);
System.debug('contact record'+conRec);
return true;
}
}
I have a requirement where in im using Fieldsets.Here using fieldsets i have constructed the query and the database.query(query) working (conRec in the given code) fine,Now i would want to know the data that is returned,(i.e.,the data in each field of the fieldset ).
Could someone help me here. My code is as follows:
Global class DataValidationNew{
Webservice static boolean dataValidate(Id conId){
String Query='SELECT ';
List<Schema.FieldSetMember> fieldList=SObjectType.Contact.FieldSets.test_field_set.getFields();
for(Schema.FieldSetMember f : fieldList) {
Query = Query+f.getFieldPath() +',';
}
Query=Query+'Id from Contact where id=:conId';
Contact conRec=Database.query(Query);
System.debug('contact record'+conRec);
return true;
}
}
Please give a try to below code, this will work for you.
Global class DataValidationNew{
Webservice static boolean dataValidate(Id conId){
String Query='SELECT ';
List<Schema.FieldSetMember> fieldList=SObjectType.Contact.FieldSets.test_field_set.getFields();
for(Schema.FieldSetMember f : fieldList) {
Query = Query+f.getFieldPath() +',';
}
Query=Query+'Id from Contact where id=:conId';
Contact conRec=Database.query(Query);
System.debug('contact record'+conRec);
sobject sobj = conRec;
for(Schema.FieldSetMember f : fieldList) {
System.debug('::::Your Field Result::::::'+sobj.get(f.getFieldPath()));
}
return true;
}
}
Thanks,
Kapil
All Answers
Data should be visible from system.debug whihc you have already used... Let me know if your looking for something else..
Thanks,
Sandeep
Please give a try to below code, this will work for you.
Global class DataValidationNew{
Webservice static boolean dataValidate(Id conId){
String Query='SELECT ';
List<Schema.FieldSetMember> fieldList=SObjectType.Contact.FieldSets.test_field_set.getFields();
for(Schema.FieldSetMember f : fieldList) {
Query = Query+f.getFieldPath() +',';
}
Query=Query+'Id from Contact where id=:conId';
Contact conRec=Database.query(Query);
System.debug('contact record'+conRec);
sobject sobj = conRec;
for(Schema.FieldSetMember f : fieldList) {
System.debug('::::Your Field Result::::::'+sobj.get(f.getFieldPath()));
}
return true;
}
}
Thanks,
Kapil