You need to sign in to do that
Don't have an account?
katrinaxx
How to loop through ALL fields in Account object and invoke method on field
Map<String, Schema.SObjectType> gdMap = Schema.getGlobalDescribe();
Schema.Describesobjectresult dsr = gdMap.get('Account').getDescribe();
Map<String, Schema.SObjectField> fieldMap = dsr.fields.getMap();
if(testAccountObj.Name.containsAny(strCompare) {
}
Is there any way to code this such that the Name field is not hard coded? The requirement is to check ALL fields in the Account object and I don't want to have separate IF clauses for each field. Want it to be as dynamic as possible. Is this even possible?
Thanks!
Of course it's possible. But, you do know in this particular case, you might want to just use SOSL to have the index system search for values for you...
You could try to do it dynamically, but it would require significant amounts of code, something like:
More complex logic if you want to test non-strings as strings, but this should probably get you started.