Lookup field in salesforce is null when saving

爷,独闯天下 提交于 2020-01-06 12:36:23

问题


I have a problem with a standard lookup field. When I try to save it, it has value null when I use autocomplete or just type the name but it works when I use the lookup popup by clicking the lookup-icon.

This is (part of) the code. (Not all of it, but even this simple controller and page doesn't work...) Controller:

public with sharing class UnresolvedItemsController {

public list<TaskItem> myUnresolvedTaskItems {get;set;}

public class TaskItem {
    public string taskId {get;set;}
    public string subject {get;set;}
    public datetime createdDate {get;set;}
    public DummyObject__c dumObj {get;set;}
}


public UnresolvedItemsController(ApexPages.Standardcontroller controller) {
    if (myUnresolvedTaskItems==null) {
        myUnresolvedTaskItems = new list<TaskItem>();
        list<Task> myUnresolvedTasks = [select id,subject,createdDate,Description from Task Where Status='Not Started' and isDeleted=false and isClosed=false and isArchived=false and OwnerId=:UserInfo.getUserId() and subject like 'Unresolved Email:%' limit 10];
        TaskItem tmp = new TaskItem();
        for (task myT:myUnresolvedTasks) {
            myUnresolvedTaskItems.add(getInfoFromTask(myT));
        }
    }   
}

public TaskItem getInfoFromTask(Task myTask) {
    TaskItem returnTaskItem = new TaskItem();
    returnTaskItem.subject = myTask.Subject.replace('Unresolved Email: ','');
    returnTaskItem.createdDate = myTask.createdDate;
    returnTaskItem.taskId = myTask.Id;
    returnTaskItem.dumObj = new DummyObject__c();
    return returnTaskItem;
}

public pagereference save() {
    system.debug('1-----'+myUnresolvedTaskItems);
    return null;
}
}

View:

<apex:page standardcontroller="Task" extensions="UnresolvedItemsController">
<apex:form >
    <apex:pageblock >
        <apex:pageblockbuttons >
            <apex:commandbutton action="{!Save}" value="{!$Label.Save}" />
            <apex:commandbutton action="{!Cancel}" value="{!$Label.Cancel}" />
        </apex:pageblockbuttons>

        <apex:pageblocktable value="{!myUnresolvedTaskItems}" var="ti">
            <apex:column >
                <apex:facet name="header">Subject</apex:facet>
                <a href="/{!ti.taskId}">{!ti.subject}</a>
            </apex:column>
            <apex:column >
                <apex:facet name="header">Date</apex:facet>
                {!ti.createdDate}
            </apex:column>
            <apex:column >
                <apex:facet name="header">Assign to salesforce.com objects</apex:facet>
                <apex:inputfield value="{!ti.dumObj.Contact__c}" />
            </apex:column>

        </apex:pageblocktable>
    </apex:pageblock>
</apex:form>
</apex:page>

The dummyObject is an Object that has a couple of lookup fields. (Contact_c to Contact, Account_c to Account, etc...)

I am not actually saving it. But it should not be null when you system.debug it...


回答1:


I finally found out what the problem is. It is a known issue that I consider to be a very serious bug. When using an inputfield for a contact, it goes wrong when you have a space in either the firstname field or the lastname field.

Knowledge Article Number: 000123565



来源:https://stackoverflow.com/questions/14957930/lookup-field-in-salesforce-is-null-when-saving

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!