You need to sign in to do that
Don't have an account?
Separate standard and custom fields from Collection of fields
Hi All
i need to do some operation on all custom fields of custom objects
I am obtaining this object dynamically. So initially i do not know name of my custom, object.
And since i am getting object on the fly hence i do not know the fields
Now say if i get object myobject__c. Then i can retrieve all its fields by following code:
map<String, Schema.SObjectField> mapFields = Schema.getGlobalDescribe().get(myobject__c).getDescribe().fields.getMap();
My problem is how do i separate standard and custom fields from this collection sothat i can operate only on custom fields.
Thanks in advance. Please Help
Let me know if i am not able to explain myself clearly and you need more details
There are a couple of ways to identify custom fields. First is to get the describe for each Schema.SobjectField reference in the map and check the isCustom method on it. The other is to simply look at the name of the field in the key. If it ends in __c then it's custom.
Check out all the methods on Schema.DescribeFieldResult as you may find more useful info there:
http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_methods_system_fields_describe.htm?SearchType=Stem
All Answers
There are a couple of ways to identify custom fields. First is to get the describe for each Schema.SobjectField reference in the map and check the isCustom method on it. The other is to simply look at the name of the field in the key. If it ends in __c then it's custom.
Check out all the methods on Schema.DescribeFieldResult as you may find more useful info there:
http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_methods_system_fields_describe.htm?SearchType=Stem
Thanks Andrew
First one will help me.. a lot of Thanks
I suppose looking at end __c will mean i have to do substring. Ans i did not want to do that
Thanks a lot for you kind help.