Share via Link :Public Link

? How to get a Public link through Apex

You have created a record on opportunity and attached a document

In order to share the document to the user who doesn’t have an access to Salesforce you have generated a public link and now you want to show use in apex

Following query can be used to get the public link

Select Id,name, DistributionPublicUrl FROM ContentDistribution

DistributionPublicUrl will give you the link. You will not get the link is you have not clicked on create link and generated the link

Maps in Salesforce [Basic]

Imagine Map collection to be a google map. You enter a location name or zip code to get the entire information about the area in the google map.

Consider location name to be the KEY and information you get to be a VALUE.

Map works on same concept. It contains KEY and VALUE

Map<key, value> ();

KEY can be of any data type, but it is usually STRING or IDs

VALUE can be of any data type, but it is usually SObjects in salesforce

 

Declaring Map

Map<Integer, string> m1 = new Map<Integer, String> ();

Storing value into MAP: put(key,value)

m1.put(1,’Hello’);
m1.put(2.’world’);

 

Get Key from the MAP:  keyset()

Set<Integer> allkeys = new Set<Integer>();

Allkeys = m1.keyset();

 

Get values from the MAP:

  • values() returns all the values
    List<String> values = new List<String>();
    Values = m1.values();

 

  • get(Key)
    m1.get(1);
    m2.get(2);

 

You can populate Key value by declaring curly brace {}. Inside Curly brace define Key followed by => and then value

Map<String, String> allstr = new Map<String, String>{1=>’a’, 2=>’b’};

 

We will cover advanced level of Map in another section . Please click on the link to check out advanced section of Map

Best Practices for View State

View state has a limit of 135k

Best Practices to optimize your view state

  • Minimize number of forms:
    Avoid using multiple form tag in VF page
    Instead of using multiple forms use <apex:actionregion> to submit portions of the form.
  • Declare variables as Transient.
    if you have referred section view state in VF page you must be aware that non-transient variables are stored.
    If variable is declared as Transient it is not saved and is not transmitted
  • Recreate state instead of storing
    if you can recreate the data during postback using SOQL , you must do that
  • Use Custom settings or Custom objects to store the read only data
  • Only Add the fields in SOQL which is required

View State in VF Page

What is View state:

View state maintains the state of the page by encompassing encrypted and hidden field

HTTP is a stateless protocol which means every request which is being sent and received is an independent request

Example: You filled in a contact form on website and clicked submit, after submitting you might have identified that an error has popped up “your mobile number should have area code” and all the data which you have filled in the form have vanished and you must refill the form again.

This happened because HTTP is stateless protocol and no state was maintained to save that data.

Salesforce encapsulates encrypted and hidden field to hold the state of the page

State includes field values, controller state

 

When Post/Postback is received State view is responsible to recreate the state of the page
It stores following data :

1) All non-transient data members used in the controller and extensions
2) Component tree
3) Small amount of data for VF

Visual Force Page

  • VF page is a markup language.
  • It is divided into two major sections  Markup and Controller

    Markup consists of  VF Tags , HTML and Javascript
    Controller are of two types : Standard and Custom Controller
  • Extensions: Extension is being used with Standard Controller , In order to add the additional functionality to the Standard Controller .
  • Controllers: Standard Controller and Custom Controller
    Standard Controller: It inherits the standard look and feel and functionality of the salesforce
    Custom Controller: It allows you to configure entire VF page as per the requirement.