Deprecated: Optional parameter $list declared before required parameter $is_script is implicitly treated as a required parameter in /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/class.redux_cdn.php on line 21

Deprecated: Optional parameter $register declared before required parameter $footer_or_media is implicitly treated as a required parameter in /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/class.redux_cdn.php on line 45

Deprecated: Optional parameter $register declared before required parameter $footer_or_media is implicitly treated as a required parameter in /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/class.redux_cdn.php on line 104

Deprecated: Optional parameter $expire declared before required parameter $path is implicitly treated as a required parameter in /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/class.redux_functions.php on line 54

Deprecated: Optional parameter $depth declared before required parameter $output is implicitly treated as a required parameter in /home1/oijoiv2f/public_html/wp-content/themes/entaro/inc/classes/megamenu.php on line 155

Deprecated: Optional parameter $depth declared before required parameter $output is implicitly treated as a required parameter in /home1/oijoiv2f/public_html/wp-content/themes/entaro/inc/classes/mobilemenu.php on line 147

Deprecated: Optional parameter $args declared before required parameter $wp_customize is implicitly treated as a required parameter in /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/extensions/customizer/extension_customizer.php on line 583

Deprecated: Optional parameter $args declared before required parameter $wp_customize is implicitly treated as a required parameter in /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/extensions/customizer/extension_customizer.php on line 606

Warning: Cannot modify header information - headers already sent by (output started at /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/class.redux_cdn.php:21) in /home1/oijoiv2f/public_html/wp-includes/feed-rss2.php on line 8
salesforce apex dynamic type casting Archives - Salesforce Next Gen https://salesforcenextgen.com/tag/salesforce-apex-dynamic-type-casting/ Trailhead and Beyond Mon, 28 Dec 2020 19:46:45 +0000 en-US hourly 1 https://wordpress.org/?v=6.4.4 https://salesforcenextgen.com/wp-content/uploads/2020/10/cropped-76dc0dd6-326a-4956-a412-bfdf20c7fb23_200x200-32x32.png salesforce apex dynamic type casting Archives - Salesforce Next Gen https://salesforcenextgen.com/tag/salesforce-apex-dynamic-type-casting/ 32 32 Salesforce: Dynamic Apex https://salesforcenextgen.com/salesforce-dynamic-apex/ https://salesforcenextgen.com/salesforce-dynamic-apex/#comments Mon, 03 Jul 2017 14:32:38 +0000 http://salesforcenextgen.com/?p=717 DYNAMIC APEX What is Dynamic Apex? Dynamic Apex is a way to create a more flexible application with the ability to do the following. Access sObject and field describe information Access Salesforce app information Write dynamic SOQL queries, dynamic SOSL queries, and dynamic DML Each of the above-mentioned ability will require a post of its own, so …
Continue reading Salesforce: Dynamic Apex

The post Salesforce: Dynamic Apex appeared first on Salesforce Next Gen.

]]>
DYNAMIC APEX

What is Dynamic Apex?

Dynamic Apex is a way to create a more flexible application with the ability to do the following.

  1. Access sObject and field describe information
  2. Access Salesforce app information
  3. Write dynamic SOQL queries, dynamic SOSL queries, and dynamic DML

Each of the above-mentioned ability will require a post of its own, so let’s begin with the sObject and field describe information.

So, let’s say you want to find what are all the standard and custom object, presently available in an Org, or say you want a select list with all the objects as a select option. Then the sObject describe calls come into the picture.

This call provides all the information necessary to display the object as well as all the fields related to the sObject.

The most important method to begin dynamic apex is the “Schema.getGlobalDescribe() “ method. This method returns you a key value pair of object name as a key and Schema.sObjectType. With the help of this code, we are going to manipulate the rest of the task, syntax of the code is given below.

Public Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe(); // Org Map

Next we are going to use a method:  “Schema.getGlobalDescribe().Values();” this method returns list of sObjectType and will come in handy to make the select list of the objects.

Below is the method which  returns a list of selectoptions, these select options has sObjectLabel as display value and sObjectName as the value.

public list<selectoption> ObjectList {

        get{ return findObjectsInOrg();}

        set;}

public list<selectoption> findObjectsInOrg(){

        list<selectoption> objectList = new list<selectoption>();

        List<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();

        for(Schema.SObjectType f : gd){           

            objectList.add(new SelectOption(f.getDescribe().getname(),f.getDescribe().getLabel()));

        }   

        return objectList;

    }

With the help of above method we can make a select list on VisualForce Page.

VisualForce Code Is below :-

<apex:page controller=”WorkbenchTrial” sidebar=”false” showHeader=”true”>

    <apex:form >

        <apex:pageBlock >

            <apex:selectList styleClass=”customStyle” value=”{!selectedObject}” size=”1″ onchange=”rerenderfield()”>

                    <apex:outputLabel styleClass=”customStyle”>Select an object to query :</apex:outputLabel>

                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

                    <apex:selectOptions value=”{!ObjectList}”></apex:selectOptions>

</apex:selectList>

  </apex:pageBlock>

    </apex:form>

</apex:page>

Preview of the page:

sObjects Dynamic

Next: 

Also, Have a look at the below resources:

  1. Best Salesforce Interview Questions book with Apex and Visualforce concept explained

Also, Have a look at the below learning resources:

  1. SOQL (Salesforce Object Query Language)

  2. Apex Trigger Best Practices and the Trigger Framework

  3. Salesforce Interview Question and Answers Part 2

  4. Salesforce Interview Questions on Test Class

  5. Salesforce-lightning-interview-questions-2018

     6. Salesforce Interview Questions Batch Clas

The post Salesforce: Dynamic Apex appeared first on Salesforce Next Gen.

]]>
https://salesforcenextgen.com/salesforce-dynamic-apex/feed/ 4