Friday 26 July 2019

          Cache control value control in a static resource:


Private- It specifies static resource data cached on the Salesforce server shouldn’t be shared with other users. The static resource is only stored in cache for the current user’s session.

Public specifies that the static resource data cached on the Salesforce server be shared with other users in your organization for faster load times.

https://salesforce.stackexchange.com/questions/9038/what-does-the-cache-control-value-control-in-a-static-resource

           System.ListException: List index out of bounds error

Before referring to the 0th index of list you must perform a check on whether the list is empty or not. Whenever you try to access records from list first check if its empty or not.

List <contact>contactList = [Select Id, Name from contact Limit 10];
// Before processing the list check if its empty or not
// It will go inside the loop only if the List is having values in it.
if(contactList.size() > 0) {
 // Do something with contactList [0].Name
 }
// If you try to access contactList [0] without empty check then it will obviously throw that error!!


Saturday 20 July 2019

Can we write SOSL statements in triggers


Yes, we can write SOSL inside triggers.There is no such restriction.

Code:

trigger trg_AccountSOSL on Account (before insert, before update) {

List<List<SObject>> searchList = [FIND 'map*' IN ALL FIELDS RETURNING Account (Id, Name), Contact, Opportunity, Lead];
List<account> myAcc = ((List<Account>)searchList[0]);

system.debug(myAcc[0].name);
}


UNABLE_TO_LOCK_ROW unable to obtain exclusive access to this record or 1 records


Solution:

When you have multiple jobs running that update the same set of records, it's recommended to lock the records using the FOR UPDATE keyword. 

It will ensure that the record is locked and no other job can update the same record at that point in time. The conflicting job will then wait until the locking on the record is released and then perform the required operation. 

This will avoid conflicts between jobs that are running concurrently and will not throw up this exception. 


You can refer the below link to learn more about record locking.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_locking_statements.htm

Thursday 11 July 2019

                                   Organization Administration Locked…?
we will face the above error Message.while saving the classes(sometimes)
This usually means:
  1. Something is being deployed via API (check Setup -> Monitor Deployments)
  2. Something is being deployed via change sets (Setup -> Deploy -> Inbound change sets)
  3. You're running some unit tests

Saturday 9 February 2019

How to Play YouTube Video In Salesforce Lightning Component


We can play video file in lightning component by 2 ways :


  • From Static Resources.
  • Play Video File Using iFrame Tag.
<aura:component>

  <iframe width="720" height="480" src="https://www.youtube.com/embed/45JRuZOBIKk"></iframe>

</aura:component>


<aura:application>
    <c:videoDemo/>
<!-- here c: is org. default namespace prefix-->
</aura:application>


How To Detect a Device In Salesforce Lightning Component ?


{!$Browser.isTablet}      > To detect the tablet device
{!$Browser.isPhone}      > To detect the user is in Mobile Phone / mobile browser
{!$Browser.isAndroid}   > To detect the user is in Android device
{!$Browser.formFactor} > Returns a FormFactor enum value based on the type of hardware the browser is                                                            running on.


DetectDevice.cmp

<aura:component>

    <aura:if isTrue="{!$Browser.isTablet}">
    You are using a tablet device
        ( <lightning:icon iconName="utility:tablet_portrait" size="x-small" alternativeText="Indicates approval"/> ).
    </aura:if>
    <aura:if isTrue="{!$Browser.isPhone}">
        You are using a phone
        ( <lightning:icon iconName="utility:phone_portrait" size="x-small" alternativeText="Indicates approval"/> ).
        This message is rendered using isPhone <br />
    </aura:if>
    <aura:if isTrue="{!$Browser.isIPhone}">
        You are using an IPhone, If it is IPhone X, _/\_ <br />
    </aura:if>
    <aura:if isTrue="{!$Browser.formFactor == 'DESKTOP'}">
    You are using a DESKTOP
        ( <lightning:icon iconName="utility:desktop" size="x-small" alternativeText="Indicates approval"/> )
        Browser device
    </aura:if>
    <aura:if isTrue="{!$Browser.formFactor == 'PHONE'}">
    You are using a Phone, This message is rendered using formFactor
    </aura:if>
    <aura:if isTrue="{!$Browser.formFactor == 'TABLET'}">
    You are using a Table device
    </aura:if>
</aura:component>


<aura:application extends="force:slds">
    <c:DetectDevice />
</aura:application


var device = $A.get("$Browser.formFactor");

               How to Find Salesforce Object ID prefixes (custom or standard)

If you want to check for standard object replace customObject__c with standardObjectName
system.debug('Prifix–> ' + customObject__c.sobjecttype.getDescribe().getKeyPrefix());


Saturday 2 February 2019

                                     DATALOADER:






A. Log In Issues: Are You Timed Out?

If you leave the Data Loader running on your machine, it will time out in the number of seconds you have defined in the Settings:If the Data Loader has timed out, and you try to perform another operation with it, you will receive a message like this one:
The message looks a bit ominous, and if you are seeing it for the first time

B. Are you logging into sandbox or production?-check server host url properly(https://test.salesforce.com for a sandbox org and https://login.salesforce.com for a production org)

C.Log In Issues: Do you need a security token?

Unless your IP address is trusted by the Salesforce org you are trying to log into, you will need to add your security token to the end of your password in order to log into the Data Loader.

Keep track of your security tokens – you need one for each production org and each sandbox org for which your IP address is not trusted.

Either add your security token to the end of your password string, or trust your IP address. Be careful trusting IP addresses – doing so reduces the protection on your Salesforce org.

To trust your IP address, obtain the IP address from your system. Then, in Salesforce, under Administration Setup => Security Controls =>Network Access, enter your IP Address as the Start IP Address and End IP Address, or enter a range that includes your IP Address.


Loading Null Values into Fields

Sometimes you may need to use the Data Loader to “null out” a value and load blank values for one field for one or more records.

In the Data Loader, select Insert null values. It is recommended that you only select this option when you specifically intend to insert null values. 

Don’t leave it selected because you may inadvertently erase data if you map a blank column to a field when you are data loading.


Loading Data When Same Record is Updated More than Once

The Data Loader limits the number of records you can update with an upsert in the same batch. If you try to upsert the same record more than time in the same batch, you will receive an error message like one of the following:

duplicate value found: unknown duplicates value on record with id: a044000000HpfNS

Duplicate external id specified: 12345


Depending on the situation, the data you are trying to load may need to be analyzed, for example, to determine the most recent update, or some other criterion of precedence.

However, if you know that all the upserts need to be loaded, you can eliminate this obstacle by reducing the Data Loader batch size to one. Each record will then load, regardless of whether that record was already upserted earlier in the data load.


Show All Salesforce Objects

The Data Loader defaults to showing the most common standard objects and your org’s custom objects when you insert/update/upsert/delete/export.

However, there are other objects that you can access by selecting Show all Salesforce objects when you begin your data loader operations.

Using Data Loader to Write SOQL Queries

When you delete/export Salesforce records using the Data Loader, you are performing a SOQL query. The generated query appears at the bottom of the Data Loader dialog. Add filters to the query by first selecting from the fields in object you are querying, and then selecting an operation and choosing a value.

Account: id value of incorrect type: #N/A

This example error is for the Account object, but where the error reads “Account,” it could be any standard or custom Salesforce object. The word(s) after the colon in this error refer to what was found in the column mapped to the Account ID – in this case, the column for Account read “#N/A.” This value is typical of using a vlookup function in Excel to build your data load file and getting no results for this row.

There is no way to update a Salesforce record without its Salesforce ID. If you have values for another field on the object that is defined as a foreign key (or “unique identifier” in Salesforce), you can use that field to upload data, but you have to perform an upsert.

Error converting value to correct data type: Failed to parse date: N/A

Error converting value to correct data type: Failed to parse date: 00:00.0

The above are two examples of errors when the data being mapped is not of the correct format for the date field to which it is being mapped. You can tell by what follows the colon in the error; this is what the Data Loader is finding and trying to map to a date. See above for help with Date/Time format.

Insufficient access rights on cross-reference ID

Insufficient access rights messages pertain to the owner of the record that is being modified. So, if you are loading an owner ID (using the Salesforce ID of someone’s User record), then that person has insufficient access (permission) to what you are trying to insert or update.

If you are not loading an Owner ID for the records, then you (the user logged into the Data Loader) do not have permission to insert or update. If you are a System Admin, check for the following:

An unassigned record type for the object (it must be one of the record types for that object that is assigned to your profile in order for you to be able to create records of that record type)
An inactive record type for the object
A field that it is read-only for the System Admin profile (it may be read-only for all profiles)
Similarly, if you see this error:

Record Type ID: this ID value isn’t valid for the user

Check to make sure:

Is it active?
Does the record owner’s profile have access to the record type?
Is the ID correct for record type – no typos, or other errors in the string?
Invalid cross-reference ID

This error is related to the other ID errors. It indicates that you are trying to load some value (or a blank value) for an external ID for a custom object that does not exist for any record in that object. For example, trying to load a reference to Contact with “9013133” as a Student_ID__c (where Student_ID__c is defined as a unique external ID for Contact) when you don’t have a Contact in your org with that Student_ID__c value.

It is also possible that the user performing the load does not have access to the Student_ID__c field (in the example). To check on this second possibility, manually try to access one of the Contact records with one of the Student_ID__c values that is giving this error, such as by building a view of Contacts with Student_ID__c = “9013133” (which should return exactly one Contact if you have access to the field and that value exists for one of the Contact records.

npe01.IndividualAccounts: execution of BeforeInsert

Any error message that references BeforeInsert, BeforeUpdate, or another Apex operation is most likely being triggered by some existing code in your organization. Review the code base for the object to which you are trying to insert or update records.

If there is a Foreign Key, you must include a Legacy System ID.

Sometimes the error is caused by existing validation rules in your Salesforce org. To recognize such errors, use consistent language for your validation rule error messages and if you need to be able to load data – for example, legacy data – that does not have to be consistent with validation rules, consider making an exception to the validation rule, such as a Custom Setting that keeps it from running when the user is the System Administrator.



Links:

https://www.salesforcetutorial.com/salesforce-data-loader/

Friday 25 January 2019

What will happen if profile related to user U1 above in role hierarchy doesn’t have CRUD permission for object say A. User U2 below in his role hierarchy have CRUD permission to object A. Will user U1 will be able to see or edit record if Grant Access Using Hierarchies is checked for object A in sharing settings?

No.If a user does not have read or edit access to an object via OWD, a profile or permission set, they will have no visibility over an object regardless of their role and role hierarchy.

Always remember that User above in role hierarchy can see records of users below in hierarchy but operation which he can perform depends on permission on his profile (CRUD & View All & Modify All).

 If a user does not have access to a specific record type, will they be able to see the records that have that record type?

Yes. Record type controls only visibility of record on UI not its access to users.



How to check whether user has access to a particular record or not?

Query “userRecordAccess” to check whether has access to record or not.


For example:

SELECT RecordId, HasReadAccess, HasTransferAccess, MaxAccessLevel, HasAllAccess, HasDeleteAccess, HasEditAccess FROM UserRecordAccessWHERE UserId = “005xxxxxxxxx”AND RecordId = “001xxxxxxxx”

HasAllAccess Indicates whether a user has all access–read, edit, delete, and transfer—to the record (true) or not (false).

HasReadAccess, HasEditAccess , HasDeleteAccess ,HasTransferAccess return Boolean value.

MaxAccessLevel return access level like None, read, Edit,Delete,Transfer and All.