Question:1
~~~~~~~~~~
What are the QueryException you handled in your Project?
Answer: Consider the below example
Account acc =[Select Id, Name from Account] ;
If the above query returns more than 1 record then we will get the below exception :
System.QueryException: List has more than 1 row for assignment to SObject
If there are no records returned by the above SOQL query then we will get the below exception :
System.QueryException: List has no rows for assignment to SObject
Solution for the above problem :
~~~~~~~~~~~~~~~~~~~~~~~~
Solution 1:
~~~~~~~~
List<Account> accList;
for(Account acc: [Select Id,Name from Account])
{
accList.add(acc);
}
Solution 2:
~~~~~~~~~
List<Account> accList;
for(List<Account> acc : [Select Id,Name from Account])
{
accList.addAll(acc);
}
Solution 3:
~~~~~~~~
String name = 'Chaari';
List<Account> acc = [Select Id,Name from Account where Name=:name];
if(acc.size()>0)
{
if(acc[0].Name=='Manjunath')
{
System.debug('Done man');
}
}
Question : 2
~~~~~~~~
How to make sure that an Object has CURD permissions before performing an operation to avoid errors?
(or)
What are the best practices you followed in your projects?
Answer :
~~~~~~
Before performing an Insert operation to make sure the user has appropriate permissions, use the below code snippet in the Apex Programming.
Below is the example for the insert operation.
Schema.DescribeSobjectResult dsr = Account.sObjectType.getDescribe();
if(dsr.isCreateable())
{
// peform DML operation here
}
For the rest of the DML operations and additional details, CLICK HERE
Question:3
~~~~~~~~~
How to get the top level role hierarchy by passing the specific roleId?
Answer:
~~~~~~~
This can be implemented using Recursion.
Recursion is a technique of calling a function itself until a specific condition is False.
public class RoleUtil
{
public static UserRole getUltimateParent(id roleId)
{
System.debug('--Checking the role '+roleId);
UserRole theRole = [select id, ParentRoleId from UserRole where id = :roleId];
if (theRole.ParentRoleId == null)
{
return theRole;
}
else
{
return getUltimateParent(theRole.ParentRoleId);
}
}
}
To test the above code, run the below code snippet from Execute anonymous window.
System.debug(RoleUtil.getUltimateParent('00E1J0000019uby'));
Here Id = UserRoleId
Question4:
~~~~~~~~
How to Insert child records using ExternalId?
Answer:
~~~~~~
a. For example, abc__c is a child object.
HEC_Recommendation__c is a Parent object and it has externalId as 444.
Below is the code snippet to use ExternalID during creation of child record which automatically relates to Parent record.
abc__c obj = new abc__c(Name='test56890');
obj.HEC_Recommendation__r = new HEC_Recommendation__c(ExternalId__c='444');
//obj.HEC_Recommendation__r= obj2;
insert obj;
CLICK HERE for additional details.
Question 5:
~~~~~~~~~~~
If My Domain is enabled in Production and if I refresh sandbox then will I lose the option to create My Domain in sandbox ??
Answer:
Yes, if you refresh from prod then sandbox will have the prod's My Domain. At that point, you cannot create a new one. It's technically possible to have sandbox My Domain changed by Salesforce support but, Salesforce support will not change it, other than what is set in Prod.
Question 6:
~~~~~~~~~~~
Why Salesforce is giving permission to create new MY Domain in the sandbox?
(or)
If My Domain is enabled in Production, after refreshing the Sandbox, the same My Domain will reflect to sandbox right? Why do we have a permission create My Domain in Sandbox?
Answer:
~~~~~~~~
It allows customers to test My Domain before deploying to production.
Question 7:
~~~~~~~~~~~
Can you tell me more about API Usage Notification?
Answer:
~~~~~~~
API usage is aggregated across the different APIs: SOAP/REST/Tooling/Metadata/Streaming API/... However, I have never seen Streaming API causing the limit to hit, as Streaming API would normally used to just send a subscribe() request and wait for updates, where as, SOAP/REST API clients are likely to send tons of API requests. This notification won't specify the number of requests made by each of them.
CLICK HERE for additional details.
tHiNk gooD and dO thE bEsT.........MANJU NATH 🌝
Very nice Manju
ReplyDelete