20 votes
Accepted

How to get an 18 digit ID from 15 digit ID using SOQL

To convert it to 18 digits you can simply set it to an Id type variable: Id someId = '001J000001eun1Q'; Which will automatically convert it for you: system.debug(someId); // 001J000001eun1QIAQ ...
18 votes
Accepted

What are the Salesforce Pod ID to instance mappings?

As per Converting the Salesforce Pod Id to ServerUrl/Name, I started the mapping process from the source code of Workbench. That list however is largely out of date. As a community resource I've ...
14 votes
Accepted

Converting uppercased 18-digit Id to valid Id

I ported Daniel Ballinger's answer here to Apex: static String CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ012345'; static List<Boolean> getBitPattern(String c) { Integer index = CHARS.indexOf(c....
  • 144k
13 votes
Accepted

What is the value of the first and final record id for an object?

Most of what you need to know is covered in What are Salesforce ID's composed of? In short, only the last 9 characters of the ID are incremented from record to record. E.g. 0010a0000000001 to ...
12 votes
Accepted

Convert Datetime to string in GMT format?

Use DateTime's formatGMT to format the time according to your specs in GMT. String formatedDt = dt.formatGMT('yyyy-MM-dd\'T\'HH:mm:ss\'Z\'');
  • 445k
10 votes

Converting uppercased 18-digit Id to valid Id

Parallel to Adrian's response I also cooked up my own version for reference; public static Id correctCapitalizedId(String input) { String keyString = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ012345', result = '...
  • 773
10 votes

Distance between Salesforce ID indicates activity of other tenants

No. IDs are not always sequential, you don't know the volume of records created by other tenants, IDs are globally unique, and records are deleted all the time. Having worked at Salesforce, I got ...
  • 5,651
9 votes

Does anybody have a good way of mapping a key prefix to an object type?

If you only have the key prefix you can pad it out with the empty id string: String emptyId = '000000000000AAA'; String prefix = '00D'; ID myId = prefix + emptyId; System.debug(myID.getSObjectType()....
9 votes
Accepted

Check if a record exists without knowing its type

You just need to make an Id instance from your String value, which you can do with Id.valueOf(stringValue). If you want to simply get a Boolean whether or not a corresponding record exists, you can do:...
  • 144k
9 votes
Accepted

getting the owner's name from a SOQL query

You can access the name of the owner using Owner as the name of the relationship between the objects. Owner.Name, Account__r.Owner.Name
  • 12.4k
9 votes

Shared API User

This is a pretty common approach on small instances (and some large ones too). I usually name the user "Integration User"; some orgs call it "System" or something like that. It's ...
  • 88.2k
9 votes
Accepted

How to choose using Collection<Id> rather than Collection<String>, or the opposite?

Both String and Id are primitive data types in apex. Consider below scenario: public class poc { static List<Id> ids = new List<Id>(); public static void check() { try { ...
9 votes

Is There a Way to Know if an Id Exists Without Querying?

The answer is NO A far better practice is to store API names in custom settings/custom metadata and query for the resource by apiName in the code: API Names are more transparent than IDs Custom ...
  • 63.8k
8 votes
Accepted

Ids in Salesforce - Same across environments?

yes the record type ids will be the same. And that's not just for record types, field ids and any object prefixes (first three parts of a record id) will also be the same. they will differ. If you ...
  • 672
8 votes

Formula Field Changing the Date to Today

Your formula evaluates every time you retrieve it's value. So at any point in time your formula will evaluate today() which will be the actual date/time. The solution would be to create a workflow ...
8 votes
Accepted

Does salesforce assign Ids of deleted Records to new records?

No, new records always receive new IDs, and they are generally allocated in sequential order within the same transaction (but, not guaranteed, so do not depend on that behavior). The only exception to ...
  • 445k
8 votes

Embed a Flow in a lightning web Component

You can embed a flow in LWC using the new lightning-flow component (from Winter '23 platform release). To embed a flow simply use the below: <lightning-flow flow-api-name="flow_api_name" ...
8 votes
Accepted

When do we need to mention Id explicitly in SOQL querry

There is no "benefit" as such by including it when your SOQL contains one or more other fields being queried as it is always returned in Apex queries, whether it is specified in the query or ...
  • 4,819
7 votes
Accepted

Get the ID of a lookup field for Onclick Javascript Button

I figured it out, you need to add 'Id' to the end of your field before '__c'. Here an example of my code (each of these fields is a lookup field other than the project ID): {!REQUIRESCRIPT("/soap/...
  • 86
7 votes

Add a custom field to multiple objects

Assuming all the objects are already created, you could create a file that simply contains the one field definition you need, copy it, and deploy it. I'd say this task is probably easiest with Ant, ...
  • 445k
6 votes

How can I convert a 15 char Id value into an 18 char Id value?

Python version import string import sys bin_lookup = { '00000':'A', '00001':'B', '00010':'C', '00011':'D', '00100':'E', '00101':'F', '00110':'G', '00111':'H', '...
  • 161
6 votes
Accepted

Entity Id Across Multiple Orgs

Behavior of custom object prefix ID when using Change Sets Knowledge Article Number: 000176809 Depending on the type of Sandbox you are using, a custom object prefix ID might change upon deploying ...
  • 13.3k
6 votes
Accepted

Need Help in Making Dynamic Sooql using Like Operator

In your case String tempInput ='\'%' + inputValue2 + '%\''; soqlRAD2 = soqlRAD2 + ' and BR_Opportunity__r.Account.name Like :'+tempInput ; Just remove colon : like this String tempInput ='\'%' + ...
  • 22.1k
6 votes
Accepted

Duplicate ID error - Don't understand other explanations

Ok, there's a few things going on here to sort out. 1. Query in a loop you have a query inside of a loop. There are very few good reasons to ever do that, and you should view it as an anti-pattern ...
  • 24.8k
6 votes
Accepted

Get Contact Record from Account List

List<Account> accounts = [Select Id,(Select Id,FirstName, LastName From Contacts), Name, BillingCountry from Account]; for(Account objAcc:accounts ) { //iterate over contact. here objAcc....
  • 22.1k
6 votes

Salesforce Lightning: How can i get session Id of current user in Salesforce lightning component?

Take a look into the document mentioned here .You cannot use the session obtained from userinfo to make REST API calls using the @AuraEnabled methods for Security reasons . Salesforce recommends ...
6 votes
Accepted

Salesforce Lightning error handling

It's a known issue. You can find the details here. Custom error messages not displayed in Lightning Experience when uploading files Summary:- Server error messages (added via addError() for ...
  • 13.4k
6 votes

Illegal assignment from Id to List

As it says, you're trying to assign an Id (a scalar value) to a collection. You need a loop for this: Id[] voterIds = new Id[0]; for(Vote__c record: [SELECT Id FROM Vote__c WHERE Suggestion__c = :...
  • 445k
6 votes

How to get list of all sobject records modified today in the system?

Simpler way? well yes and no. We have Database.getUpdated method that returns Id of records updated in a particular time span. It takes sObject Type , start date and end date as arguments and returns ...
6 votes
Accepted

How to pass the record id to controller method from LWC

When you have an LWC that works in Lightning Record Pages, it can automatically receive the record ID by declaring an API property: @api recordId; The LWC framework ensures this gets set when the ...
  • 28.7k

Only top scored, non community-wiki answers of a minimum length are eligible