Tuesday 18 July 2017

             apex:relatedList

A list of Salesforce records that are related to a parent record with a lookup or master-detail relationship.
<apex:page standardController="Account">
    <apex:pageBlock>
        You're looking at some related list of--->{!account.name}:
        <apex:relatedList list="Opportunities" />
        <apex:relatedList list="Contacts"/>
        <apex:relatedList list="Cases"  />
    </apex:pageBlock>
</apex:page>


Special Note:
           apex:relatedList' component cannot be nested within form tags

Sunday 16 July 2017

                                    FREEZE USERS IN SALESFORCE

When administering Salesforce, you can at times run into scenarios where a particular users’s account should no longer have access. An example of that is when you have reason to believe that a user’s account has been compromised or someone has just left the company and you want to prevent them from logging in. Normally you would just disable the user; however, if the user is part of a custom heirachary field - there are more steps involved. A nice solution in the meantime us to just use the "Freeze" function.

After the user is frozen - the Freeze button changes to an Unfreeze button which performs (well, you get the idea).
Note: When you freeze a user, it does not free up a user license. In order to actually free up a license you have to perform an actual deactivation of the user.


For more Information please refer  Link:
                      http://blog.shivanathd.com/2013/10/Freeze-User-In-Salesforce.html

Thursday 13 July 2017

Tricky sales force Questions 

1. How to delete the User from Salesforce
  salesforce does not allow to delete any user, however you can deactivate the user.

2.If one object in Salesforce have 2 triggers which runs “before insert”. Is there any way to control the sequence of execution of these triggers?

 Salesforce.com has documented that trigger sequence cannot be predefined. As a best practice create one trigger per object and use comment blocks to separate different logic blocks. By having all logic in one trigger you may also be able to optimize on your SOQL queries.

3.How to enable truncate custom object feature in Salesforce ?
Ans : Navigate to “App Setup | User Interface” and select “Enable Custom Object Truncate”.

Sometimes while deleting record it gives error “Object cannot be Deleted”. What is the reason for this kind of error ?

This is generic error message prompted by Salesforce many times, which is not well informative. To get informative message, we can try to delete same record in “Developer Console”. In Developer Console Debug log, we will get exact error message.

Interesting !!!

Example:
Lets say there is one record which is parent of more than 2000 records and grand parent of 5000 records. In such scenario from developer console it gives error something like “record cannot be deleted because it has many associated objects” However in User Interface, it will just display that “Object cannot be deleted."


4.Why CSS is not working in PDF created by Visualforce ?

1.Use “apex:stylesheet” tag to import external CSS file
2.Wrap “Style” tag inside “Head” tag in Visualforce
You have to cross verify the things.If you mentions these propery your css should work

5.whats Test.isRunningTest() ?
Use Test.isRunningTest() in your code to identify that context of class is Test or not. You can use this condition with OR (||) to allow test classes to enter inside code bock. It is very handy while testing for webservices, we can generate fake response easily.


                                                                                                                          Continues ...

Converting Lowercase string to Uppercase & Upper case string to Lower case

/* Here I'am converting lower case to Uppercase  */

string x='ajay';
string uppercase=x.touppercase();     //Converting string to Upper case
system.debug('uppercase ====>'+uppercase);

/* Here I'am converting Uppercase to lower case */
string y='SACHIN';
string Lowercase=y.tolowercase();
system.debug('lowercase====>'+Lowercase);

How to get all Salesforce records even from recycle bin or Achieved Activities using SOQL query?


we cannot do it directly within the Query Editor of developer console.If I run the query in query editor what will happen?!!....I hope you got the answer. But there's a workaround for we can test it  in Developer Console. The workaround is to use the "Execute Anonymous Window".

1. Open "Enter Apex Code" window by selecting "Debug" -> "Open Execute Anonymous Window" menu
2. Enter your query there and output the result to the log. Check the "Open Log" checkbox.
List<contact> clist = [SELECT name FROM contact ALL ROWS];
System.debug(JSON.serialize(clist));
3. Click "Execute" to run your code and check the log file for your result.

Special Note:
               Deleted data is stored in the Recycle Bin for 15 days.


Interesting Link:
                  https://salesforce.stackexchange.com/questions/4020/whats-the-actual-meaning-of-all-rows-in-soql

Wednesday 5 July 2017

 Tricky Error : Cannot Create Master-Detail Relationship

                                        Great things are done by a series of small things brought together. 
                                                                                                                         -Vincent Van Gogh


Some times we will get below error message while creating master detail relationship..

whats that error massage?

"You cannot create a new Master-Detail relationship on an existing custom object if records already exist. You must first create a Lookup relationship, populate the lookup field with data in all records, and then change the relationship type to Master-Detail. "

Have you encounter this error before then its great!!!!. Today I'am going to explain solution about that error

Tricky solution:

Master - Detail relationship requires that the Detail Record (Child) ALWAYS have a Master (Parent) record since the detail record inherits security and ownership from the parent record.
Therefore, if you want to create a Master - Detail relationship between existing objects, you need to make sure that all the existing records for the child object have a lookup value to the parent object BEFORE you can create the Master Detail relationship.

1. Create a lookup from the child object to the parent object.
2. Populate ALL the records with a valid lookup value to the parent.
3. Change the Lookup relationship to a Master - Detail relationship. This is only allowed if ALL RECORDS HAVE A VALID LOOKUP.

Use this query to confirm to check if child record exist arent:
SELECT count()  from Child_object__c;


For detailed Information Visit Below Link:
http://www.tutorialkart.com/salesforce/cannot-create-master-detail-relationship/

Tuesday 4 July 2017

What is a System.runAs() Method in Apex?

Generally, all Apex code runs in system mode, and the permissions and record sharing of the current user are not taken into account. The system method, System.runAs(), lets you write test methods that change user contexts to either an existing user or a new user. All of that user’s record sharing is then enforced. You can only use runAs in a test method. The original system context is started again after all runAs() test methods complete.

Example :

System.runAs(Annappa) {

// The following code runs as user 'Annappa'

System.debug('Current User: ' + UserInfo.getUserName());

System.debug('Current Profile: ' + UserInfo.getProfileId()); }

// Run some code that checks record sharing

}
Special Note:
                       Please check these two Links:

https://salesforce.stackexchange.com/questions/88642/system-runasnew-userid-userinfo-getunserid

https://salesforce.stackexchange.com/questions/13318/error-mixed-dml-operation-on-setup-and-non-setup-objects

I hope you enjoyed the post :)

Monday 3 July 2017

System and User Mode in Sales force

System mode -


Its running apex code by ignoring user's permissions. So if logged in user does not have create permission but they will able to create a record.
Apex code has access to all objects and fields, sharing rules aren't applied for the current user. 
All apex code run in system mode. It ignores user's permissions. Only exception is anonymous blocks like developer console and standard controllers.

User mode - 


Its running apex code by respecting user's permissions and sharing of records. So, logged in user does not have create permission they are not able to create a record.
Only standard controllers and anonymous blocks like developer console run in user mode.


Special Note:

  Please Visit the  below Links.
                                                http://www.tgerm.com/2011/03/trigger-insufficient-access-cross.html

 


Does option “Re-evaluate Workflow Rules after Field Change” exist in process builder?"


Yes its possible in Process Builder.

How to do that?

You can do this while adding the object. If you check the Yes checkbox under Allow process to evaluate a record multiple times in a single transaction. the record will be re-evaluated maximum of 5 times in same transaction.

Hope it helps.

Purpose of 'Re-evaluate Workflow Rules after Field Change'


There is no connection between workflows, and there is no way to control the order of multiple workflows on the same object.  So, if you need 1 workflow to impact another one, make sure the criteria of each workflow takes that into consideration and make sure a Field Update is marked as 're-evaluate workflows'
For Example:
wf1-->type=customer  sets customerdate
wf2-->closedopp>0 and set type=customer
Since you can't control which of these WFRs runs first, you might consider setting 're-evaluate' on the 2nd Field Update to give the first WFR another chance.
NOTE:  This is a simple example to demonstrate the feature -- you would never design Workflow Rules as I have outlined them in this example.

Create records with Java script custom buttons in salesforce.


step1:
Navigate to Setup | Customize | Account | Buttons, Links and Actions
step2:
Press the New Button or Link button
step3:
Give your button a name
step4:
Choose the appropriate Display Type option but in most cases you’ll likely choose a Detail Page Button
step5:
Choose Execute JavaScript as the Behavior
step6:
In the field box you’ll add the JavaScript which I’ll explain below
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
var acct = new sforce.SObject("Account");
acct.name = 'Test Account';
acct.phone = '8147285030';
var result = sforce.connection.create([acct]);
if (result[0].getBoolean("success")) {
window.location = "/" + result[0].id + "/e";
} else {
alert('Could not create record ' + result);
}

Special Note: Dont write require script Like this
               {
              !REQUIRESCRIPT("/soap/ajax/29.0/connection.js")
               }

I hope you enjoyed this post......