• Punit@force
  • 65 Points
  • Member since 2018

  • Chatter
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
  • 5
I am testing my POST REST API service in apex. 
​​​​ RestRequest request = new RestRequest();
 request.requestURI = MY_API_ENDPOINT;
 request.httpMethod = 'POST';
 request.addHeader('Content-Type', 'application/json');
 String jsonBody = '<some_json_here>';
 request.requestBody = Blob.valueOf(jsonBody);

 RestContext.request = request;

 * assertions here
The json string I will be using is lengthy. I can simply form a string inline in the code by use '+' operator repetatively. But what is the best way of doing this?
Can somone who has taken this certification recently confirm whether Lightning Web Component questions are also being asked. Secondly is it still a lot of Visualforce or Aura lightning questions in the test currently.
Does MavensMate for Sublime Text support checking for conflicts before saving on the server for Lightning components. For me, It does the conflict check for Apex classes but not for Lightning components and client side controllers/helpers. Is it a Mavensmate limitation or it's Tooling API limitation.
I'm getting the following error on Advanced Apex Specialist Superbadge - Step 5.  Any ideas please?
User-added image

Here is the current code segments:

Public static void VerifyQuantityOrdered(Product2 originalProduct, Product2 updatedProduct, Integer qtyOrdered) {
       	decimal tot = (originalProduct.Quantity_Ordered__c + qtyOrdered);
            system.debug('OldVQ ' + originalProduct.Quantity_Ordered__c);
            system.debug('NewVQ ' + updatedProduct.Quantity_Ordered__c);
            system.debug('QTYVQ ' + qtyOrdered);
private with sharing class OrderTests {

    private static void SetupTestData (){    

    private static void OrderUpdate_UnitTest (){
        List<Order> OrderList = [select id, name, status from order];

        For (Order ordrec : OrderList) {
            OrderItem oirec = [select id, Pricebookentry.product2Id from orderitem where orderid=:ordrec.id];
			Product2 oldprodrec = [SELECT Family,Id,Name,Quantity_Ordered__c,Quantity_Remaining__c 
                            	FROM Product2 where id =: oirec.Pricebookentry.product2Id  limit 1];
            ordrec.status = constants.ACTIVATED_ORDER_STATUS;
            update ordrec;
            OrderItem oirec1 = [select id, Pricebookentry.product2Id from orderitem where orderid=:ordrec.id];
			Product2 newprodrec = [SELECT Family,Id,Name,Quantity_Ordered__c,Quantity_Remaining__c 
                            	FROM Product2 where id =: oirec1.Pricebookentry.product2Id  limit 1]; 
            system.debug('Old ' + oldprodrec.Quantity_Ordered__c);
            system.debug('New ' + newprodrec.Quantity_Ordered__c);
            system.debug('QTY ' + constants.DEFAULT_ROWS);
@isTest  (seeAllData=false)
private with sharing class Product2Tests {

     * @name product2Extension_UnitTest
     * @description UnitTest for product2Extension
    private static void Product2Extension_UnitTest(){
// Set-up user
        String uniqueUserName = 'standarduser' + DateTime.now().getTime() + '@testorg.com';
        Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
        User u = new User(Alias = 'standt', Email='standarduser@testorg.com',
        	EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
        	LocaleSidKey='en_US', ProfileId = p.Id, TimeZoneSidKey='America/Los_Angeles', UserName=uniqueUserName);

        System.runAs(u) {
// When a user first visits the page, there should be multiple rows displayed on the screen. 
// Assert that the size of the productsToInsert list is equal to the DEFAULT_ROWS constant.
//		Test.StartTest(); 
        	Product2 prod = new Product2(name='Test',isActive=true);
        	ApexPages.StandardController stdc = new ApexPages.StandardController(prod);
        	Product2Extension p2x = new Product2Extension(stdc);        
       		System.assertEquals(Constants.DEFAULT_ROWS, p2x.productsToInsert.size());
//		Test.StopTest();  

// When the Add button is clicked, an additional set of rows should be added, 
// so assert that the size of the productsToInsert ** list is double **DEFAULT_ROWS after the button is clicked once. 
//        Test.StartTest();
        	System.assertEquals(Constants.DEFAULT_ROWS * 2, p2x.productsToInsert.size());
//		Test.StopTest();          

// Next, test the Save button. Verify that populated rows are saved and unpopulated rows are not saved. 
// Loop through the rows in the productsToInsert list and populate the values of the first 5 records, 
// and then simulate clicking the Save button. Verify that the button worked by asserting that only 5 products were saved.
		integer x = 0; 
        for (Product2Extension.ProductWrapper PTI : p2x.productsToInsert){
            pti.productrecord.name='TESTPRODUCT ' + x;
            pti.productRecord.IsActive = true;
            pti.productRecord.Initial_Inventory__c = 20;
            pti.productRecord.Family = Constants.PRODUCT_FAMILY[0].getValue();           
            pti.pricebookEntryRecord.UnitPrice = 10;
        	x++; if (x==5) {break;}

//        Test.startTest();
//        Test.stopTest();
        List<Product2> createdProducts = [SELECT Id FROM Product2];
        System.assertEquals(5, createdProducts.size());

// plus some more test areas        


I am testing my POST REST API service in apex. 
​​​​ RestRequest request = new RestRequest();
 request.requestURI = MY_API_ENDPOINT;
 request.httpMethod = 'POST';
 request.addHeader('Content-Type', 'application/json');
 String jsonBody = '<some_json_here>';
 request.requestBody = Blob.valueOf(jsonBody);

 RestContext.request = request;

 * assertions here
The json string I will be using is lengthy. I can simply form a string inline in the code by use '+' operator repetatively. But what is the best way of doing this?
Hello All,

I'm currently developing a component to use in a quick action in a record page of a Custom object I created.
My component will use Lightning data service to create records of two different custom objects.
I will call one object Main__c, and the other one Smaller__c, Smaller__c is a child of Main__c and has a lookup relationship to it.
My component is composed by one Main component, which houses other Smaller components.
Inside my Main component, I use iteration to create a list of another Smaller components, in which each one have input fields to user input and a file upload element.
Also in my Main component, I have a save button which will execute LDS(Lightning Data services) saveRecord in both Main and Smaller Components.
Whenver the user fills up the entire Smaller components list fields, he clicks the Save button. This executes saveRecord in my force:recordData located in my Main component, creating a Main__c object.
Using saveResult.state, I check what the result was, if it is 'SUCCESS' or 'DRAFT', I fire an event which will be handled by each Smaller components. This event carries the recently created Main__c ID using lightning event attributes and saveResult.recordId to get the Main__c ID.
Each Smaller component has a handler to the event generated by Main component, whenever it gets fired it will execute its force:recordData.saveRecord in order to its corresponding Smaller__c object , with the user typed in info, and uses the event parameter to get the Main__c Id to populate the Smaller__c lookup relationship fild to Main__c. Note: the Main component contains several Smaller components, and the event will be listened by each one of the Smaller component, therefore creating one Smaller__c for each.

This works perfectly when I'm testing in desktop, the problem is I need this to work in mobile app.

When I try it at mobile app, my Main__c creation saveResult always return with 'DRAFT', and its saveResult.RecordId is something weird as "a05___qkEjrVUV9AIO", yes it has 3 underscores in it '___'.
So, when the event is fired, Smaller__c creation fails because the parent Main__c wasn't succesfully created, because it is in 'DRAFT', and I'm sure he can't find "a05___qkEjrVUV9AIO" as a valid Id.

Of course, I can just not fire the event when the saveResult is 'DRAFT', but if I do so, then my Main__c object with 'DRAFT' state will eventually be created outside my lightning component runtime, but my child Smaller__c objects will never be created.

A possible solution that came to me, would be an apex trigger after Main__c is insert object that would fire the events in Smaller components. But I'm not sure it's possible to fire lighting events inside Apex Triggers.

My component works perfectly in desktop, how can I address this issue for mobile, when my parent object is in 'DRAFT' state?

Cross-posting here from the Trailhead forum, where I'm working on the Lightning Components Framework SuperBadge. We're implementing LDS on a page, but NOT using force:hasRecordId. Instead, we're dynamically setting an aura:attribute, and then referencing it in the LDS parameter for recordId. I've been researching this for hours, but all the reference docs and Trailhead modules assume the case where you're using the implicit recordId on the page. No examples I can find where they're setting the recordId and then forcing the reload.

In this case, the id attribute is successfully being set, but LDS isn't loading the record. The error message says: The onBoatSelected handler in the BoatDetails controller must force Lightning Data Service to load the specified record, using logic in the controller.

In the controller, I'm using a reloadRecord command: component.find("service").reloadRecord() where "service" is the aura:id for the force:recordData element.

Is there some other command required to get the LDS to load the record?

Here's the component markup with the force:recordData info:
<aura:attribute name="id" type="String"/>
    <aura:attribute name="boat" type="Boat__c"/>
    <aura:attribute name="boatSimple" type="Boat__c"/>
    <aura:attribute name="recordError" type="String"/>

    <aura:handler event="c:BoatSelected" action="{!c.onBoatSelected}"/>

    <force:recordData aura:id="service"
                      fields=  "Id,
                                Price__c, Length__c,
                      recordUpdated="{!c.onRecordUpdated}" />
Am I screwing up something in the markup? 

I have followed a progression.

1.  I built Lightning components on the developer console, and the documentation shows.

     In order to keep snapshots of my work as I went, I copied and pasted to emails that I sent to myself. 

2.  I attended Midwest Dreaming, and discovered that my compatriots worked in Sublime and Eclipse, and connected to Salesforce. 

     That would allow me to use git, as I'm used to.  

3.  I tried Sublime 3 with MavensMate.  I got a complaint that TLS 1.0 wasn't supported, only TLS 1.1. 

4.  I looked into using Eclipse with the Force.com IDE.  It's not clear that environment supports building Lightning components conveniently.

5.  I discovered that if you go to salesforce...devcenter/lightning, they talk about a plug-in for Sublime.  Not a MavensMate plug-in.  One made by Salesforce.

So my question is:  Where can I go for reliable, convenient development of Lightning components?