<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>util &#8211; Hamza Siddiqui</title>
	<atom:link href="https://www.mhamzas.com/blog/tag/util/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.mhamzas.com</link>
	<description>4x Salesforce MVP &#124; 26x Certified &#124; Salesforce App &#38; System Architect</description>
	<lastBuildDate>Mon, 17 Apr 2023 07:23:30 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1</generator>
<site xmlns="com-wordpress:feed-additions:1">233526040</site>	<item>
		<title>Field Utils Helper Class</title>
		<link>https://www.mhamzas.com/blog/2023/04/17/field-utils-helper-class/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=field-utils-helper-class</link>
					<comments>https://www.mhamzas.com/blog/2023/04/17/field-utils-helper-class/#respond</comments>
		
		<dc:creator><![CDATA[hamza]]></dc:creator>
		<pubDate>Mon, 17 Apr 2023 07:23:29 +0000</pubDate>
				<category><![CDATA[Salesforce]]></category>
		<category><![CDATA[apex]]></category>
		<category><![CDATA[util]]></category>
		<guid isPermaLink="false">https://www.mhamzas.com/?p=3526</guid>

					<description><![CDATA[I was exploring the internet and found a wonderful utility class having methods to get information about fields and objects, including schema information by Kevin Antonioli posted on Playground App. Although I do have my own version but I prefer this one <br /><a href="https://www.mhamzas.com/blog/2023/04/17/field-utils-helper-class/" class="more-link btn btn-primary">Read More</a>]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">I was exploring the internet and found a wonderful utility class having methods to get information about fields and objects, including schema information by <a href="https://www.linkedin.com/in/kevin-antonioli-b075b340/" target="_blank" rel="noreferrer noopener nofollow">Kevin Antonioli</a> posted on <a href="https://live.playg.app/play/field-utils" target="_blank" rel="noreferrer noopener">Playground App</a>. Although I do have my own version but I prefer this one as this has probably more methods and documented :p</p>



<h3 class="wp-block-heading">Examples:</h3>



<p class="wp-block-paragraph">Get the describe for an object without ever running an expensive Schema.globalDescribe() call</p>



<pre class="wp-block-preformatted">// using object api name string param:
Schema.DescribeSObjectResult accountDescribe = FieldUtils.getDynamicDescribe('Account');

// using SObject record param:
Schema.DescribeSObjectResult accountDescribe = FieldUtils.getDynamicDescribe(accountRecord);
</pre>



<p class="wp-block-paragraph">Get the field map for an object without ever running an expensive Schema.globalDescribe() call</p>



<pre class="wp-block-preformatted">// using object api name string param:
Map&lt;String, Schema.SObjectField&gt; accountFieldMap = FieldUtils.getFieldMap('Account'); 

// using SObject record param:
Map&lt;String, Schema.SObjectField&gt; accountFieldMap = FieldUtils.getFieldMap(accountRecord); 
</pre>



<p class="wp-block-paragraph">Get the properties for a particular field set:</p>



<pre class="wp-block-preformatted">List&lt;Schema.FieldSetMember&gt; accountFieldSet = FieldUtils.readFieldSet( 'My_Field_Set',  'Account');
</pre>



<p class="wp-block-paragraph">Get just the api names of the fields belonging to a particular field set:</p>



<pre class="wp-block-preformatted">List&lt;Schema.FieldSetMember&gt; acctFieldSetApiNames = FieldUtils.getFieldSetFieldAPINames( 'My_Field_Set',  'Account');
</pre>



<p class="wp-block-paragraph">Determine if SObjectField is createable using object and field string params:</p>



<pre class="wp-block-preformatted">Boolean isCreateable = FieldUtils.isFieldCreateable('Account', 'Industry');
</pre>



<p class="wp-block-paragraph">Determine if SObjectField is accessible using object and field string params:</p>



<pre class="wp-block-preformatted">Boolean isAccessible = FieldUtils.isFieldAccessible('Account', 'Industry');
</pre>



<p class="wp-block-paragraph">Determine if SObjectField is updateable using object and field string params:</p>



<pre class="wp-block-preformatted">Boolean isUpdateable = FieldUtils.isFieldUpdateable('Account', 'Industry');
</pre>



<p class="wp-block-paragraph">Get the field type for an SObject field using object and field string params:</p>



<pre class="wp-block-preformatted">String industryFieldType = FieldUtils.getFieldType('Account', 'Industry'); //PICKLIST
</pre>



<p class="wp-block-paragraph">Get a list of all field api names for a given object:</p>



<pre class="wp-block-preformatted">List&lt;String&gt; acctFields = FieldUtils.getAllFieldsForSobj('Account');
</pre>



<p class="wp-block-paragraph">Get a list of all createable fields for a given object:</p>



<pre class="wp-block-preformatted">List&lt;String&gt; acctCreateableFields = FieldUtils.getCreateableFields('Account');
</pre>



<p class="wp-block-paragraph">Get a list of all accessible fields for a given object:</p>



<pre class="wp-block-preformatted">List&lt;String&gt; acctAccessibleFields = FieldUtils.getAccessibleFields('Account');
</pre>



<p class="wp-block-paragraph">Get a list of all updateable fields for a given object:</p>



<pre class="wp-block-preformatted">List&lt;String&gt; acctUpdateableFields = FieldUtils.getUpdateableFields('Account');
</pre>



<p class="wp-block-paragraph">Get a list of all fields (except within a specified blacklist) for a given object:</p>



<pre class="wp-block-preformatted">List&lt;String&gt; acctFieldsExceptBlacklist = FieldUtils.getAllFieldsExceptBlacklist('Account', new List&lt;String&gt;{'PersonPronouns', 'PersonGenderIdentity'});
</pre>



<p class="wp-block-paragraph">Parse last object from field path:</p>



<pre class="wp-block-preformatted">// sample data:
Contact contact = [SELECT Id, Name, Account.Owner.Name FROM Contact LIMIT 1];

// dynamically get the last object within a multi-level path (in this case, User/Owner):
SObject deepestRecordFromPath = ApexUtils.parseLastSubObjectFromPath(contact, 'Account.Owner.Name'); // get the user record
</pre>



<p class="wp-block-paragraph">Parse value from field path:</p>



<pre class="wp-block-preformatted">// sample data:
Contact contact = [SELECT Id, Name, Account.Owner.Name FROM Contact LIMIT 1];

// dynamically get the field value as an Object for a multi-level path:
Object fieldValueObj = ApexUtils.parseValueFromFieldPath(contact, 'Account.Owner.Name'); // get the value stored in the Name field</pre>



<h2 class="wp-block-heading">Source</h2>



<script src="https://gist.github.com/mhamzas/925a84cabcf8fdc4736ca93e334471d5.js"></script>



<p class="wp-block-paragraph"><strong>Credits</strong>: <a href="https://www.linkedin.com/in/kevin-antonioli-b075b340/" target="_blank" rel="noreferrer noopener nofollow">Kevin Antonioli</a> </p>



<p class="wp-block-paragraph"><strong>Source</strong>: https://live.playg.app/play/field-utils</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.mhamzas.com/blog/2023/04/17/field-utils-helper-class/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3526</post-id>	</item>
	</channel>
</rss>
