0% found this document useful (0 votes)
37 views

Standard Controller Actions: Retrieve and Update All The Records/single Record From Object-With Icon - 9 Video

The document provides information about standard controller actions in Visualforce pages for Salesforce. It discusses actions like save, edit, quick save, and cancel that are available through standard controllers. It also includes an example of using a standard controller with an Account object, including input fields, output fields, and command buttons to save, quick save, and edit. It notes that pageBlockSectionItem can only include two child tags. Other topics covered include global variables, retrieving and updating single or multiple records from an object using a recordSetVar, data tables, data lists, repeats, and constructor and argument usage.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Standard Controller Actions: Retrieve and Update All The Records/single Record From Object-With Icon - 9 Video

The document provides information about standard controller actions in Visualforce pages for Salesforce. It discusses actions like save, edit, quick save, and cancel that are available through standard controllers. It also includes an example of using a standard controller with an Account object, including input fields, output fields, and command buttons to save, quick save, and edit. It notes that pageBlockSectionItem can only include two child tags. Other topics covered include global variables, retrieving and updating single or multiple records from an object using a recordSetVar, data tables, data lists, repeats, and constructor and argument usage.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Standard Controller Actions

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_std_actions.htm

Save, Edit, Quick save, cancel etc.

Standard Component Reference


<apex:page showHeader="false" standardController="Account">
<apex:form >
<apex:pageblock >
<apex:pageBlockSection title="Details" columns="2">
<apex:inputfield value="{!Account.name}"/>
<apex:inputtext value="{!Account.AccountNumber}"/>
<apex:inputtext value="{!Account.Site}"/>
<apex:inputtext value="{!Account.Owner}"/>
<apex:inputtext value="{!Account.CleanStatus}"/>
<apex:inputHidden value="{!Account.Phone}"/>
<apex:inputSecret value="{!Account.Phone}"/>
</apex:pageBlockSection>

<apex:pageblockSection title="Output">
<apex:pageblockSectionItem >
<apex:outputLabel value="Naresh" for="Item"/>
<apex:inputField value="{!Account.Ownership}" id="Item"/>
</apex:pageblockSectionItem>
<p>PageblockItem</p><br/>
</apex:pageblockSection>
<apex:pageblockButtons location="top">
<apex:commandButton action="{!Save}" value="Save"/>
<apex:commandButton action="{!quicksave}" value="quicksave"/>
<apex:commandButton action="{!edit}" value="edit"/>
</apex:pageblockButtons>
</apex:pageblock>
</apex:form>

<apex:panelGrid columns="3" id="theGrid">


<apex:panelBar>

Pageblocksetion Item:
We cant use morethan 2 tags within this tag.

Global Variables
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_variables_global.htm

Retrieve and Update all the records/Single record from object—with icon---9 th Video
<apex:page showHeader="false" standardController="Account" recordSetVar="Acclist">
<apex:form >
<apex:pageBlock >

<apex:facet name="header">
<div class="content">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQWTQRRzHL9-pEoN90jOp2WWeBoYFVbkBidHobUqeRyHqIFjiKb"
class="pageTitleIcon" />
</div>
<div class="pbTitle">
<h3>Account</h3>
</div>
</apex:facet>
<apex:pageblockTable value="{!Acclist}" var="Acc">
<apex:column value="{!Acc.name}"/>
<apex:column value="{!Acc.site}"/>
<apex:column value="{!Acc.Accountnumber}"/>
<apex:column headerValue="Industry">
<apex:inputfield value="{!Acc.industry}"/>
</apex:column>
</apex:pageblockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

Data Table , Datatlist and Repeat-10th:


Column tag mandatory-Data table
<apex:page showHeader="false" sidebar="false" standardController="contact" recordSetVar="con">
<apex:form >
<apex:pageblock >
<apex:dataTable value="{!con}" var="c" border="2" cellspacing="0" cellpadding="" bgcolor="red">
<apex:column headerValue="Name">
<apex:inputtext value="{!c.name}"/>
</apex:column>
<apex:column value="{!c.id}" headerValue="ID"/>
<apex:column value="{!c.phone}" headerValue="Phone"/>
</apex:dataTable>
</apex:pageblock>
</apex:form>
</apex:page>
Datalist:
<apex:page showHeader="false" sidebar="false" standardController="contact" recordSetVar="con">
<apex:form >
<apex:pageblock >
<apex:datalist value="{!con}" var="c">
<apex:inputtext value="{!c.name}"/>
</apex:datalist>
</apex:pageblock>
</apex:form>
</apex:page>

Repeat:

Constructor and Argument: 16


We can declare the varibles in 2 ways--
1) Class level
2) Constructor level
We can assign the values to the variables in 2 ways
1) in side the Class
2) Outside of the class(Anonymous window)
**We can't assign the values to the constructor level variables from anonymouswindow. We can assign by passing the arguments.
Constructor has 2 type of arguments.
1) Empty argument Constructor
2) multiple argument Constructor
** We can have more than 1 constructor within the class.

17th: Methods:
3 types:
1) Void method
2) Return methods.
again 2 types
Primitive and non primitive return method(Sobj,standard obj , custom obj,classes)
3) Page reference method--It iwll cover in controller topic.
Void :
Syntax:
public void method(){
}
return:
public pri/non pri datatype method(){
return value;
}

The variables which are declared within the class will not access from the outside.
We can call a method from any other method

Method Arguments:
Methods Argu are similar to the constructor arg.
Utility class:
Utility classes are helper classes that consists of reusable methods.
Utiltity class-1
public class Utilityclass_20 { //--Utility class is a helper class which contains reusable methods.

public account returnaccount(string name,string site) {


account a = new account();
a.name=name;
a.site=site;
return a;
}
public contact returncont(id accid,string firstname,string lastname)
{
contact c=new contact();
c.AccountId=accid;
c.LastName=lastname;
c.FirstName=firstname;
return c;
}
}

Utility class-2:
public class Utilityclass_1_20 {
public void insertmethod(){
Utilityclass_20 ut=new Utilityclass_20();
account a = ut.returnaccount('Naresh Ut2','DVK');
insert a;
contact cc=ut.returncont(a.id,'Hony','Sweety');
insert cc;
}
}
Inner class:
Inner class is a class which is written within the class.
We can use inner class as a wrapper class in VF pages to combine the different data types.
We can call the Inner class in 3 ways.
1) From the main class.
2) From outside of the class
3) From the other inner class of the same main class.
From the Main class:

From outside of the class(Outside class):


Main class:

Colletions: 24th video


Lists:
List is a collection of elements, and they are ordered according to their insertion; elements can be of any data-type
List elements can be of any data type—primitive types, collections, sObjects, user-defined types, and built-in Apex types.
List allows duplicate values and are referred by their indices.

List<String> name = new List<String>{'John','Kelly','Mike'};


or
List<String> name=new List<String>();
name.add('John');
name.add('Kelly');
Hence the values and index positions are stored as mentioned above.

https://micropyramid.com/blog/how-to-use-list-methods-in-salesforce/
Set: 25th Video

Set is an unordered collection of elements that will not allow duplicates.


datatype allows only primitive datatypes and SObjects.
We cannot get retrieve the data based on the index because the set does not have an index.

Set setName = new Set();

Conversion:

Converting from a List to Set, can be done using the set’s constructor.

List<String> lStrings = new List<String>{'a','b','c','d','e'};


Set<String> sStrings = new Set<String>(lStrings);

Converting from a Set to a List, can be done using the List constructor.
1) First Approach
Set<String> sStrings = new Set<String>{'a','b','c','d','e'}; 
List<String> lStrings = new List<String>(sStrings);
--------------------------------------------------------------------------
2) Second approach
Set<String> sStrings = new Set<String>{'a','b','c','d','e'}; 
List<String> lStrings = new List<String>();
lStrings.addall(sStrings);

Program:

public class Set_25 {

    list<account> al;

    public list<account> method1(){  

     set<account> accset=new set<account>();    

        for(integer i=0;i<5;i++){         

      account a=new account();

        a.name='ooo1' +i;

        a.site='set2';

        accset.add(a);

       al=new list<account>(accset); //Converting set to list.

       system.debug('accset==>' +al);         

        insert al;

        return al;

    } 

Maps:26,27,28.

Map is a collection of class, which consists a group of elements. It is a key and value pair. Each and every element in the map contains key and value.
Key should be unique and value can be duplicated. It supports dynamic memory allocation. It's like a collection of Key-value pair, where each
key(unique) map to a single value. Keys and values can be any data types.

Map<Key,Value> variablename=new Map<Key,Value>();

Map<Id,Account> Accmap=new Map<Id,Account>();


https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_map.htm#apex_System_Map_constructors
Static Method:29

Static method and Variables:

static variables should start with static keyword

static string std='Naresh';

Static method have to declare with static keyword.

Public static void method()

Calling:

classname.staticmethod();

if we execute static method , it will execute only static variables and it skips constructor and normal variables.

if we execute normal method it will execute static and normal variables.

Private Variables 30:

//Private variables can access within the same class only.Will not work outside of the
class(Another class).
public class Private_variable_30 {
private string str='Naresh';

public void method(){

system.debug('Str==>' +str); 
}
}

VF controller 30:

We have 3 types controller in salesforce.

1) Standard controller.
2) Custom controller
3) Extension controller.

Standard controller : Standard Controller in Salesforce are used in visualforce page. These controllers are available for both standard
and custom objects. The main aim of these standard controllers are to provide standard functions like Save, Delete and Create records.

<apex:page showheader=’false’ standardcontroller=’Account’>

https://www.tutorialkart.com/visualforce/standard-controller-in-salesforce-standardcontroller-attribute/

Custom Controllers:

A custom controller is an Apex class that implements all of the logic for a page without leveraging a standard controller. Use custom
controllers when you want your Visualforce page to run entirely in system mode, which does not enforce the permissions and field-
level security of the current user.

Sample code: with getter method.


The above code represents Fetching single record by using custom controller.

If we are using Sobjects setter method is not required. We have to use setter method for primitive data types.

Get and Set :31:

Getter: Get (getter) method is used to pass the value from controller(Apex) to VF page.

Setter :It will pass he data from VF page to Apex controller

Single record insert with custom controller:

Deployments: 33, 34:

Developer Sandbox:(Local)

A Developer sandbox is intended for development and testing in an isolated environment. A Developer Sandbox includes a copy of your production
org’s configuration (metadata).

Developer Pro Sandbox:(testing and Training)

A Developer sandbox is intended for development and testing in an isolated environment. A Developer Sandbox includes a copy of your production
org’s configuration (metadata).Use a Developer Pro sandbox to handle more development and quality assurance tasks and for integration testing or
user training.

Partial Copy Sandbox:(Client QA)

A Partial Copy sandbox is intended to be used as a testing environment. This environment includes a copy of your production org’s configuration
(metadata). Use a Partial Copy sandbox for quality assurance tasks such as user acceptance testing, integration testing, and training.

Full Sandbox:

A Full sandbox is intended to be used as a testing environment. Only Full sandboxes support performance testing, load testing, and staging. Full
sandboxes are a replica of your production org, including all data, such as object records and attachments, and metadata. The length of the refresh
interval makes it difficult to use Full sandboxes for development.

Deployments can be done for only meta data(Config).

The records we can move from one org to antoher org with the help of Data loader.

Tools for Deployments:

1) Eclipse tool (Olden days)

2) ANT

3) changesets(Salesforce inbuilt)
ANT:

Wehave 2 files .

1) build.properties:

We have to provide our credetials.

Password should give with security token.

If we use company proxy , security token not required.

2) Create package.xml with class and page details.

3) build.xml:

Retrive build:

we have to provide package path and retrive path(output).

Deply the code to target org (sandbox to sandbox)

---With test class run

---Without testclass run

But if we deploy the code from sandbox to prod

---Deploy with test class run only

Search Functionality 35:

Sobject to normal object conversion: (Type Casting)

sobject obj=new account(name='Naresh');

database.insert(obj); //It will insertt the record in account object.

again im trying to passing Sobj values to account variable, then

acount acc=(account)obj; //converting Sobj values to account.


Insert record with database.insert 35:

account acc=new account(name='database');

database.insert(acc);

Search functionality for Multiple Obj:

Search_global_3:

Export he result to Excel ad PDF:

Export_to_excel.

Class 36:

Rendared:

Generally we will use the Rendared to Hide or Disaplay the elements.Generaly we will use in Pageblock, Pageblocksections,output panels.

Param:

Custom Settings and Cusom Metadata type 37 and 38:

Advantages to Custom Metadata:

1. Most importantly, they are Metadata and thus deployable! No more annoying configuration after deployment, which you have to do with Custom
Settings. They're also refreshed to sandboxes, so you don't need to create Apex classes to generate your default Custom Setting records.

2. They have WAY more options that Custom Settings: picklist fields, long text areas (in Spring '17), page layouts, and validation rules (though as of
Winter '17 these are not deployable either by change set or by migration tool - weird!)

3. The beauty that is Metadata Relationships! You can create lookups between Custom Metadata objects. Additionally, you can create an Object
Definition lookup - so you're relating Custom Metadata to Standard or Custom Object definitions.

Reason why you would use custom settings instead:

============

1. Hierarchies - Custom metadata types do not purport to replace hierarchy custom settings which allow you to vary values based on users and
profiles across the org. These custom settings can also be referenced in formulas, so can be used in formula fields, validation rules, workflow rules,
and visualforce. (Documentation here).

Custom setting records’ values can be edited in code, while custom metadata cannot. If you will need to modify your configuration programmatically
for any reason (say you’re creating a config console for the user), custom metadata will not work.

If we deploy custom settings only obj will deploy records wont deploy, we have to create again custom records in another enviroment.We can
overcome this problem with custom metadatypes.

To deploy the records from custom settings we have to use dataloader.


Extension Controller and Inline VF page -40 (We can extend the standard functionality)

Extension Controller in Salesforce is an Apex class containing a constructor that is used to add or extend the functionalities of a Standard
Controller or custom controller in Salesforce. 
Extension controller is also used to leverage the functionality of another controller using our own custom logic.

We can
1) Override the buttons
2) Create custom buttons
3) Create tabs.

We can use this extension controller with standard controller and custom controller.
For standard controller we have to use Apexpages.standardcontroller variable.

Inline VF page (Show Child records In Parent record):

Extension controller with custom Controller40 :

<apex:page extension=”Extension_con” controller=”Any_custom_controller” />

Public Extension_con(Any_custom_controller variable)

Javascript Basics-41:
 Object creation in Javascript:

<apex:page showHeader="false" >

    <head>
        <body>
            <script type="text/javascript">
            var sobject = {
               Name :'Naresh',
                Mobile:'789654131',
                Address:'Hyderabd',               
            
            };
            console.log('Object Name==>'+sobject.Name);
            console.log('Object Name==>'+sobject.Mobile);
            console.log('Object Name==>'+sobject.Address);
                        
            </script>
        </body>
    </head>
</apex:page>

Assign a variable to object for dynamically getting the records.

for(var std in sobject){                

            console.log('Filed Name==>'+std);  

            console.log('Filed values==>'+sobject[std]);  

        }

 Create list in Javascript:


 
 var  list=['naresh','srinivas','dummy'];
            for(var sd of list){
            console.log('Filed Name==>'+sd);  
            
      }

Javascript-43:
1) alert
2) Validation
3) Add JS file into salesforce static resource.

alert:

<apex:page showHeader="false" standardController="Account">

    <apex:form id="form">

        <apex:pageBlock id="pb">

            <div id="Validation" style="background-color:red">

                    

                </div>

            <apex:pageBlockSection id="ps">

                

                <apex:inputField value="{!Account.name}"/>

                <apex:inputField value="{!Account.site}" id="ste"/>

                <apex:inputField value="{!Account.industry}"/>

                <apex:inputField value="{!Account.rating}"/>

            </apex:pageBlockSection>   

            <apex:commandButton value="Save" action="{!save}" onclick="return Alertfunction();"/>

        </apex:pageBlock>    

    </apex:form> 

    <script type="text/javascript">

    

    function Alertfunction(){

        var stee = document.getElementById("{!$Component.form.pb.ps.ste}");

        

        if(stee.value !='hyderabad'){

            alert('Site should be Hyderabad');

                      return false;            
    }

  }

    </script>    

</apex:page>

Validation Msg:

<apex:page showHeader="false" standardController="Account">

    <apex:form id="form">

        <apex:pageBlock id="pb">

            <div id="Validation" style="background-color:red">

                    

                </div>

            <apex:pageBlockSection id="ps">

                

                <apex:inputField value="{!Account.name}"/>

                <apex:inputField value="{!Account.site}" id="ste"/>

                <apex:inputField value="{!Account.industry}"/>

                <apex:inputField value="{!Account.rating}"/>

            </apex:pageBlockSection>   

            <apex:commandButton value="Save" action="{!save}" onclick="return Alertfunction();"/>

        </apex:pageBlock>    

    </apex:form> 

    <script type="text/javascript">

    

    function Alertfunction(){

        var stee = document.getElementById("{!$Component.form.pb.ps.ste}");

        

        if(stee.value !='hyderabad'){

          var para = document.createElement("div");

           var node = document.createTextNode("Please enter a valid Site");

            para.appendChild(node);

            var element = document.getElementById("Validation");

            element.appendChild(para);

            return false;

            

    }

  }

    </script>    

</apex:page>

Add Javascript file from static resource.

Setup--> static resource--> upload js file.


We can add this file to the <head> tag.

<apex:includeScript value="{!$Resource.example_js}"/>

sometimes "{!$Component.form.pb.ps.ste}") will not work, then we can

Javascript Action function 44:

Standard Set controllers 45:

Setpagesize

Next,Prv,last first buttons.

public class Standard_set_controller_45 {

public list<account> acclist {get;set;}

public apexpages.StandardSetController std {get;set;}

public integer val {get;set;}


public Standard_set_controller_45(){

std=new apexpages.StandardSetController(database.getQueryLocator([select id,name,site from account]));

val=5;

std.setpagesize(val);

acclist=(list<account>)std.getrecords(); //by default some records will show.i.e 5

public void method(){

std.setpagesize(val);

acclist=(list<account>)std.getrecords();

public void first(){

std.First();

acclist=(list<account>)std.getrecords();

public void Previous(){

std.previous();

acclist=(list<account>)std.getrecords();

public void Next(){

std.next();

acclist=(list<account>)std.getrecords();

public void Last(){

std.last();

acclist=(list<account>)std.getrecords();

public Boolean getHasNext(){

return std.getHasNext();

public Boolean gethasPrev(){

return std.getHasPrevious();

VF Webcomponent 46:

Triggers 47:
Triggers only works on DML operattions.
It will executte based on events(before insert, after insert)
triggers have context variables
divided into 2 types
before and After

below are the trigger events.


before insert,
after insert,
before update,
after update
before delete
after delete
after undelete.

Before triggers 48:


Trigger.new: contains new data (after updaed data).
Trigger.old: contins old data (before updated data)

Trigger.newmap: It holds the key and value of new data. (id,value)


Trigger.oldmap:It holds the key and value of old data. (Id,value)

We have to use Trigger.old in isdelete events.


we can restrict the record that unable to delete if any condition met by passing adderror(msg) method i trigger

for a best practices we can use condition


if(acc.rating!=trigger.oldmap.get().rating)

what is the best practises writing triggers:


1) one trigger for one object
2) Bulkify the code.(It will come after rigger)
3) Write trigger handlers: It is othing but a apex class. We can write all logics in apex class and call this class from triggers

Handler class:
Writitng total logic in Apex lass and calling this class in Triggers.

After triggers 49:


Recursion triggers 50:
Future method 51:
A future method runs in the background, asynchronously. You can call a future method for executing long-running operations. Each
future method is queued and executes when system resources become available. That way, the execution of your code doesn’t have to
wait for the completion of a long-running operation. A benefit of using future methods is that some governor limits are higher, such as
SOQL query limits and heap size limits.

It is a separate transaction.
Future method doesnot support non primitive datatypes.

You might also like