• Ankit Gupta 305
  • NEWBIE
  • 10 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 0
    Questions
  • 3
    Replies
My error message on this challenge is; "Challenge Not yet complete... here's what's wrong: 
Could not find at least 500 Account records with the Name like 'Bulk Company'."

My steps are;
1. Import the account records and save in csv format
2. Logged into workbench and linked to my dev org
3. In REST explorer I uploaded the job
     HTTP method POST
    URI textbox:  /services/data/v41.0/jobs/ingest  (also tried API version 42)
    Request header text;
Content-Type: application/json; charset=UTF-8
Accept: application/json
    Request body text; 
{
"operation" : "insert",
"object" : "Account",
"contentType" : "CSV",
"lineEnding" : "CRLF"
}
4. Execute
5. Note the job ID
6. Add the data to the job;
 HTTP method PUT
    URI textbox:  /services/data/v41.0/jobs/ingest/7500O00000Bo5AUQAZ/batches
    Request header text;
Content-Type: text/csv
Accept: application/json
    Request body text; 
"Name" "Sample Bulk API Account 1"
"Sample Bulk API Account 2"
"Sample Bulk API Account 3"
"Sample Bulk API Account 4"
    etc until 500
7. Execute
8. Close the job
 HTTP method PATCH
    URI textbox:  /services/data/v41.0/jobs/ingest/7500O00000Bo5AUQAZ
    Request header text;
Content-Type: application/json; charset=UTF-8
Accept: application/json
Body text;
{
"state" : "UploadComplete"
}
9. Execute

Check the challenge
 



 
The Lightning Components Developer Guide warns about using the same name for client and server controller actions:
Use unique names for client-side and server-side actions in a component. A JavaScript function (client-side action) with the same name as a server-side action (Apex method) can lead to hard-to-debug issues.
I was unlucky enough to miss this tip before I debugged one of those hard-to-debug issues. To prevent others from making the same mistake, I wanted to share my debug path in case you miss the memo about naming conventions and run into similar symptoms:

PricingTool.cmp
My component contains a button that runs a client controller action named "c.getPricing"

<pre>
<aura:component controller="ServerController">
  <aura:attribute name="products" type="ServerController.ProductPrice[]"></aura:attribute>
  <ui:button aura:id="buttonGetPricing" label="Get Pricing" press="{!c.getPricing}"></ui:button>
</aura:component>
</pre>

PricingToolController.js
The controller action calls a helper action with the same name: "hlp.getPricing"

<pre>
({
    getPricing: function(cmp,evt,hlp){
        console.log('in c.getPricing');
        hlp.getPricing(cmp,hlp);
    }
})
</pre>

PricingToolHelper.js
My helper attempts to call a server-side action "c.getPricing", which is the same name as the client-side action "c.getPricing"

<pre>
({
    getPricing : function(cmp,hlp)
    {
        console.log('in hlp.getPricing');
        var action = cmp.get('c.getPricing');
        var products = cmp.get('v.products');
        action.setParams({productList : products});
        action.setCallback(this,function(res){
            console.log('in hlp.getPricing callback');
            var state = res.getState();
            console.log('hlp.getPricing ' + state);
            if (state === "SUCCESS") {
                var pricing = JSON.parse(res.getReturnValue().body);
                console.log(pricing);
            }
        });
        $A.enqueueAction(action);
    },
})
</pre>

ServerController.cls
The server code successfully passes unit testing, but when launched from my Lightning Component helper class, no "/aura" logs are created on the server, indicating the server code is never touched.

<pre>
public class ServerController{

    @AuraEnabled
    public static Response getPricing(List<ProductPrice> productList) {...}
}
</pre>

Back To The Client...
So the server action is never run, and my javascript console is growing a fearsome loop of the following log lines:
 
in c.getPricing             # client controller action triggered
in hlp.getPricing           # helper action triggered
in hlp.getPricing callback  # callout to "c.getPricing" triggered
hlp.getPricing SUCCESS      # callout successfully returned
undefined                   # the results of res.getReturnValue() are empty
in c.getPricing
in hlp.getPricing
in hlp.getPricing callback
hlp.getPricing SUCCESS
undefined

The Moral of this Story
When the helper attempts to "get" a server action from the component, it receives the client action instead, because they use the same name. This causes an endless loop on the client, where the controller executes itself again and again via the helper's action call. The callback won't throw any errors and happly continues with a "SUCCESS" state.

The fix to this all, of course, is quite simple.

ServerController.cls
First change the name of the server controller action:

<pre>
// public static Response getPricing(...) {...}
public static Response getServerPricing(...){...}
</pre>

PricingToolHelper.js
Then update the helper reference to the server controller:

<pre>
// var action = cmp.get('c.getPricing');
var action = cmp.get('c.getServerPricing');
</pre>

Happy Lightning Development!
  • March 27, 2016
  • Like
  • 1
Hi,
I am working on creating a custom web page that is basically a poor mans Mail Merge.  Basically we have a custom object that has all of the information I need in it, but I can use the normal mail merge to get everything we need in the print out.  So instead my thought is to just make a web page and some javascript and then just print that out instead.
 
The issue I am running into is the custom lookups we have.
In my example, I have the account linked to the my new Custom object (CustomObject), but additionally I have 2 different contacts linked to the object that may or may not be linked to the main account.  Contact one is say a Bill To contact and Contact 2 is the Ship To contact.  The web page that I want to create needs to go and get details on the 2 different contacts.
The code:
{!CustomObject__c.Bill_to_Contact__c} gets me the name of contact 1
{!CustomObject__c.Ship_to_Contact__c} gets me the name of contact 2
The issue is that my JavaScript needs the IDs of these 2 contacts so I can query the records.  I have no idea how to go and get these from my custom object.  Bill_to_Contact__c and Ship_to_Contact__c are lookup fields.
 
I'm attempting to write this in JavaScript as I have not done much investigating into VisualForce yet. If anyone can lend me any help on this I would be greatly appreaciative.
 
Thanks
  • February 28, 2008
  • Like
  • 0
The Lightning Components Developer Guide warns about using the same name for client and server controller actions:
Use unique names for client-side and server-side actions in a component. A JavaScript function (client-side action) with the same name as a server-side action (Apex method) can lead to hard-to-debug issues.
I was unlucky enough to miss this tip before I debugged one of those hard-to-debug issues. To prevent others from making the same mistake, I wanted to share my debug path in case you miss the memo about naming conventions and run into similar symptoms:

PricingTool.cmp
My component contains a button that runs a client controller action named "c.getPricing"

<pre>
<aura:component controller="ServerController">
  <aura:attribute name="products" type="ServerController.ProductPrice[]"></aura:attribute>
  <ui:button aura:id="buttonGetPricing" label="Get Pricing" press="{!c.getPricing}"></ui:button>
</aura:component>
</pre>

PricingToolController.js
The controller action calls a helper action with the same name: "hlp.getPricing"

<pre>
({
    getPricing: function(cmp,evt,hlp){
        console.log('in c.getPricing');
        hlp.getPricing(cmp,hlp);
    }
})
</pre>

PricingToolHelper.js
My helper attempts to call a server-side action "c.getPricing", which is the same name as the client-side action "c.getPricing"

<pre>
({
    getPricing : function(cmp,hlp)
    {
        console.log('in hlp.getPricing');
        var action = cmp.get('c.getPricing');
        var products = cmp.get('v.products');
        action.setParams({productList : products});
        action.setCallback(this,function(res){
            console.log('in hlp.getPricing callback');
            var state = res.getState();
            console.log('hlp.getPricing ' + state);
            if (state === "SUCCESS") {
                var pricing = JSON.parse(res.getReturnValue().body);
                console.log(pricing);
            }
        });
        $A.enqueueAction(action);
    },
})
</pre>

ServerController.cls
The server code successfully passes unit testing, but when launched from my Lightning Component helper class, no "/aura" logs are created on the server, indicating the server code is never touched.

<pre>
public class ServerController{

    @AuraEnabled
    public static Response getPricing(List<ProductPrice> productList) {...}
}
</pre>

Back To The Client...
So the server action is never run, and my javascript console is growing a fearsome loop of the following log lines:
 
in c.getPricing             # client controller action triggered
in hlp.getPricing           # helper action triggered
in hlp.getPricing callback  # callout to "c.getPricing" triggered
hlp.getPricing SUCCESS      # callout successfully returned
undefined                   # the results of res.getReturnValue() are empty
in c.getPricing
in hlp.getPricing
in hlp.getPricing callback
hlp.getPricing SUCCESS
undefined

The Moral of this Story
When the helper attempts to "get" a server action from the component, it receives the client action instead, because they use the same name. This causes an endless loop on the client, where the controller executes itself again and again via the helper's action call. The callback won't throw any errors and happly continues with a "SUCCESS" state.

The fix to this all, of course, is quite simple.

ServerController.cls
First change the name of the server controller action:

<pre>
// public static Response getPricing(...) {...}
public static Response getServerPricing(...){...}
</pre>

PricingToolHelper.js
Then update the helper reference to the server controller:

<pre>
// var action = cmp.get('c.getPricing');
var action = cmp.get('c.getServerPricing');
</pre>

Happy Lightning Development!
  • March 27, 2016
  • Like
  • 1