14

sorry for almost duplicate - but I have not enough reputation yet to comment on: Lightning/Aura components: aura attribute default sobjectType gives error in managedpackage

I am having the same issue with Standard Objects:

<aura:component >
<aura:attribute name="acc" type="Account" default="{'sObjectType':'Account', 'Name':'Account123'}"/>
</aura:component>

Trying to save, I get

"Failed to save undefined: Unable to read SObject: Source"

To my understanding of the documentation, I do not need any namespace for Standard Objects. I tried all combinations nonetheless to no avail.

Tried several standard Objects as well. All produce the same error with exception of sObjectType Event. The following can be saved but does not work:

<aura:component >
<aura:attribute 
name="demo" 
type="Event" 
default="{'sObjectType':'Event', 
'Subject':'Account123', 
'WhoId':'00300000121aAAB'}"/>
{!v.demo.WhoId}
</aura:component>
  • To run lightning, your org needs its own namespace. A managed package will also have a namespace associated with it as well. That means there are two different namespaces involved, one for the managed package and one for your own org (the latter is relative to your org). Ultimately, everything has to first point to your org's namespace, then for a component from a managed package, it will resolve to the namespace for the package that's located within your org. Does that help clarify things for you? – crmprogdev Dec 26 '15 at 14:55
  • Thanks - only in theory, as I still do not understand what the syntax needs to look like. :) My packages namespace is 'szDev', standard namespace c: , right? the docs link do not mention standard objects and namespacing. I am sorry, I just cannot see it. – Christian Szandor Knapp Dec 26 '15 at 15:25
  • All objects need to be namespaced whether managed or not if using lighting. If a custom object needs namespaced, it only makes sense that standard object would need it too. It wasn't until W16 that namespacing became a requirement for using lightning. The documentation may not be fully up to date. The Lightning platform itself is still in flux and not fully defined IMO. – crmprogdev Dec 26 '15 at 15:32
  • <aura:attribute name="contact" type="contact" default="{'sObjectType':'Contact'}"/> the type will be saved as szDev.contact - which makes sense. <aura:attribute name="contact" type="szDev.Contact" /> is accepted <aura:attribute name="contact" type="c.Contact" /> is (c is standard namespace, right?) accepted (and translated to szDev.Contact) But anything.Contact is accepted as type. Whereas anything.C2ontact throws an error: unknown type It is is still the question how to write {'sObjectType':'Contact'} I tried c.Contact, c__Contact, szDev__Contact, szDev.Contact... – Christian Szandor Knapp Dec 26 '15 at 16:05
  • I may be mistaken as it's been a while for me since I've done any Lightning components, but I think there's now the force.hasSObjectName and force:hasSObjectId that you might find helpful. They're new as of W16. – crmprogdev Dec 26 '15 at 16:12
11

You need to use sobjectType as the attribute of default object. Not sObjectType and not SObjectType. i.e.

<aura:attribute name="acc" type="Account" default="{'sobjectType':'Account', 'Name':'Account123'}"/>

Starting from Spring 15 Lightning Compomnents markup is case sensitive (Release Notes) therefore you get an error when referencing incorrect attribute.

  • Oh, how very obvious! A quick search revealed: lots of dated sources, but the official documentation is as you say. Thx – Christian Szandor Knapp Mar 31 '16 at 19:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.