function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Roshan 10Roshan 10 

Why is apex wire service that calls an apex method returning data with data and error tags

Please find the sample code below. Thank you for helping me on this

ex:The console.log for data from getCaseRTByDeveloperName:{data: "{"Support":"Id1","Suggestion","Id2"}", error: undefined}.
I am trying to extract the keys returned by Apex (Support, Suggestion)            


--- Apex

public with sharing class CreateCaseHelper {

@AuraEnabled(cacheable=true)    
public static String getCaseRecordTypeDeveloperNameMap(){

    Map<String, Id> psdCaseRTDeveloperNameMap = new Map<String, Id>();

    for(RecordType rt : [Select Id, developername from RecordType 
    where SobjectType = 'Case']){

        psdCaseRTDeveloperNameMap.put(rt.developername, rt.Id);

    }

    return JSON.serialize(psdCaseRTDeveloperNameMap);


}

}

--- LWC HTML

<template>

    Suggestion Case Record TypeId:
    
</template>

---- LWC JS

import { LightningElement, api, track, wire } from "lwc";
import {
  getObjectInfo,
  getPicklistValues,
  getPicklistValuesByRecordType
} from "lightning/uiObjectInfoApi";

import CASE_OBJECT from "@salesforce/schema/Case";

import getCaseRTByDeveloperName from '@salesforce/apex/CreateCaseHelper.getCaseRecordTypeDeveloperNameMap';

export default class CaseTestLWC extends LightningElement {

    @track suggestionCaseRecId = "";


    @wire(getPicklistValuesByRecordType, {
        objectApiName: CASE_OBJECT,
        recordTypeId: "$suggestionCaseRecId"
      }) wiredRecordTypeSuggInfo({ data, error }) {
          if(data){
              console.log("data from getPicklistValuesByRecordType: " , data);
          }
      }
    
    
    @wire(getCaseRTByDeveloperName)
    caseRTByDeveloperName(data, error){
    if(data){
      console.log("data from getCaseRTByDeveloperName:", data);
      
      let p = data;
      for(let i in Object.entries(p)){
        
        var key = Object.entries(p)[i][0];
        var value = Object.entries(p)[i][1];
        console.log('key['+i+']='+key+' '+'value['+i+']='+value);
      }

    }else if(error){
      console.log("Error Occured while geting case record types ---> " + error);
    }
    
    }


}

---- LWC Meta

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>48.0</apiVersion>
    <isExposed>true</isExposed>
    <masterLabel>Create Case Test LWC</masterLabel>
    <targets>
        <target>lightning__RecordPage</target>
        <target>lightning__AppPage</target>
        <target>lightning__HomePage</target>
        <target>lightningCommunity__Page</target>
        <target>lightningCommunity__Default</target>
    </targets>
</LightningComponentBundle>