My problem is as follows:
I've got a Site VF page with fields bound to a custom Lead object. One of these fields is a id field that's used for contact lookup. The controller seems to work fine but all records created with it are empty, since the lookup in the controller code returns 0 rows.
This is the controller:
public with sharing class VF_TabletWaitingList {
private final CustomLead__c sales;
private Contact c;
public VF_TabletWaitingList(ApexPages.StandardController stdcontroller) {
this.sales= (CustomLead__c)stdController.getRecord();
}
public PageReference createNew()
{
//CustomLead__c solumal = new CustomLead__c();
//Set the record type on CustomLead
RecordType r = [select Id
from RecordType
where Name = 'Verslun'
AND SobjectType = 'CustomLead__c' limit 1];
solumal.RecordTypeId = r.Id;
try{
Contact c = [select id, tx_Id__c
from contact
where tx_Id__c =: sales.tx_Id__c limit 1];
system.debug('Id: '+c.tx_Id__c);
sales.Contact__c = c.Id;
}
catch (Exception e){
}
try{
insert sales;
system.debug('Inserted'+sales.Id);
}
The debug log for the Site user shows this:
09:54:31.059 (59258000)|SOQL_EXECUTE_BEGIN|[25]|Aggregations:0|select id, tx_Id__c from contact where tx_Id__c = :tmpVar1 limit 1
09:54:31.076 (76765000)|SOQL_EXECUTE_END|[25]|Rows:0
I thought it would be enough to refer to the sales object like I do in the standard controller. Any ideas where I'm going wrong?