2

I am passing Sobject using aura attribute.. But I am getting error as:

Invalid Aura API : Source

Here is the code:

orderadd : function(component, event, helper) {
    var action = component.get("c.addOrder");
    var obj = component.get("v.New_Order");
    component.set(obj.Name,component.get("v.Name"));
    component.set(obj.Quantity__c,component.get("v.Quantity"));
    component.set(obj.Address__c,component.get("v.Address"));
    component.set(obj.Type__c,component.get("v.Type"));
    alert(ord);
    action.setParams({
        "orderadd" : $A.util.json.encode(obj)
    });
    action.setCallback(this,function(response){
        var state = response.getState();
        if (component.isValid() && state ==="SUCCESS"){
            resp = response.getReturnValue();
            alert(resp);
        }
    });
    $A.enqueueAction(action);

}

Component Code:

<aura:attribute name="New_Order" type="Order__c" default="{'sobjectType' : 'Order__c', 'Name; : '', 'Quantity__c' : '0.0' , 'Address__c' : '', 'Type__c' : 'Cow', 'Date__c', ''}"/>
  • 1
    I don't see a json.encode method in Aura util library exposed to public – codeyinthecloud Nov 20 '18 at 15:27
1

Validate Aura API (aura-api) This rule verifies that use of the framework APIs is according to the published documentation. The use of undocumented or private features is disallowed.

When Locker Service is enabled, the framework prevents the use of unsupported API objects or calls. That means your Lightning components code is allowed to use:

  • Features built into JavaScript (“intrinsic” features)
  • Published, supported features built into the Lightning Component framework
  • Published, supported features built into Locker Service SecureObject objects

This rule deals with the supported, public framework APIs, for example, those available through the framework global $A.

Why is this rule called “Aura API”? Because the core of the the Lightning Component framework is the open source Aura Framework. And this rule verifies permitted uses of that framework, rather than anything specific to Lightning Components.

The following patterns are considered problematic:

Aura.something(); // Use $A instead
$A.util.fake(); // fake is not available in $A.util

Below are the public exposed methods as of today from the util library:

  1. addClass
  2. getBooleanValue
  3. hasClass
  4. isArray
  5. isEmpty
  6. isObject
  7. isUndefined
  8. isUndefinedOrNull
  9. removeClass
  10. toggleClass

As far as the Locker service is concerned it would not allow you to use any unsupported or unexposed methods from the util library! ($A.util.json.encode(obj)).For details of all of the methods available in the framework, including $A, see the JavaScript API at https://myDomain.lightning.force.com/auradocs/reference.app, where myDomain is the name of your custom Salesforce domain.

If all you're trying to do is send an sobject value to the server side you can just pass it as a parameter to the auraenabled method. Below is an example of how you pass an account to the server side! Read about Standard and Custom Object Types

Markup:

<aura:attribute name="acct" type="Account" />

Controller.js:

var action = component.get("c.getAcc");
    var acct= component.get("v.acct");
    action.setParams({
        "acc" : acct
    });
    action.setCallback(this,function(response){
        var state = response.getState();
        if (component.isValid() && state ==="SUCCESS"){
            resp = response.getReturnValue();
            alert(resp);
        }
    });
    $A.enqueueAction(action);

Apex method:

@AuraEnabled
public static getAcc(Account acc){

}
|improve this answer|||||

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.