function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ramon PereiraRamon Pereira 

Capture id Account

I have a field (account.id) that opens a window to search. I would like to capture the id of the account that I selected. In my organization I have multiple accounts with the same name and perform a SOQL query passing the name as parameter end up retrieving the wrong record. Someone has gone through this problem?

Best Answer chosen by Admin (Salesforce Developers) 
Ramon PereiraRamon Pereira

I managed to solve.
It has a hidden field type that is filled when you select some information using the lookup. This field has the id of the field that has the lookup and acresenta "_lkid" at the end of your id field. Ex: field id = "accoountid" Have your lookup field will be hidden id = "accoountid__lkid."

All Answers

SFAdmin5SFAdmin5

Can you provide more detail on exactly what you're doing or trying to do?  

Ramon PereiraRamon Pereira

OK,

I have the following page: 

 

<apex:pageBlock title="Novo Pedido Rápido" helpTitle="ajuda(Somente Rede CNC)" helpUrl="http://www.google.com.br" id="bloc1" >
            <apex:pageBlockSection title="Informações Básicas" showHeader="true" collapsible="false" id="blocf1" >
                <apex:panelGrid columns="8" cellpadding="08" >
                        <apex:outputLabel for="campoNomeConta" > Cliente:</apex:outputLabel>
                        <apex:inputField value="{!opportunity.accountId}" required="true" id="campoConta" onchange="mover_valor();setaData();retornaContato()" />
                        <apex:outputLabel value="{!Opportunity.name}" for="campoPedido" title="Teste" > Nome: </apex:outputLabel>
                        <apex:inputField value="{!Opportunity.name}" id="campoPedido" label="Nome do Pedido:" />
                        <apex:outputLabel for="fasePedido" > Fase: </apex:outputLabel>
                        <apex:inputField value="{!opportunity.StageName}" id="fasePedido" />                         
                        <apex:outputLabel value="{!opportunity.createdDate}">Data: </apex:outputLabel>
                        <apex:inputField value="{!opportunity.CloseDate}" id="dataPedido" />
                        <apex:outputLabel >Condição Pagamento:</apex:outputLabel>
                        <apex:inputField value="{!opportunity.Condicao_de_pagamento__c}" required="true"/>
                        <apex:outputLabel >Tipo de Pedido:</apex:outputLabel>
                        <apex:inputField value="{!opportunity.Tipo_de_Pedido__c}" required="true" id="tipoPedido"/>
                        <apex:outputLabel for="campoContato" >Contato: </apex:outputLabel>
                        <apex:inputField value="{!opportunity.Contato_do_cliente__c}" id="campoContato"/>
                        
               </apex:panelGrid>
               
            </apex:pageBlockSection>

 In the field ( <apex:inputField value="{!opportunity.accountId}" required="true" id="campoConta" onchange="mover_valor();setaData();retornaContato()" />) I capture the value of it and call a javascript function to access my controller (@ remoteAction). But to capture the value of the field, he gave me the name and not the ID. My query in SOQL would be more accurate if the account ID and not the name, since I have several accounts with the same name.

 

One of the functions that call is this: 

@remoteAction 
	global static List<Contact> retornaContato(String nomeConta){
		List<Contact> listContato = new List<Contact>(); 
		Contact cont = new Contact();		
		String nomeContato; 
		listContato =[SELECT name 
		FROM CONTACT 
		WHERE Account.Name = :nomeConta 
		AND Contato_principal__c = true ];
		
		nomeContato = listContato.get(0).Name;
		
		return listContato ; 
	}

 No lugar de (Where Account.Name =:nomeConta) gostaria de passar (Where Account.Id =: idAccounta) da conta, assim minha consulta poderar trazer o contato automatico. 

 

vishal@forcevishal@force

Hi,

 

Can you share the functions where you're passing the value? (Opportunity.AccountId)

Ramon PereiraRamon Pereira

Hello,

The Account.id field is a field of research that I click on a magnifying glass and opens a window for me with the bills that I can select. When selecting an account it sets the value of the field with the account name. From this name I realize some conultas in SOQL to bring information relating to this account. However in my organization, I have several accounts with the same name and end up bringing other account information. In the image shown below is the window that I use to search for your account.

 

Ramon PereiraRamon Pereira

Hello,

 

 

By doing some research on the forums, I found something like customize lokup standard sales force. However in my case it will not be necessary if I can capture the ID that lokup capture internally because it captures the name and Id of the selected record, put the id is not shown to the User.

Ramon PereiraRamon Pereira

I managed to solve.
It has a hidden field type that is filled when you select some information using the lookup. This field has the id of the field that has the lookup and acresenta "_lkid" at the end of your id field. Ex: field id = "accoountid" Have your lookup field will be hidden id = "accoountid__lkid."

This was selected as the best answer