Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Salesforce 自定义Lightning组件的页面URL无效_Salesforce_Salesforce Lightning - Fatal编程技术网

Salesforce 自定义Lightning组件的页面URL无效

Salesforce 自定义Lightning组件的页面URL无效,salesforce,salesforce-lightning,Salesforce,Salesforce Lightning,我创建了一个新的自定义lightning组件和控制器,以在Salesforce中创建一个新的lead。正确输入所有字段并通过验证后,页面将按设计工作。但是,如果某个字段未通过验证,例如电子邮件格式不正确(abc.abc.com),则我会收到以下错误 页面不存在请输入有效的URL,然后重试 我还收到Salesforce的成功祝酒词,但没有创建潜在客户。我相信我在getState响应中的控制器有问题,但无法找出我的错误 这是组件 组成部分 <aura:component implements=

我创建了一个新的自定义lightning组件和控制器,以在Salesforce中创建一个新的lead。正确输入所有字段并通过验证后,页面将按设计工作。但是,如果某个字段未通过验证,例如电子邮件格式不正确(abc.abc.com),则我会收到以下错误

页面不存在请输入有效的URL,然后重试

我还收到Salesforce的成功祝酒词,但没有创建潜在客户。我相信我在getState响应中的控制器有问题,但无法找出我的错误

这是组件

组成部分

<aura:component implements="lightning:actionOverride" access="global" controller="overrideStandabuttonwithLC">
    <aura:attribute name="lea" type="Lead" default="{'sobjectType': 'Lead',
                                                        'FirstName':'',
                                                        'LastName':'',
                                                        'Title':'',
                                                        'Email':'',
                                                        'Phone':''}" />    
    <div class="slds-m-around--large">
        <div class="slds-form--stacked">
            <div class="slds-form-element">  
                <div class="slds-form-element__control">
                    <lightning:input aura:id="leaFirstName" label="First Name" value="{!v.lea.FirstName}" class="slds-input"/>
                    <lightning:input aura:id="leaLastName" required="true" label="Last Name" value="{!v.lea.LastName}" class="slds-input"/>
                    <lightning:input aura:id="leaTitle" label="Title" value="{!v.lea.Title}" class="slds-input"/>
                    <lightning:input aura:id="leaEmail" label="Email" value="{!v.lea.Email}" placeholder="abc@email.com..." class="slds-input"/>
                    <lightning:input aura:id="leaPhone" label="Phone" value="{!v.lea.Phone}" class="slds-input"/>
                  </div>
            </div>
            <div class="slds-m-around--medium">
                <button class="slds-button slds-button--brand" onclick="{!c.createLead}">Save</button>
            </div>
        </div>
    </div>    
</aura:component>
顶点


发生这种情况的原因是有道理的。您的控制器方法
saveLead
失败。永远不会插入潜在客户记录。您正在将
null
返回到组件。无法导航到空记录

您需要更好地处理错误。如果
leadId
未定义/为空,则应向用户显示错误。如果
leadId
有一个值,则可以安全地导航到该记录

或者,您可以从服务器方法中删除try/catch,并使回调如下所示

action.setCallback(this, function(response){
    var toastEvent = $A.get("e.force:showToast");
    if(response.getState()==='SUCCESS'){
        var leaId = response.getReturnValue();

        toastEvent.setParams({
            "title": "Success!",
            "type":"Success",
            "message": "Lead created successfully."
        });

        toastEvent.fire();


        var navEvt = $A.get("e.force:navigateToSObject");
        navEvt.setParams({
            "recordId": leaId,
            "slideDevName": "related"
        });
        navEvt.fire();
    } else {
        let errors = response.getError();
        let message = 'Unknown error'; // Default error message
        // Retrieve the error message sent by the server
        if (errors && Array.isArray(errors) && errors.length > 0) {
            message = errors[0].message;
        }
        toastEvent.setParams({
            "title": "Error!",
            "type":"Error",
            "message": message
        });

        toastEvent.fire();
    }
});

挑剔,但你应该有更好的命名约定。将
d
添加到
leadRec
中,是
leadRec
更难,还是完成
leadRecord
的整个描述更难?
public with sharing class overrideStandabuttonwithLC {

    @AuraEnabled
    public static ID saveLead(Lead leaRec){
        try{
            insert leaRec;
        }
        catch(Exception e){
            system.debug('e-->' + e.getMessage());
        }

        return leaRec.Id;
    }  

}
action.setCallback(this, function(response){
    var toastEvent = $A.get("e.force:showToast");
    if(response.getState()==='SUCCESS'){
        var leaId = response.getReturnValue();

        toastEvent.setParams({
            "title": "Success!",
            "type":"Success",
            "message": "Lead created successfully."
        });

        toastEvent.fire();


        var navEvt = $A.get("e.force:navigateToSObject");
        navEvt.setParams({
            "recordId": leaId,
            "slideDevName": "related"
        });
        navEvt.fire();
    } else {
        let errors = response.getError();
        let message = 'Unknown error'; // Default error message
        // Retrieve the error message sent by the server
        if (errors && Array.isArray(errors) && errors.length > 0) {
            message = errors[0].message;
        }
        toastEvent.setParams({
            "title": "Error!",
            "type":"Error",
            "message": message
        });

        toastEvent.fire();
    }
});