+ Start a Discussion
SolidLucasSolidLucas 

How to load data from a logged user

Hello guys, i would like to know how can i load data from contact of the logged user. someone could give some example

Regards,Lucas.

Balaji BondarBalaji Bondar
Hi Lucas,

To load data, salesforce.com require the sfdc user account with approprite credentials.Let me know if you are looking for someting different.
SolidLucasSolidLucas

Hi Balaji,

So I'm trying to display those data when the user is logged in on salesforce through a visualForce page.

My controller

 

public with sharing class AnalyticsRevendaController {
	public Account contas  {get;set;}     
    public Contact contato {get;set;}
    public User	   usuario {get;set;}
    
    //Retorna os dados do usuário Logado
    public String userId = UserInfo.getUserId();
    public User activeUser = [SELECT AccountId,ContactId,LastName,FirstName,Email FROM User 
    						  WHERE Id = :userId LIMIT 1];
    						  
    public String userAccount = activeUser.AccountId;
    public String userContact = activeUser.ContactId;  
    
    //retorna os valores da conta.
    public Account getAccount(){
    	
    	contas = [SELECT a.OwnerId, a.Name From Account a
        			  WHERE Id =:userId];
        return contas;
    	}
    	
    //retorna os valores do contato	
    public Contact getContact(){
    		contato = [SELECT c.FirstName, c.AccountId FROM Contact c
    				   WHERE Id=:userId];
    		return contato;		   
    	}	
	}
 

My visualForce page

 

<apex:page controller="AnalyticsRevendaController">
	<apex:form>
		<apex:pageBlock>
			<apex:pageBlockSection  title="Contato">
				<apex:inputField value ="{!Contact.FirstName}" />
				<apex:inputField value ="{!Contact.LastName}" />
				<apex:inputField value ="{!Contact.Email}" />
			</apex:pageBlockSection>
			<apex:pageBlockSection  title="Conta">
				<apex:inputField value ="{!Account.Name}" />
				<apex:inputField value ="{!Account.OwnerId}" />
			</apex:pageBlockSection>
			<apex:pageBlockSection  title="Usuário">
				<apex:inputField value ="{!User.Name}" />
				<apex:inputField value ="{!User.LastName}" />
				<apex:inputField value ="{!User.Email}" />
			</apex:pageBlockSection>
		</apex:pageBlock>
	</apex:form>
</apex:page>
 

 

Balaji BondarBalaji Bondar
Hi,

You have to compaire the record OwerId with current logged in user to show user related records:
public with sharing class AnalyticsRevendaController {
	public Account contas  {get;set;}     
    public Contact contato {get;set;}
    public User	   usuario {get;set;}
    
    //Retorna os dados do usuário Logado
    public String userId = UserInfo.getUserId();
    //public User activeUser = [SELECT AccountId,ContactId,LastName,FirstName,Email FROM User 
    						  WHERE Id = :userId LIMIT 1];
    						  
    //public String userAccount = activeUser.AccountId;
    //public String userContact = activeUser.ContactId;  
    
    //retorna os valores da conta.
    public Account getAccount(){
    	
    	contas = [SELECT a.OwnerId, a.Name From Account a
        			  WHERE a.OwnerId =:userId];
        return contas;
    	}
    	
    //retorna os valores do contato	
    public Contact getContact(){
    		contato = [SELECT c.FirstName, c.AccountId FROM Contact c
    				   WHERE c.OwnerId=:userId];
    		return contato;		   
    	}	
	}
Important :
If this is what you were looking for then please mark it as a "SOLUTION" or You can Click on the "Like" Button if this was beneficial for you.
SolidLucasSolidLucas
you mean something like this?
 
public with sharing class AnalyticsRevendaController {
	public Account contas  {get;set;}     
    public Contact contato {get;set;}
    public User	   usuario {get;set;}
    
    public Account AccountInfo(Account acc, Contact con)	{
		this.Conta = acc;
		this.Contato = con;
	}
    
    //Retorna os dados do usuário Logado
    public String userId = UserInfo.getUserId();
    public User activeUser = [SELECT AccountId,ContactId,LastName,FirstName,Email FROM User 
    						  WHERE  Id = :userId LIMIT 1];   						  
    public String userAccount = activeUser.AccountId;
    public String userContact = activeUser.ContactId;  
    
    //retorna os valores da conta.
    public Account getAccount(){
    	List<AccountInfo> contas;
		contas = new List<Account>();
		Account conta = null;
		try{
			
			Set<Id> setConta = new Set<Id>();
		
			list<Account> listConta = [SELECT Id,Name,ParentId FROM Account 
									   WHERE Id = :userAccount];
			
			if(listConta[0].ParentId != null)
				setConta.add(listConta[0].ParentId);
				setConta.add(listConta[0].Id);
    	}
    }
    	
    //retorna os valores do contato	
    public Contact getContact(){
    		contato = [SELECT c.FirstName, c.AccountId FROM Contact c
    				   WHERE Id=:userId];
    		return contato;		   
    	}	
	}