Things available in Salesforce, but you don't know.


There are lots of things available in every technology which are unknown to most of the developers. It will be better to know about those available features or may be a bug. So, let's start with the "Unknown features available in Salesforce".

1. Creating a Apex class with the name of "Account" or any sObject name.

Yes!!, you read it right. We can create a apex class with name of sObject. While there is no restrictions in creating a class with the name which is same as the sObject name, we are creating a class with the same name as the name of any sObject, then the class will be created in the Org, but what happen's when these class will be created. As far as I tested in salesforce org, When we created a class with the same name as the name of sObject then we will loose the reference to sObject.
Sound's wired ? No.?

have a look at the code now.

//The class name is Account
public class Account {
public String acc_name;
public String acc_Id;
}

we have created a Wrapper class with the name of Account and saved it in our org.
Now, What happen's when we try to create an Object of "Account".
If you have look at the below code, then you will find that while creating an object of Account, we will get the reference of the class we had created. So now, we are not able to get the reference of sObject "Account" using the Account keyword.

//The class name is Account
public class AccountController {
public static Account getAccount(){
Account acc = new Account(); //Object will be created here
acc.Name = 'Tarique Shamim'; // will through error
acc.acc_name = 'Tarique Shamim'; //will be correct here
return acc;
}
}

2. Changing the name of a Lightning Component Controller.

This is another topic which caused a lot of problems. It is often required to change the name of a Apex class which is a controller of a lightning class. In this situation, the first solution we think is to create another class with the new name and then copy the contents of previous class and delete the previous one.But here's come another solution for this, We can actually change the name of a lightning component controller (Apex class) with the reference is by Just renaming the name of the Apex class. When we rename the Apex class name then it will be automatically changed in the lightning component reference. Have a look at the code below.


//The controller class name is Comp_Controller
public class Comp_Controller {
//Body of class
}

//Lightning component code
<aura:component controller="Comp_Controller">
<!--Body of component-->
</aura:component>


In the above code snippet we are having a controller class which we need to change the name of it. When we change the name of the class, then it will be automatically changed in referenced lightning component. Have a look at the code below,

//The changed controller class name is Comp_CTRL
public class Comp_CTRL {
//Body of class
}

//Lightning component code
<aura:component controller="Comp_CTRL">
<!--Body of component-->
</aura:component>


In this case the the referenced name will be automatically changed in Component.
Here a point to take a note for this, the reference of the class in apex classes will not get automatically changed.

3. Changing the name of a Lightning Component.

Here's another issue we face when we are required to change the name of a lightning component. The same tactics(creating a new one component) we follow to change the lightning component name. But, here's another solution we can take to work for us.
We can change the name of lightning component by doing a Query on AuraDefinitionBundle Object.
Have a look at the query and Screen shots below


We can use this query to get the list of all available lightning components in our salesforce org.

We got the list of lightning component's here,


We are going to change the name of the component which is highlighted, by double clicking on the column.
We had edited the name of lightning component and we can save it now.

Here is the changed name of the component,

So, this is the way we can use the AuraDefinitionBundle object to change the name of the lightning component.


If you guys have any question related to this post, Please do ask in the comment section.

Keep learning, Cheers!!!





Things available in Salesforce, but you don't know. Things available in Salesforce, but you don't know. Reviewed by Tarique Shamim on February 24, 2018 Rating: 5

No comments:

Powered by Blogger.