• Vinay Ramu
  • NEWBIE
  • 0 Points
  • Member since 2018
  • Senior Consultant
  • Equinix


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 7
    Replies
I'm trying to use Lightning Data Service feature to create new Case record by relating it to that particular contact & it's account from Contact Record Detail Page. Added "Create Related Case" button on the Contact Record Detail Page and related with lightning component mentioned below.

Error in UI:
Error
An error was encountered trying to save this case. Please review and correct any errors before submitting.

Error in Console:
Problem saving case, response state: [{"fieldErrors":{},"pageErrors":[]}]

CreateCaseWithLDS.cmp
<aura:component implements="force:lightningQuickAction,flexipage:availableForRecordHome,force:hasRecordId" access="global">
    <aura:attribute name="newCase" type="Case" default="{ 'sobjectType': 'Case' }" />
    <aura:attribute name="contact" type="Contact" />
    <aura:attribute name="recordId" type="Id" />
    <aura:attribute name="hasErrors" type="Boolean" />
    <aura:attribute name="message" type="String" />
    <aura:attribute name="contactError" type="String" />
    <force:recordData aura:id="contactRecordLoader"
                         recordId="{!v.recordId}"
                         fields="Name,AccountId"
                         targetRecord="{!v.contact}"
                         targetError="{!v.contactError}" />
    <aura:attribute name="caseError" type="String" />
    <force:recordData aura:id="caseRecordCreator"
                         layoutType="FULL"
                         targetRecord="{!v.newCase}"
                         targetError="{!v.caseError}" />
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <div class="slds-page-header" role="banner">
        <p class="slds-text-heading--label">{!v.contact.Name}</p>
        <h1 class="slds-page-header__title slds-m-right--small
            slds-truncate slds-align-left">Create New Case</h1>
    </div>
    
    <aura:if isTrue="{!v.hasErrors}">
        <div class="recordSaveError">
            <ui:message title="Error" severity="error" closable="true">
                An error was encountered trying to save this case.
                Please review and correct any errors before submitting.
            </ui:message>
        </div>
    </aura:if>
    
    <aura:if isTrue="{!not(empty(v.message))}">
        <div class="recordSaveSuccess">
            <ui:message >
                {!v.message}
            </ui:message>
        </div>
    </aura:if>
    <div class="slds-form--stacked">
        <lightning:input required="true" type="input" aura:id="Subject" 
                         label="Subject:" value="{!v.newCase.Subject}" />
        
        <lightning:textArea required="true" aura:id="Descrption" maxlength="1000"
                          label="Descrption:" value="{!v.newCase.Descrption}" />
        
        <br />
        <lightning:button variant="brand" label="Save Case" onclick="{!c.saveCase}" />
    </div>
</aura:component>   

CreateCaseWithLDSController.js
({
    doInit : function(component, event, helper) {
        console.log(component.get("v.contact.Name"));
        console.log(component.get("v.contact.AccountId"));
        component.find("caseRecordCreator").getNewRecord(
            "Case",
            null,
            false,
            $A.getCallback(function() {
                var rec = component.get("v.newCase");
                var error = component.get("v.caseError");
                if(error || (rec === null)){
                    console.log("Error initializing record template: " + error);
                }
            })
        );
    },
    saveCase : function(component, event, helper){
        component.set("v.hasErrors", false);
        component.set("v.newCase.Status", 'New');
        component.set("v.newCase.ContactId", component.get("v.recordId"));
        console.log(component.get("v.recordId"));
        component.set("v.newCase.AccountId", component.get("v.contact.AccountId"));
        console.log(component.get("v.contact.AccountId"));
        component.find("caseRecordCreator").saveRecord(
            function(saveResult){
                if(saveResult.state === "SUCCESS" || saveResult.state === "DRAFT"){
                    component.set("v.message","Case was saved successfully!");
                    var resultsToast = $A.get("e.force:showToast");
                    resultsToast.setParams({
                        "title": "Saved",
                        "message": "The record was saved."
                    });
                    resultsToast.fire();
                }
                else if(saveResult.state === "ERROR"){
                    component.set("v.hasErrors", true);
                    console.log("Problem saving case, response state: " + JSON.stringify(saveResult.error));
                }
                else{
                    component.set("v.hasErrors", true);
                    console.log('Unknown problem, response state: ' + saveResult.state + ", error: "+ JSON.stringify(saveResult.error));
                }
            }
        );
    }
})

Not able to find out what's causing failure. Need help.
User-added image

Thanks,
Vinay
 
My requirement is to add in contact object record page an action to create case related to that contact & it's account. Below lightning component added as action to contact record page and following error upon saving case.
Error on user interface:
An error was encountered trying to save this case. Please review and correct any errors before submitting.
Error on console:
Problem saving case, response state: [{"fieldErrors":{},"pageErrors":[]}]
Lightning Data Service Component Code:
<aura:component implements="force:lightningQuickAction,flexipage:availableForRecordHome,force:hasRecordId" access="global">
    <aura:attribute name="newCase" type="Case" default="{ 'sobjectType': 'Case' }" />
    <aura:attribute name="contact" type="Contact" />
    <aura:attribute name="recordId" type="Id" />
    <aura:attribute name="hasErrors" type="Boolean" />
    <aura:attribute name="message" type="String" />
    <aura:attribute name="contactError" type="String" />
    <force:recordData aura:id="contactRecordLoader"
                         recordId="{!v.recordId}"
                         fields="Name,AccountId"
                         targetRecord="{!v.contact}"
                         targetError="{!v.contactError}" />
    <aura:attribute name="caseError" type="String" />
    <force:recordData aura:id="caseRecordCreator"
                         layoutType="FULL"
                         targetRecord="{!v.newCase}"
                         targetError="{!v.caseError}" />
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <div class="slds-page-header" role="banner">
        <p class="slds-text-heading--label">{!v.contact.Name}</p>
        <h1 class="slds-page-header__title slds-m-right--small
            slds-truncate slds-align-left">Create New Case</h1>
    </div>
    
    <aura:if isTrue="{!v.hasErrors}">
        <div class="recordSaveError">
            <ui:message title="Error" severity="error" closable="true">
                An error was encountered trying to save this case.
                Please review and correct any errors before submitting.
            </ui:message>
        </div>
    </aura:if>
    
    <aura:if isTrue="{!not(empty(v.message))}">
        <div class="recordSaveSuccess">
            <ui:message >
                {!v.message}
            </ui:message>
        </div>
    </aura:if>
    <div class="slds-form--stacked">
        <lightning:input required="true" type="input" aura:id="Subject" 
                         label="Subject:" value="{!v.newCase.Subject}" />
        
        <lightning:textArea required="true" aura:id="Descrption" maxlength="1000"
                          label="Descrption:" value="{!v.newCase.Descrption}" />
        
        <br />
        <lightning:button variant="brand" label="Save Case" onclick="{!c.saveCase}" />
    </div>
</aura:component>   

Lightning Data Service Controller JS File:
({
    doInit : function(component, event, helper) {
        console.log(component.get("v.contact.Name"));
        console.log(component.get("v.contact.AccountId"));
        component.find("caseRecordCreator").getNewRecord(
            "Case",
            null,
            false,
            $A.getCallback(function() {
                var rec = component.get("v.newCase");
                var error = component.get("v.caseError");
                if(error || (rec === null)){
                    console.log("Error initializing record template: " + error);
                }
            })
        );
    },
    saveCase : function(component, event, helper){
        component.set("v.hasErrors", false);
        component.set("v.newCase.Status", 'New');
        component.set("v.newCase.ContactId", component.get("v.recordId"));
        console.log(component.get("v.recordId"));
        component.set("v.newCase.AccountId", component.get("v.contact.AccountId"));
        console.log(component.get("v.contact.AccountId"));
        component.find("caseRecordCreator").saveRecord(
            function(saveResult){
                if(saveResult.state === "SUCCESS" || saveResult.state === "DRAFT"){
                    component.set("v.message","Case was saved successfully!");
                    var resultsToast = $A.get("e.force:showToast");
                    resultsToast.setParams({
                        "title": "Saved",
                        "message": "The record was saved."
                    });
                    resultsToast.fire();
                }
                else if(saveResult.state === "ERROR"){
                    component.set("v.hasErrors", true);
                    console.log("Problem saving case, response state: " + JSON.stringify(saveResult.error));
                }
                else{
                    component.set("v.hasErrors", true);
                    console.log('Unknown problem, response state: ' + saveResult.state + ", error: "+ JSON.stringify(saveResult.error));
                }
            }
        );
    }
})
User-added image
Thanks in advance.
Need help on how this requirement can be achieved. 
Requirement: In Contact object, custom picklist field "Primary Contact Type" having values 'Other','Home','Mobile' and 'Work'. Based on value selected that particular picklist field 'Other Phone', 'Home Phone', 'Mobile Phone' and 'Work Phone' will be rendered as required.

Visualforce Page Code:
<apex:page standardController="Contact" extensions="conExtn">
    <apex:form id="conForm">
        <apex:pageBlock id="conBlk" title="Contact Details">
            <apex:pageMessages />
                <apex:pageBlockButtons location="top">
                    <apex:commandButton action="{!QuickSave}" title="QuickSave" value="Quick Save"/>
                </apex:pageBlockButtons>
                <apex:pageBlockSection title="Header Details">
                    <apex:outputField value="{!Contact.LastName}"/>
                    <apex:outputField value="{!Contact.FirstName}"/>
                    <apex:outputField value="{!Contact.Department}"/>                    
                </apex:pageBlockSection>
                <apex:pageBlockSection title="Phone Details" id="phDtls">
                        <apex:inputField value="{!Contact.Primary_Contact_Type__c}" required="{!isPrimary}" id="pConType">
                            <apex:actionSupport action="{!callSectionRefresh}" event="onchange" reRender="phDtls" immediate="true">
                                <apex:param id="contactType" name="conType" value="{!Contact.Primary_Contact_Type__c}" assignTo="{!cType}"/>
                            </apex:actionSupport>
                        </apex:inputField>
                    <apex:inputField label="Other" value="{!Contact.OtherPhone}" rendered="{!Contact.Primary_Contact_Type__c='Other'}" required="{!isOther}"/>
                    <apex:inputField label="Mobile" value="{!Contact.MobilePhone}" rendered="{!Contact.Primary_Contact_Type__c='Mobile'}" required="{!isMobile}"/>
                    <apex:inputField label="Home" value="{!Contact.HomePhone}" rendered="{!Contact.Primary_Contact_Type__c='Home'}" required="{!isHome}"/>
                    <apex:inputField label="Work" value="{!Contact.Phone}" rendered="{!Contact.Primary_Contact_Type__c='Work'}" required="{!isWork}"/>
                </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller Extension:
public class conExtn {
    public Contact con;
    public String conType;
    public object cType {get; set;}
    public Boolean isOther {get; set;}
    public Boolean isHome {get; set;}
    public Boolean isMobile {get; set;}
    public Boolean isWork {get;set;}
    public Boolean isPrimary {get;set;}
    
    public conExtn(ApexPages.StandardController controller) {
        this.con = (Contact) controller.getRecord();
        System.debug('Record Id is ' + con.Id);
        if(con.Id != null)
            refreshSection(con.Primary_Contact_Type__c);
    }
    public void makeAllOptional(){
        isOther    = false;
        isHome     = false;
        isMobile   = false;
        isWork     = false;
        isPrimary  = true;
    }
    public void refreshSection(String conType){
        makeAllOptional();
        System.debug('Inside refreshSection conType value is ' + conType);
        if(con.Primary_Contact_Type__c == 'Other'){
            isOther = true;
        }
        else if(con.Primary_Contact_Type__c == 'Mobile'){
            isMobile = true;
        }
        else if(con.Primary_Contact_Type__c == 'Work'){
            isWork = true;
        }
        else if(con.Primary_Contact_Type__c == 'Home'){
            isHome = true;
        }
        else{
            isPrimary = true;
        }
    }

    public static void setconType(String conType){
        System.debug('Inside set conType ' + conType);
    }
    public void getconType(){
        this.conType = con.Primary_Contact_Type__c;
        System.debug('Inside get conType ' + conType);
    }
    public void callSectionRefresh(){
        System.debug('cType in callSectionRefresh is ' + (String) cType);
        conType = (String) cType;
        refreshSection(conType );
    }
}

Always controller is passed "Primary Contact Type" in database and not the value changed in UI as its not saved yet.

Thanks,
Vinay
Need help as I want to display one of the conditional apex:column true or false values as checkbox.

In My Code below, I want to display custom column TRUE or FALSE as checkbox.
<apex:page controller="SObjectsListController">
    <apex:form >
        <apex:pageBlock title="List Of Objects">
            <apex:pageblockTable value="{!lstObjects}" var="f">
                <apex:column value="{!f}"><apex:facet name="header">Object Names</apex:facet></apex:column>
                <apex:column value="{!IF(FIND('__c',f,1)>1,TRUE,FALSE)}"><apex:facet name="header">Custom</apex:facet></apex:column>
            </apex:pageblockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Thanks,
Vinay
Need help in displaying List<String> in VF Page. Even with below code nothing displaying except h1 html text.

VF Page Code:
<apex:page controller="SObjectsListPageController">
    <h1>List Of sObjects</h1>
    <apex:repeat value="{!sObjectsList}" var="listStr" id="theRepeat">
        <apex:outputText value="{!listStr}" id="theValue"/><br/>
    </apex:repeat>
</apex:page>

Controller:
public class SObjectsListPageController {
    public List<String> sObjectsList {get; set;}
    public List<Schema.SObjectType> sObjTypeList = new List<Schema.SObjectType>();

    public void getsObjectsList (){
        Map<String, Schema.SObjectType> objMap = Schema.getGlobalDescribe();
        sObjTypeList = objMap.values();
        String str;
        for(Schema.SObjectType scs : sObjTypeList){
            str = scs.getDescribe().getName();
            sObjectsList.add(str);
        }
    }
}

Thanks,
Vinay
Dear Gurus,

I have created a custom object Voter__c with standard field "Name" and custom Master-Detail field "Precinct__c"(relationship with custom object Precinct__c).
Requirement is to upload few Voter records for precinct and queued job failing with this error. Does not clearly point out what's wrong with the file.
My file to upload:
<?xml version="1.0" encoding="UTF-8"?>
<sObjects xmlns="http://www.force.com/2009/06/asyncapi/dataload">
<sObject>
<Name>[Bulk API] Voter 1</Name>
<Precinct__c>a0J7F00000Hw7PuUAJ</Precinct__c>
</sObject>
<sObject>
<Name>[Bulk API] Voter 2</Name>
<Precinct__c>a0J7F00000Hw7PuUAJ</Precinct__c>
</sObject>
</sObjects>

Thanks,
Vinay
Need help on how this requirement can be achieved. 
Requirement: In Contact object, custom picklist field "Primary Contact Type" having values 'Other','Home','Mobile' and 'Work'. Based on value selected that particular picklist field 'Other Phone', 'Home Phone', 'Mobile Phone' and 'Work Phone' will be rendered as required.

Visualforce Page Code:
<apex:page standardController="Contact" extensions="conExtn">
    <apex:form id="conForm">
        <apex:pageBlock id="conBlk" title="Contact Details">
            <apex:pageMessages />
                <apex:pageBlockButtons location="top">
                    <apex:commandButton action="{!QuickSave}" title="QuickSave" value="Quick Save"/>
                </apex:pageBlockButtons>
                <apex:pageBlockSection title="Header Details">
                    <apex:outputField value="{!Contact.LastName}"/>
                    <apex:outputField value="{!Contact.FirstName}"/>
                    <apex:outputField value="{!Contact.Department}"/>                    
                </apex:pageBlockSection>
                <apex:pageBlockSection title="Phone Details" id="phDtls">
                        <apex:inputField value="{!Contact.Primary_Contact_Type__c}" required="{!isPrimary}" id="pConType">
                            <apex:actionSupport action="{!callSectionRefresh}" event="onchange" reRender="phDtls" immediate="true">
                                <apex:param id="contactType" name="conType" value="{!Contact.Primary_Contact_Type__c}" assignTo="{!cType}"/>
                            </apex:actionSupport>
                        </apex:inputField>
                    <apex:inputField label="Other" value="{!Contact.OtherPhone}" rendered="{!Contact.Primary_Contact_Type__c='Other'}" required="{!isOther}"/>
                    <apex:inputField label="Mobile" value="{!Contact.MobilePhone}" rendered="{!Contact.Primary_Contact_Type__c='Mobile'}" required="{!isMobile}"/>
                    <apex:inputField label="Home" value="{!Contact.HomePhone}" rendered="{!Contact.Primary_Contact_Type__c='Home'}" required="{!isHome}"/>
                    <apex:inputField label="Work" value="{!Contact.Phone}" rendered="{!Contact.Primary_Contact_Type__c='Work'}" required="{!isWork}"/>
                </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller Extension:
public class conExtn {
    public Contact con;
    public String conType;
    public object cType {get; set;}
    public Boolean isOther {get; set;}
    public Boolean isHome {get; set;}
    public Boolean isMobile {get; set;}
    public Boolean isWork {get;set;}
    public Boolean isPrimary {get;set;}
    
    public conExtn(ApexPages.StandardController controller) {
        this.con = (Contact) controller.getRecord();
        System.debug('Record Id is ' + con.Id);
        if(con.Id != null)
            refreshSection(con.Primary_Contact_Type__c);
    }
    public void makeAllOptional(){
        isOther    = false;
        isHome     = false;
        isMobile   = false;
        isWork     = false;
        isPrimary  = true;
    }
    public void refreshSection(String conType){
        makeAllOptional();
        System.debug('Inside refreshSection conType value is ' + conType);
        if(con.Primary_Contact_Type__c == 'Other'){
            isOther = true;
        }
        else if(con.Primary_Contact_Type__c == 'Mobile'){
            isMobile = true;
        }
        else if(con.Primary_Contact_Type__c == 'Work'){
            isWork = true;
        }
        else if(con.Primary_Contact_Type__c == 'Home'){
            isHome = true;
        }
        else{
            isPrimary = true;
        }
    }

    public static void setconType(String conType){
        System.debug('Inside set conType ' + conType);
    }
    public void getconType(){
        this.conType = con.Primary_Contact_Type__c;
        System.debug('Inside get conType ' + conType);
    }
    public void callSectionRefresh(){
        System.debug('cType in callSectionRefresh is ' + (String) cType);
        conType = (String) cType;
        refreshSection(conType );
    }
}

Always controller is passed "Primary Contact Type" in database and not the value changed in UI as its not saved yet.

Thanks,
Vinay
Need help in displaying List<String> in VF Page. Even with below code nothing displaying except h1 html text.

VF Page Code:
<apex:page controller="SObjectsListPageController">
    <h1>List Of sObjects</h1>
    <apex:repeat value="{!sObjectsList}" var="listStr" id="theRepeat">
        <apex:outputText value="{!listStr}" id="theValue"/><br/>
    </apex:repeat>
</apex:page>

Controller:
public class SObjectsListPageController {
    public List<String> sObjectsList {get; set;}
    public List<Schema.SObjectType> sObjTypeList = new List<Schema.SObjectType>();

    public void getsObjectsList (){
        Map<String, Schema.SObjectType> objMap = Schema.getGlobalDescribe();
        sObjTypeList = objMap.values();
        String str;
        for(Schema.SObjectType scs : sObjTypeList){
            str = scs.getDescribe().getName();
            sObjectsList.add(str);
        }
    }
}

Thanks,
Vinay
Dear Gurus,

I have created a custom object Voter__c with standard field "Name" and custom Master-Detail field "Precinct__c"(relationship with custom object Precinct__c).
Requirement is to upload few Voter records for precinct and queued job failing with this error. Does not clearly point out what's wrong with the file.
My file to upload:
<?xml version="1.0" encoding="UTF-8"?>
<sObjects xmlns="http://www.force.com/2009/06/asyncapi/dataload">
<sObject>
<Name>[Bulk API] Voter 1</Name>
<Precinct__c>a0J7F00000Hw7PuUAJ</Precinct__c>
</sObject>
<sObject>
<Name>[Bulk API] Voter 2</Name>
<Precinct__c>a0J7F00000Hw7PuUAJ</Precinct__c>
</sObject>
</sObjects>

Thanks,
Vinay
Hi,

I am getting error as below in Lightning Experience Rollout Specialist Challenge #8

The Lightning Knowledge app doesn't have the ability to view either or both: recently-visited primary tabs or subtabs.

Could any one please suggest me?

Thanks
Surya
Did anyone have this issue with challenge 6.

Challenge Not yet complete... here's what's wrong: 
Didn't find a Lightning page named Key Sales Data. This page must include: 1. List of new Accounts this week, 2. Recent items showing an "Opportunity", "Lead" and "Contact", 3. Log A Call and New Opportunity actions. Don't use the CreateOppty custom Lightning component for this challenge.

My Key Sales Data Lightning page screenshots:
User-added image

User-added image