• Nathan Hinchey
  • NEWBIE
  • 60 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 3
    Likes Given
  • 4
    Questions
  • 14
    Replies
I'm building a lightning component to override the New action for a custom sObject, let's call it My_Object. My_Object has a master detail relationship with Contact (My_Object is the detail). The way user's are going to create a new My_Object is by clicking on the New button of the My_Object related list on Contact.

My issue is that after creating the record, I want to navigate back to the (master) Contact's page and see my newly created My_Object immediately.

I have a helper function to do this navigation:
 
navigateToContact: function(component) {
    var navEvt = $A.get("e.force:navigateToSObject");
    navEvt.setParams({
        "recordId": component.get("v.contact.Id") // this is the ID of the parent record
    });

    navEvt.fire();

}

This works for getting me to the page, but I can't see my new My_Object in the My_Object related list on Contact until I refresh the page.

What I tried:
  • I tried the method above
  • I also tried using force:navigateToURL, with the same result, and I tried using force:navigateToURL and adding a query string in the hopes of overcoming some kind of caching.
  • I unchecked Enable secure and persistent browser caching to improve performance in Session Settings

What I want is a way to make the newly created My_Object record appear on the Related List section without the User needing to manually refresh the page.

Is there a way to make this happen? Or a way to tell the Contact page to refresh immediately after navigation?
I'm trying to create a form using Lightning that allows the user to select a Contact (and in the future I will want to do this with other sObject types).

I just want to recreate this:

Contact insert field

Is this possible? Is there a relevant documentation section or tutorial you can link? If this is impossible, is there a workaround?

Thanks
I'm doing Lightning Components Basic - Input Data Using Forms, and I am running into an error I can't figure out.

I've reduced it here to the minimum code I can for reproducing the error, and I'm hoping someone can explain to me what's causing it.

campingApp.app
<aura:application extends="force:slds">
    <c:campingOneNewItem />
</aura:application>

campingOneNewItem.cmp
<aura:component >
    <aura:attribute name="items"
                    type="Camping_Item__c[]"/>
    <aura:attribute name="newItem"
                    type="Camping_Item__c"
                    default="{
                             'sObjectType': 'CampingItem__c',
                             'Quantity__c': 0,
                             'Price__c': 0
                             }"/>
    <form>
        <lightning:input type="number"
                 label="Quantity"
                 name="campingitemquantity"
                 value="{!v.newItem.Quantity__c}"
                 min="1"
                 aura:id="newcampingitemform"
                 messageWhenRangeUnderflow="Enter an amount that's at least 1"/>
        <lightning:button label="Add quantity"
                          onclick="{!c.addQuantity}"/>
    </form>
    <ol>
        <aura:iteration items="{!v.items}" var="item">
            <li><c:campingListItemSimple item="{!item}"/></li>
        </aura:iteration>
    </ol>
</aura:component>

campingListItemSimple.cmp
<aura:component >
    <aura:attribute name="item"
                type="Camping_Item__c"
                required="true"/>
    <h2>Quantity</h2>
    <p>
        <lightning:formattedNumber value="{! v.item.Quantity__c}" style="number"/>
    </p>
</aura:component>

campingOneNewItemController.js
({
	addQuantity : function(component, event, helper) {
        // Get current items
        var items = component.get('v.items');
        // Create the new item
        var newItem = component.get('v.newItem');
    
        // Copy the expense to a new object
        // THIS IS A DISGUTING, TEMPORARY HACK
        var newItem = JSON.parse(JSON.stringify(newItem));
    
        // explicitly casting newItem.Quantity__c to Number had no effect:
        // newItem.Quantity__c = Number(newItem.Quantity__c);

        items.push(newItem);
        component.set("v.items", items);
	}
})

campingApp renders like this:
User-added image

But when I click Add quantity I get an error:

Sorry to interrupt
This page has an error. You might just need to refresh it. Action failed: lightning:formattedNumber$controller$init [Value number out of range for numberformat options property style] Failing descriptor: {lightning:formattedNumber$controller$init}

User-added image

I'm pretty sure that somehow Quantity__c is being cast to string, but even when I explicitly cast it to number before calling component.set I get this error.
What is the allowed syntax for v.attribute notation in controllers?

I found the same solution as @Jeff Hansen, but I'm curious about WHY. Why do we have to do
 
var a = component.get("v.item");
a.Packed__c = true;
component.set("v.item",a)

Instead of just doing
 
component.set("v.item.Packed__c",true)


to get the correct answer here?

I can't find documentation about this.

Thank you.

 

PS: is there a way to include code blocks in these questions and answers?

I'm doing Lightning Components Basic - Input Data Using Forms, and I am running into an error I can't figure out.

I've reduced it here to the minimum code I can for reproducing the error, and I'm hoping someone can explain to me what's causing it.

campingApp.app
<aura:application extends="force:slds">
    <c:campingOneNewItem />
</aura:application>

campingOneNewItem.cmp
<aura:component >
    <aura:attribute name="items"
                    type="Camping_Item__c[]"/>
    <aura:attribute name="newItem"
                    type="Camping_Item__c"
                    default="{
                             'sObjectType': 'CampingItem__c',
                             'Quantity__c': 0,
                             'Price__c': 0
                             }"/>
    <form>
        <lightning:input type="number"
                 label="Quantity"
                 name="campingitemquantity"
                 value="{!v.newItem.Quantity__c}"
                 min="1"
                 aura:id="newcampingitemform"
                 messageWhenRangeUnderflow="Enter an amount that's at least 1"/>
        <lightning:button label="Add quantity"
                          onclick="{!c.addQuantity}"/>
    </form>
    <ol>
        <aura:iteration items="{!v.items}" var="item">
            <li><c:campingListItemSimple item="{!item}"/></li>
        </aura:iteration>
    </ol>
</aura:component>

campingListItemSimple.cmp
<aura:component >
    <aura:attribute name="item"
                type="Camping_Item__c"
                required="true"/>
    <h2>Quantity</h2>
    <p>
        <lightning:formattedNumber value="{! v.item.Quantity__c}" style="number"/>
    </p>
</aura:component>

campingOneNewItemController.js
({
	addQuantity : function(component, event, helper) {
        // Get current items
        var items = component.get('v.items');
        // Create the new item
        var newItem = component.get('v.newItem');
    
        // Copy the expense to a new object
        // THIS IS A DISGUTING, TEMPORARY HACK
        var newItem = JSON.parse(JSON.stringify(newItem));
    
        // explicitly casting newItem.Quantity__c to Number had no effect:
        // newItem.Quantity__c = Number(newItem.Quantity__c);

        items.push(newItem);
        component.set("v.items", items);
	}
})

campingApp renders like this:
User-added image

But when I click Add quantity I get an error:

Sorry to interrupt
This page has an error. You might just need to refresh it. Action failed: lightning:formattedNumber$controller$init [Value number out of range for numberformat options property style] Failing descriptor: {lightning:formattedNumber$controller$init}

User-added image

I'm pretty sure that somehow Quantity__c is being cast to string, but even when I explicitly cast it to number before calling component.set I get this error.
What is the allowed syntax for v.attribute notation in controllers?

I found the same solution as @Jeff Hansen, but I'm curious about WHY. Why do we have to do
 
var a = component.get("v.item");
a.Packed__c = true;
component.set("v.item",a)

Instead of just doing
 
component.set("v.item.Packed__c",true)


to get the correct answer here?

I can't find documentation about this.

Thank you.

 

PS: is there a way to include code blocks in these questions and answers?

Hi,

I'm currently working on the "Connect to Salesforce with Server-Side Controllers" module and I'm facing an error.

The error is:
Error: An internal server error has occurred
Error ID: 615929029-122427 (-1189130377)



I already:
  • Re-wrote the code from zero
  • Checked other posts on this forum
  • Checked fields security
  • Tried to remove the "with sharing" from the Apex controller
The challenge has been marked "completed" but it doesn't work :(

I did not have any issue on the previous unit, with expenses.

Please find my code below. Do you have an idea because I'm going crazy :)

Camping.cmp:
<aura:component>
    <aura:attribute name="items" type="Camping_Item__c[]"/>
    <!-- PAGE HEADER -->
    <div class="slds-page-header" role="banner">
      <div class="slds-grid">
        <div class="slds-col">
          <p class="slds-text-heading--label">Camping items</p>
          <h1 class="slds-text-heading--medium">Items</h1>
        </div>
      </div>
    </div>
    <!-- / PAGE HEADER -->
	<c:campingList items="{!v.items}"/>
</aura:component>
campingList.cmp:
<aura:component controller="CampingListController">
	<aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
    <aura:attribute name="items" type="Camping_Item__c[]"/>
    <aura:attribute name="newItem" type="Camping_Item__c"
     default="{ 'sobjectType': 'Expense__c',
                    'Name': '',
                    'Price__c': 0,
                    'Quantity__c': '',
                    'Packed__c': false }"/>
    
    <!-- NEW EXPENSE FORM -->
    <div class="slds-col slds-col--padded slds-p-top--large">
  
          <div aria-labelledby="newitemform">
        
          <!-- BOXED AREA -->
          <fieldset class="slds-box slds-theme--default slds-container--small">
        
            <legend id="newItemform" class="slds-text-heading--small 
              slds-p-vertical--medium">
              Add Item
            </legend>
        
            <!-- CREATE NEW EXPENSE FORM -->
            <form class="slds-form--stacked">
        
              <div class="slds-form-element slds-is-required">
                  <div class="slds-form-element__control">
                      <ui:inputText aura:id="itemname" label="Item Name"
                          class="slds-input"
                          labelClass="slds-form-element__label"
                          value="{!v.newItem.Name}"
                          required="true"/>
                  </div>
             </div>
             <div class="slds-form-element slds-is-required">
                  <div class="slds-form-element__control">
                      <ui:inputNumber aura:id="itemprice" label="Price"
                          class="slds-input"
                          labelClass="slds-form-element__label"
                          value="{!v.newItem.Price__c}"
                          required="true"/>
        
                  </div>
              </div>
        
              <div class="slds-form-element">
                  <div class="slds-form-element__control">
                      <ui:inputNumber aura:id="itemquantity" label="Quantity"
                          class="slds-input"
                          labelClass="slds-form-element__label"
                          value="{!v.newItem.Quantity__c}"/>
                  </div>
              </div>
        
              <div class="slds-form-element">
                  <ui:inputCheckbox aura:id="itempacked" label="Packed?"
                      class="slds-checkbox"
                      labelClass="slds-form-element__label"
                      value="{!v.newItem.Packed__c}"/>
              </div>        
              <div class="slds-form-element">
                  <ui:button label="Create Item"
                      class="slds-button slds-button--brand"
                      press="{!c.clickCreateItem}"/>
              </div>
        
            </form>
            <!-- / CREATE NEW EXPENSE FORM -->
        
          </fieldset>
          <!-- / BOXED AREA -->
        
        </div>
        <!-- / CREATE NEW EXPENSE -->
    </div>    
    
    
    <div class="slds-card slds-p-top--medium">
        <header class="slds-card__header">
            <h3 class="slds-text-heading--small">Camping Items</h3>
        </header>
        
        <section class="slds-card__body">
            <div id="list" class="row">
                <aura:iteration items="{!v.items}" var="item">
                    <c:CampingItem item="{!item}"/>
                </aura:iteration>
            </div>
        </section>
    </div>

</aura:component>

CampingItem.cmp:
<aura:component >
    <aura:attribute name="item" type="Camping_Item__c"/>
    <p>Name:
        <ui:outputText value="{!v.item.Name}"/>
    </p>
    <p>Price:
        <ui:outputNumber value="{!v.item.Price__c}"/>
    </p>
    <p>Quantity:
        <ui:outputNumber value="{!v.item.Quantity__c}"/>
    </p>
    <p>Packed?:
        <ui:outputCheckbox value="{!v.item.Packed__c}"/>
    </p>
</aura:component>
CampingListController.apxc:
public with sharing class CampingListController {

    @AuraEnabled
    public static List<Camping_Item__c> getItems() {
        // Perform isAccessible() checking first, then
        return [SELECT Name, Price__c, Quantity__c, Packed__c FROM Camping_Item__c];
    }
    
    @AuraEnabled
    public static Camping_Item__c saveItem(Camping_Item__c newItem) {
        // Perform isUpdatable() checking first, then
        upsert newItem;
        return newItem;
    }
}
campingListController.js:
({
    // Load items from Salesforce
    doInit: function(component, event, helper) {
    
        // Create the action
        var action = component.get("c.getItems");
    
        // Add callback behavior for when response is received
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (component.isValid() && state === "SUCCESS") {
                component.set("v.items", response.getReturnValue());
            }
            else {
                console.log("Failed with state: " + state);
            }
        });
    
        // Send action off to be executed
        $A.enqueueAction(action);
    },
    
    clickCreateItem: function(component, event, helper) {
        if(helper.validateItemForm(component)){
            // Create the new item
            var newItem = component.get("v.newItem");
            helper.createItem(component, newItem);
        }
    }
})

campingListHelper.js:
({
    
    validateItemForm: function(component) {
        // Simplistic error checking
        var validItem = true;
    	/*
        // Name must not be blank
        var nameField = component.find("expname");
        var expname = nameField.get("v.value");
        if ($A.util.isEmpty(expname)){
            validExpense = false;
            nameField.set("v.errors", [{message:"Expense name can't be blank."}]);
        }
        else {
            nameField.set("v.errors", null);
        }
    
        // Amount must be set, must be a positive number
        var amtField = component.find("amount");
        var amt = amtField.get("v.value");
        if ($A.util.isEmpty(amt) || isNaN(amt) || (amt <= 0.0)){
            validExpense = false;
            amtField.set("v.errors", [{message:"Enter an expense amount."}]);
        }
        else {
            // If the amount looks good, unset any errors...
            amtField.set("v.errors", null);
        }
        */
        return(validItem);
	},
    
    createItem: function(component, newItem) {
        var action = component.get("c.saveItem");
        alert(JSON.stringify(newItem));
        action.setParams({"newItem": newItem});
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "ERROR") {
                var errors = response.getError();
                if (errors && errors[0]) {
                    console.log(errors[0]);
                }
                else {
                    console.log("Unknown error");
                }
            }            
            else if (component.isValid() && state === "SUCCESS") {
                var items = component.get("v.items");
                items.push(response.getReturnValue());
                component.set("v.items", items);
            }
        });
        $A.enqueueAction(action);
    }
})
Thanks  !





 
I'm going through this trail and I have gotten stuck on the Handle acitons with controllers module in the first section in the intermeidate developer trail. I am stuck onthe chalange for this module. The error i have not been able to get past is this: The campingListItem Lightning Component doesn't contain a button or its attributes are not set correctly when clicked.
I know the code i have now is not perfect, i have been messing with it trying everything i can think of for hours now. at this point this is what i have:
<aura:component >
    <aura:attribute name="item" type="Camping_Item__c" />
  
     <aura:attribute name="buttonDisabled" type="String" default="false"/>
   
    <ui:outputText value="{! v.item.name}"  />
     <ui:outputCheckbox value="{!v.item.Packed__c}"/>
     <ui:outputCurrency value="{!v.item.Price__c}"/>
     <ui:outputNumber value="{! v.item.Quantity__c}"  />
    <ui:button  label="Mark as packed" press="{!c.packItem}" disabled="{! v.buttonDisabled}" />
     
</aura:component>


and JS of
({
 packItem  : function(component, event, helper) {
      //component.set("v.item.Packed__c", true);      
       
       component.set("v.buttonDisabled", "true");         
 }
})


the one line is commented out because i was trying to just focus and get past this one error.
I just can't seem to figure out how the challenge want me to disable the button. very frustrating when the module doesn't give an example of how to do this and the challenge expects you to figure it out. I've looked at all the additional resources for the module and looked in forms and google, and i guess this is my last hope. otherwise I guess I'll have to skip this challenge...
Thanks for any help.
 

Hi,

 

I need to retrieve some data using a nested SOQL, but I can't get the needed data. The SOQL is the following:

 

SELECT (SELECT Name,
               Unit_Price__c, 
               Quantity__c, 
               Time__c 
        FROM Valitut_Tuotteet__r)
FROM Service_Reservation__c 
WHERE Room_Reservation__c =: roomRes

 I need to extract the Name, Unit_Price__c, Quantity__c and Time__c and show them on a table (apex:repeat). Do you have any idea of how can I access that data?

 

Using <apex:repeat> and retrieving the fields doesn't work, I guess is because the data structure that the query creates is not a simple List<Service_Reservation__c>. 

 

Any idea on this?

 

Greetings,

 

MGA.

Hi,

 

I need to construct a CSV file with APEX and am a bit new to this cloud computing.

Do you have any sample code I could get started with that, or a resources that you can point me to develop and generate a  CSV File to send through the Email??

 

Can this be achieved in salesforce by any Way?

  • December 29, 2011
  • Like
  • 0

I'd like to get the dates of the most recently completed activities for each of a set of contacts by using a single SOQL query.

I realize that I could fetch all completed activities for those contacts and iterate through them to find the most recent ones, but I'm wondering if it's possible to do this in a single query that only returns the data I need.

If I were writing SQL instead of SOQL, I would do something like the examples below. (I've omitted the where clauses for simplicity.)

select WhoId, Max(ActivityDate) 
from Task where ... Group By WhoId

 or less optimally,

select WhoId, 
   (select top 1 from ActivityDate from Task T2 where T1.Id = T2.Id order by ActivityDate desc)
from Task T1
where ...
Group By WhoId

 

Neither of these approaches seems to translate directly to SOQL. Is there an alternative?


I'm looking for a method that will have a join/implode functionality.

 

I cannot seem to find an equivalent in the docs.  Does one exist in APEX?

 

Thanks

I'm getting a warning on a project in the IDE:

 

"Project was created in an older version of the Force.com IDE and must be upgraded to be used with Winter '11.  You will not be able to save or refresh files in this project from the server until you upgrade it.  To upgrade, use the upgrade wizard by right-clicking on the project in Package Explorer and choosing Force.com > Upgrade Project. " 

 

1) I've update Eclipse(helios)  to latest Force.com IDE release

2) Right clicking on project does NOT give an option to "upgrade project"

3) Despite the warning,  i am able to save and refresh files from the server

4) I've tried closing project, restarting eclipse and then re-opening project.

 

How do i upgrade this project?

 

Peter

  • December 05, 2010
  • Like
  • 0

Ultimately I am wanting to create a custom field called PO Received Month which pulls the month of the PO Received Date field, but in text format, not number format.

 

Currently this is the formula I put in the Formula Text field but its spitting out "4" for April and "5" for May and I want it to read "April" and "May".

 

 

TEXT(( YEAR( PO_Received_Date__c )))

 Thanks in advance!

 

Hi,

 

I checked off "Insert spaces for tabs" under Preferences, General, Editors, Text Editors. It replaces tabs I create with 4 spaces which is great. Unfortunately, it doesn't turn the tabs generated by the automatic indenting into 4 spaces.

 

Anyone know how to make this happen?

 

Thanks a lot,

Mike 

Hello there,
I wanted to find out the max(of a list of Dates) .e.g: Select PSOD_Project__r.Name,Resource__r.Name,max(Period_Beginning__c) from Time_Sheet__c where PSOD_Project__r.Name = 'PSOD Internal'

This is not working; Any hints whether this is feasible at all in SOQL ? if so, help pls.



Thanks,
Arun B
Apparently, internally, some calculations are made based on the values of this field.

I am not seeing where these values are.

Instead of my going through all the permutations - can you show me where these values are published, I'm not seeing it.

thanks.
I am trying to write a relationship query that will pull tasks along with the associated lead and owner.  I have a current query in production that works, but using sforce explorer returns an error that says "Query Failed: Length cannot be less than zero.  Parameter name: length"  Does anyone know what this error indicates?

This is my current query that works:

SELECT Id,
Subject,
ActivityDate,
Who.FirstName,
Who.LastName,
What.Name,
Status,
Priority
FROM TASK 
WHERE Owner.Email = '<email of owner>'
ORDER BY Priority


I'm trying to rewrite this to return values from the associated lead such as the lead id.  But, like I said, even the working production query is giving errors in sforce explorer.  The service url I am using is https://www.salesforce.com/services/Soap/u/10.0.  I tried using 9.0 and 8.0 and it still gives the same error.
  • September 25, 2007
  • Like
  • 0
Any idea how you can achieve an order by relevance clause in SOQL (similar to what returns by default in SOSL)? If not, is it possible to replicate the logic using some sort of custom class to parse and order the data? I may attempt doing this, but I wanted to see if anything out there existed already before spending too much time on it.
I have an Apex Trigger that is currenty calling upon a MAX function to display the most recent date a Task has been created.
 
for(AggregateResult aggregateResult:[SELECT max(createdDate)MaxCDate,WhatId FROM Task WHERE WhatID IN: acc_set AND Status ='Completed' AND Subject ='Completed Call' Group By WhatId]){
I want to change the date field that it is referencing from createdDate to ActivityDate like below:
 
for(AggregateResult aggregateResult:[SELECT max(ActivityDate)MaxCDate,WhatId FROM Task WHERE WhatID IN: acc_set AND Status ='Completed' AND Subject ='Completed Call' Group By WhatId]){

But when I do I recieve the following error: field ActivityDate does not support aggregate operator MAX at line 26 column 42.

Can anyone help me out here?
 
How can I get the current Salesforce User ID in an Apex class?

Any help is appreciated!

Chris