+ Start a Discussion
Salesforce BlitzSalesforce Blitz 

get record name from record id

How do i need to fetch record name from record id in salesforce


Thanks
Laxman
sandeep sankhlasandeep sankhla
Hi Laxman,

You can do a simple query and get all the details of the record if you have id.

Ex:
 
Select Id, Name, Address, Email, Phone from Account where Id =: strAccountId;

thanks!
Rupal KumarRupal Kumar

Hi Laxman,

Use this query-: 
string qr = 'select id, CaseNumber from '+match+' where id='+'\'' + BrowserURLId + '\''
Recommend link-http://salesforce.stackexchange.com/questions/5072/how-to-get-record-name-passing-object-name-record-id-dynamically


Thanks
Rupal Kumar
http://mirketa.com
 
Salesforce BlitzSalesforce Blitz
Hi Sandeep.

Forgt to mention,..
I need to get the name without using any SQOL

Thanks
reymagdaongreymagdaong
Can you elaborate more on how exactly you are going to use the name or id? is from a page/trigger/apex? thanks.
Salesforce BlitzSalesforce Blitz
No..Not through page
I have a list of ids in sa controller method.

I need to get the names of the record and display them..

Thanks
reymagdaongreymagdaong
Hi, ok. I cannot think of way to retrieve the name but SOQL.

Try this
 
Set<Id> listOfIds = new Set<Id>();
// load some data into the listOfIds

List<CustomObject__c> cList = [select name from CustomObject__c where id in:listOfIds];

then use the cList to display.

alternatively if you are just using a list view you can check this link.
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_sosc_list_views.htm




 
Anil Kumar GandlaAnil Kumar Gandla
<apex:page controller="accountdef" standardStylesheets="true" showHeader="false">
    <apex:form >
        <apex:pageBlock title="Search Account Record's Id based on Name and Vice-Versa">
            <apex:pageBlockSection >
                <apex:inputText label="Input" value="{!Text}"/>
                <apex:commandButton value="Search" action="{!GetResult}"/>
                <apex:outputText label="Output" value="{!Output}">
                </apex:outputText>
            </apex:pageBlockSection>        
        </apex:pageBlock>
    </apex:form>
</apex:page>
----------------------------
public class accountdef
{
    public string Text{get;set;}
    public string output{get;set;}
    public Void GetResult()
    {
        if(Text!=null && Text!='')
        {
            Account Acc=[select id,name from Account where id=:Text or name=:Text];
            if(Text==acc.name)
            {
                Output=acc.id;
            }
            else
            {
                Output=acc.name;
            }
            
        }
    }
}