How to move the content to next PDF page if content doesn’t fit in the page?

If you want to move the content dynamically in the PDF page when the content does not fit in the PDF.
See below screenshot where opportunity table doesn’t fit into the PDF page

 

You want to achieve below screenshot

 

Use CSS page-break-after Property

style=”page-break-after:always;”   inside div tag

 

Advertisements

Error OAUTH_APP_ACCESS_DENIED connecting Postman to Salesforce

After inserting all the correct information , if you are unable to Generate new access token and receiving following error OAUTH_APP_ACCESS_DENIED.

You have to enable users to Self-authorize

Setup >> Manage Connected Apps[Lightning]/ Connected Apps under Manage Apps[ Classic] >> Edit against connected app >> Select All Users may self-authorize in permitted users picklist

Connected apps

You are all set. Go ahead and try again and you will be prompted with allow window

How to get Id of the Object

Salesforce allows you to get the Key Prefix.

Key Prefix is 3 character unique key for each Object. There are two ways to find the Key prefix.

1) using schema.getGlobalDescribe()

For(Schema.SObjecttype obj: Schema.getGlobalDescribe().Values()){

System.debug(obj.getDescribe());
System.debug(obj.getDescribe().getKeyPrefix());

}

 

2) Every record Id first 3 letters is a Object KeyPrefix;

Contact cc: [Select id from Contact limit 1];
String keyPrefix = String.valueOf(cc.id).substring(0,3);

 

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