You need to sign in to do that
Don't have an account?
Deja Bond
Get a default value for a look up to be the current user in apex
Hi all,
I am trying to have my Candidate Lookup field on my UI to default to the current user
public LightningActivity(Contact candidateRecord){
this();
system.debug(candidateRecord);
string userid = UserInfo.getUserID(); // getting current user info
List<MTX_Matrix_Candidate__c> user= [SELECT Id, Name, Candidate__c FROM MTX_Matrix_Candidate__c
WHERE Id =: userid]; //storing the query into list for user
if(candidateRecord.Candidate__c == null) //checking to see if the lookup is populated
{
candidateRecord.Candidate__c = user.candidateName; //default to the current user
}
}
Right now the Candidate Look up is blank, can someone help me with my code?
I am trying to have my Candidate Lookup field on my UI to default to the current user
public LightningActivity(Contact candidateRecord){
this();
system.debug(candidateRecord);
string userid = UserInfo.getUserID(); // getting current user info
List<MTX_Matrix_Candidate__c> user= [SELECT Id, Name, Candidate__c FROM MTX_Matrix_Candidate__c
WHERE Id =: userid]; //storing the query into list for user
if(candidateRecord.Candidate__c == null) //checking to see if the lookup is populated
{
candidateRecord.Candidate__c = user.candidateName; //default to the current user
}
}
Right now the Candidate Look up is blank, can someone help me with my code?
Egor Gerasimenko 9
First of all, `user` is a list. How do you expect to get the field `candidateName` from a list of records? Second, you never queried for the field `candidateName`. You only queried for Id, Name, Candidate__c