Skip to main content
Added code mentioned in comment in OP
Source Link
Dan Jones
  • 7.3k
  • 4
  • 41
  • 63

I'm having trouble passing through the value of a Lookup field on Insert. I've got an object called ts2__Project_Job__c, which has a custom Lookup field called Candidate__c which looks at the Contact standard object. In my Application I simply want to use this Lookup field, to find a contact, then Insert a new record.

Here's what I've got:

VisualForce

<apex:inputField id="candidate" value="{!contactLookup.Candidate__c}" />

Apex

This is used to get the value:

public ts2__Project_Job__c contactLookup {
  get;
  set;
}

This is used to instantiate:

contactLookup = new ts2__Project_Job__c();

So far, so good. It creates the Lookup field on the VF Page and it works great! However, when trying to Insert using the following code:

pro.Candidate__c = candidate;

after initializingAfter initialising pro as:

ts2__Project_Job__c pro = new ts2__Project_Job__c();

I get the error:

Illegal assignment from ts2__Project_Job__c to Id

I've tried using

pro.Candidate__c = candidate.Id;

Which will save and create the record, but won't populate the field. Debug logs show that this is blank, whereas the variable candidate does have an Id in there. It's just the wrong type. I've tried using:

Id candidate = String.valueOf(contactLookup);

And passing this through, but nothing happens again.

Kind of stuck on this one!

Thanks!

Edit: When using:

pro.Candidate__c = contactLookup.Id;

I'm getting the following in the debug logs:

System.NullPointerException: Attempt to de-reference a null object

I'm having trouble passing through the value of a Lookup field on Insert. I've got an object called ts2__Project_Job__c, which has a custom Lookup field called Candidate__c which looks at the Contact standard object. In my Application I simply want to use this Lookup field, to find a contact, then Insert a new record.

Here's what I've got:

VisualForce

<apex:inputField id="candidate" value="{!contactLookup.Candidate__c}" />

Apex

This is used to get the value:

public ts2__Project_Job__c contactLookup {
  get;
  set;
}

This is used to instantiate:

contactLookup = new ts2__Project_Job__c();

So far, so good. It creates the Lookup field on the VF Page and it works great! However, when trying to Insert using the following code:

pro.Candidate__c = candidate;

after initializing pro as

ts2__Project_Job__c pro = new ts2__Project_Job__c();

I get the error:

Illegal assignment from ts2__Project_Job__c to Id

I've tried using

pro.Candidate__c = candidate.Id;

Which will save and create the record, but won't populate the field. Debug logs show that this is blank, whereas the variable candidate does have an Id in there. It's just the wrong type. I've tried using:

Id candidate = String.valueOf(contactLookup);

And passing this through, but nothing happens again.

Kind of stuck on this one!

Thanks!

Edit: When using:

pro.Candidate__c = contactLookup.Id;

I'm getting the following in the debug logs:

System.NullPointerException: Attempt to de-reference a null object

I'm having trouble passing through the value of a Lookup field on Insert. I've got an object called ts2__Project_Job__c, which has a custom Lookup field called Candidate__c which looks at the Contact standard object. In my Application I simply want to use this Lookup field, to find a contact, then Insert a new record.

Here's what I've got:

VisualForce

<apex:inputField id="candidate" value="{!contactLookup.Candidate__c}" />

Apex

This is used to get the value:

public ts2__Project_Job__c contactLookup {
  get;
  set;
}

This is used to instantiate:

contactLookup = new ts2__Project_Job__c();

So far, so good. It creates the Lookup field on the VF Page and it works great! However, when trying to Insert using the following code:

pro.Candidate__c = candidate;

After initialising pro as:

ts2__Project_Job__c pro = new ts2__Project_Job__c();

I get the error:

Illegal assignment from ts2__Project_Job__c to Id

I've tried using

pro.Candidate__c = candidate.Id;

Which will save and create the record, but won't populate the field. Debug logs show that this is blank, whereas the variable candidate does have an Id in there. It's just the wrong type. I've tried using:

Id candidate = String.valueOf(contactLookup);

And passing this through, but nothing happens again.

Kind of stuck on this one!

Thanks!

Edit: When using:

pro.Candidate__c = contactLookup.Id;

I'm getting the following in the debug logs:

System.NullPointerException: Attempt to de-reference a null object

I'm having trouble passing through the value of a Lookup field on Insert. I've got an object called ts2__Project_Job__c, which has a custom Lookup field called Candidate__c which looks at the Contact standard object. In my Application I simply want to use this Lookup field, to find a contact, then Insert a new record.

Here's what I've got:

VisualForce

<apex:inputField id="candidate" value="{!contactLookup.Candidate__c}" />

Apex

This is used to get the value:

public ts2__Project_Job__c contactLookup {
  get;
  set;
}

This is used to instantiate:

contactLookup = new ts2__Project_Job__c();

So far, so good. It creates the Lookup field on the VF Page and it works great! However, when trying to Insert using the following code:

pro.Candidate__c = candidate;

after initializing pro as

ts2__Project_Job__c pro = new ts2__Project_Job__c();

I get the error:

Illegal assignment from ts2__Project_Job__c to Id

I've tried using

pro.Candidate__c = candidate.Id;

Which will save and create the record, but won't populate the field. Debug logs show that this is blank, whereas the variable candidate does have an Id in there. It's just the wrong type. I've tried using:

Id candidate = String.valueOf(contactLookup);

And passing this through, but nothing happens again.

Kind of stuck on this one!

Thanks!

Edit: When using:

pro.Candidate__c = contactLookup.Id;

I'm getting the following in the debug logs:

System.NullPointerException: Attempt to de-reference a null object

I'm having trouble passing through the value of a Lookup field on Insert. I've got an object called ts2__Project_Job__c, which has a custom Lookup field called Candidate__c which looks at the Contact standard object. In my Application I simply want to use this Lookup field, to find a contact, then Insert a new record.

Here's what I've got:

VisualForce

<apex:inputField id="candidate" value="{!contactLookup.Candidate__c}" />

Apex

This is used to get the value:

public ts2__Project_Job__c contactLookup {
  get;
  set;
}

This is used to instantiate:

contactLookup = new ts2__Project_Job__c();

So far, so good. It creates the Lookup field on the VF Page and it works great! However, when trying to Insert using the following code:

pro.Candidate__c = candidate;

I get the error:

Illegal assignment from ts2__Project_Job__c to Id

I've tried using

pro.Candidate__c = candidate.Id;

Which will save and create the record, but won't populate the field. Debug logs show that this is blank, whereas the variable candidate does have an Id in there. It's just the wrong type. I've tried using:

Id candidate = String.valueOf(contactLookup);

And passing this through, but nothing happens again.

Kind of stuck on this one!

Thanks!

Edit: When using:

pro.Candidate__c = contactLookup.Id;

I'm getting the following in the debug logs:

System.NullPointerException: Attempt to de-reference a null object

I'm having trouble passing through the value of a Lookup field on Insert. I've got an object called ts2__Project_Job__c, which has a custom Lookup field called Candidate__c which looks at the Contact standard object. In my Application I simply want to use this Lookup field, to find a contact, then Insert a new record.

Here's what I've got:

VisualForce

<apex:inputField id="candidate" value="{!contactLookup.Candidate__c}" />

Apex

This is used to get the value:

public ts2__Project_Job__c contactLookup {
  get;
  set;
}

This is used to instantiate:

contactLookup = new ts2__Project_Job__c();

So far, so good. It creates the Lookup field on the VF Page and it works great! However, when trying to Insert using the following code:

pro.Candidate__c = candidate;

after initializing pro as

ts2__Project_Job__c pro = new ts2__Project_Job__c();

I get the error:

Illegal assignment from ts2__Project_Job__c to Id

I've tried using

pro.Candidate__c = candidate.Id;

Which will save and create the record, but won't populate the field. Debug logs show that this is blank, whereas the variable candidate does have an Id in there. It's just the wrong type. I've tried using:

Id candidate = String.valueOf(contactLookup);

And passing this through, but nothing happens again.

Kind of stuck on this one!

Thanks!

Edit: When using:

pro.Candidate__c = contactLookup.Id;

I'm getting the following in the debug logs:

System.NullPointerException: Attempt to de-reference a null object

added 190 characters in body
Source Link
Dan Jones
  • 7.3k
  • 4
  • 41
  • 63

I'm having trouble passing through the value of a Lookup field on Insert. I've got an object called ts2__Project_Job__c, which has a custom Lookup field called Candidate__c which looks at the Contact standard object. In my Application I simply want to use this Lookup field, to find a contact, then Insert a new record.

Here's what I've got:

VisualForce

<apex:inputField id="candidate" value="{!contactLookup.Candidate__c}" />

Apex

This is used to get the value:

public ts2__Project_Job__c contactLookup {
  get;
  set;
}

This is used to instantiate:

contactLookup = new ts2__Project_Job__c();

So far, so good. It creates the Lookup field on the VF Page and it works great! However, when trying to Insert using the following code:

pro.Candidate__c = candidate;

I get the error:

Illegal assignment from ts2__Project_Job__c to Id

I've tried using

pro.Candidate__c = candidate.Id;

Which will save and create the record, but won't populate the field. Debug logs show that this is blank, whereas the variable candidate does have an Id in there. It's just the wrong type. I've tried using:

Id candidate = String.valueOf(contactLookup);

And passing this through, but nothing happens again.

Kind of stuck on this one!

Thanks!

Edit: When using:

pro.Candidate__c = contactLookup.Id;

I'm getting the following in the debug logs:

System.NullPointerException: Attempt to de-reference a null object

I'm having trouble passing through the value of a Lookup field on Insert. I've got an object called ts2__Project_Job__c, which has a custom Lookup field called Candidate__c which looks at the Contact standard object. In my Application I simply want to use this Lookup field, to find a contact, then Insert a new record.

Here's what I've got:

VisualForce

<apex:inputField id="candidate" value="{!contactLookup.Candidate__c}" />

Apex

This is used to get the value:

public ts2__Project_Job__c contactLookup {
  get;
  set;
}

This is used to instantiate:

contactLookup = new ts2__Project_Job__c();

So far, so good. It creates the Lookup field on the VF Page and it works great! However, when trying to Insert using the following code:

pro.Candidate__c = candidate;

I get the error:

Illegal assignment from ts2__Project_Job__c to Id

I've tried using

pro.Candidate__c = candidate.Id;

Which will save and create the record, but won't populate the field. Debug logs show that this is blank, whereas the variable candidate does have an Id in there. It's just the wrong type. I've tried using:

Id candidate = String.valueOf(contactLookup);

And passing this through, but nothing happens again.

Kind of stuck on this one!

Thanks!

I'm having trouble passing through the value of a Lookup field on Insert. I've got an object called ts2__Project_Job__c, which has a custom Lookup field called Candidate__c which looks at the Contact standard object. In my Application I simply want to use this Lookup field, to find a contact, then Insert a new record.

Here's what I've got:

VisualForce

<apex:inputField id="candidate" value="{!contactLookup.Candidate__c}" />

Apex

This is used to get the value:

public ts2__Project_Job__c contactLookup {
  get;
  set;
}

This is used to instantiate:

contactLookup = new ts2__Project_Job__c();

So far, so good. It creates the Lookup field on the VF Page and it works great! However, when trying to Insert using the following code:

pro.Candidate__c = candidate;

I get the error:

Illegal assignment from ts2__Project_Job__c to Id

I've tried using

pro.Candidate__c = candidate.Id;

Which will save and create the record, but won't populate the field. Debug logs show that this is blank, whereas the variable candidate does have an Id in there. It's just the wrong type. I've tried using:

Id candidate = String.valueOf(contactLookup);

And passing this through, but nothing happens again.

Kind of stuck on this one!

Thanks!

Edit: When using:

pro.Candidate__c = contactLookup.Id;

I'm getting the following in the debug logs:

System.NullPointerException: Attempt to de-reference a null object

Source Link
Dan Jones
  • 7.3k
  • 4
  • 41
  • 63
Loading