• ZG
  • NEWBIE
  • 25 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 15
    Replies
I can't find a good example of a custom Apex class being set with default values on the Lightning component and then its values being updated in the helper function. The code below is not updating the object values retrieved from component.get even thought I have JSON.parse(JSON.stringify) to create a new editable object. What is the correct way to do this?
Apex class

public class Claim {

    public ID ContactID;
    public ID AccountID;
    public string RetireeNumber;
    public string recordType; 
  
    public Claim()
    {
        
    }
}


<aura:component controller="ClaimController">
   <aura:attribute name="claim" type="Claim"     
      default="{ContactID: '7890',
    AccountID: '12345',
    RetireeNumber': '6789',
    recordType: 'Rec Type 1',
    MedicalCodes: null}"
                   />

helper class

createMedicalCode: function(component...) 
{
        
        let claim = component.get("v.claim");
        console.log('claim:' + claim);
        claim.RetireeNumber = 'hello';
        claim.recordType = 'Claim';
        
        console.log('updated claim:' + claim);
   
        let newClaim = JSON.parse(JSON.stringify(claim));
        newClaim.RetireeNumber = 'hello';
        newClaim.recordType = 'Claim';
        console.log('newClaim' + newClaim);
        console.log('newClaim.RetireeNumber: '+ newClaim.RetireeNumber);
        console.log('newClaim["RetireeNumber"]: ' + newClaim["RetireeNumber"]);
       ...
}
     
})


The output on the console is:
 
claim:{ContactID: '7890',     AccountID: '12345',     RetireeNumber': '6789',     recordType: 'Claim',     MedicalCodes: null}
updated claim:{ContactID: '7890',     AccountID: '12345',     RetireeNumber': '6789',     recordType: 'Claim',     MedicalCodes: null} 
newClaim{ContactID: '7890',     AccountID: '12345',     RetireeNumber': '6789',     recordType: 'Claim',     MedicalCodes: null}
 
newClaim.RetireeNumber: undefined
newClaim["RetireeNumber"]: undefined

 
  • September 02, 2018
  • Like
  • 0
Hello, I am in the "Learn About Open Redirects" section of the  "App Logic Vulnerability Prevention" module in the Developer Advanced trail. I am stuck on the Open Redirects Basics Challenge because the changes I make to the completion URL parameter are not making it to the Save or Cancel methods: The completion value is still showing up as 'a07' no matter what I put at the completion parameter in the header.

Even before the challenge, the Open Redirects  Basics Demo is not working, I assume for the same reason the challenge page is not working. As given in the instructions, I enter '/apex/open_redirect_basics_demo?onSave=https://www.youtube.com/watch?v=dQw4w9WgXcQ', then I edit the Quantity field and click Enter but the page doesn't get redirected to youtube. Is there some kind of a setting I need to set so that upon clicking Save or Cancel, the new value of the onSave URL parameter is sent to the Save and Cancel methods?
  • March 19, 2018
  • Like
  • 0
In the Context Variable Considerations section of the Apex Developer Guide it is stated that for a before delete trigger:
Can update original object using an update DML operation: Allowed. The updates are saved before the object is deleted, so if the object is undeleted, the updates become visible.

Yet, the code below results in the exception System.FinalException: Record is read-only

Any ideas on how to accomplish this (Waypoint__c is a custom object from one of the trails modules. I added the text field field3__c to it)?
if(Trigger.isDelete)
        {
           
            List<Waypoint__c> lw = new List<Waypoint__c> {};
			for(Waypoint__c w : trigger.old)
            {
                lw.add(w);
            }
            for(Waypoint__c w : lw)
            {
                w.Field3__c = 'BeforeDel';
            }
            
            update lw;
  	}

 
  • March 14, 2018
  • Like
  • 0
On https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_expressions_operators_understanding.htm
it is stated that:

"Unlike Java, == in Apex compares object value equality, not reference equality, except for user-defined types."
"For sObjects and sObject arrays, == performs a deep check of all sObject field values before returning its result. Likewise for collections and built-in Apex objects." 

Why are the two asserts below failing then? If you look at the debug logs with the "Debug Only" option selected you should see that all 3 objects re identical.

Are the asserts below failing for you as well or is it just a glitch in my dev org?

// Two different ways to get a DescribeSObjectResult object 
        DescribeSObjectResult dsor1 = Account.SObjectType.getDescribe();
        DescribeSObjectResult dsor2 = Schema.sObjectType.Account;
        
        // Another way to get the DescribeSObjectResult using the Schema object
        List<DescribeSObjectResult> l =  Schema.describeSObjects(new List<String> {'Account'});
        DescribeSObjectResult dsor3 = l[0];
        
        System.assert(dsor1 == dsor2); // succeeds
       //System.assert(dsor1 == dsor3); // fails
      // System.assert(dsor2 == dsor3); // fails
       System.assert(dsor1.getsObjectType() == dsor3.getsObjectType()); // succeeds
       System.assert(dsor2.getsObjectType() == dsor3.getsObjectType()); // succeeds
        
        // If you look at the debug logs with the "Debug Only" option selected
        // you should see that the objects below are identical
        system.debug('dsor1: ' + dsor1);
        system.debug('dsor2: ' + dsor2);
        system.debug('dsor3: ' + dsor3);

 
  • March 13, 2018
  • Like
  • 0
Hello, I am new to Lightning and am going through the Lightning Components Basics module.

In the expensesHelper.js file would like to find out if it's possible to move the callback function definition inside the setCallback function to its own function and pass it in the arguments.

Instead of this:
({ 
    createExpense: function(component, expense) {
        var action = component.get("c.saveExpense");
        action.setParams({
            "expense": expense
        });
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                var expenses = component.get("v.expenses");
                expenses.push(response.getReturnValue());
                component.set("v.expenses", expenses);
            }
        })
        $A.enqueueAction(action);
    },
    
    
})

I would like to move the callback function defintion out into its own function like this:
 
({ 
    createExpense: function(component, expense) {
        var action = component.get("c.saveExpense");
        action.setParams({
            "expense": expense
        });
        action.setCallback(this, this.cbackfunction);
        $A.enqueueAction(action);
    },
    
    cbackfunction: function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                var expenses = component.get("v.expenses");
                expenses.push(response.getReturnValue());
                component.set("v.expenses", expenses);
            }
        }
    
})

WIth the code above I am getting the run-time error: "Error in $A.getCallback() [component is not defined]
   Callback failed: apex://ExpensesController/ACTION$saveExpense
   Failing descriptor: {c:expenses}"


I added a console log to make sure that "this.cbackfunction" exists and it does: 

   
console.log("this.cbackfunction: " + this.cbackFunction);
     this.cbackfunction: function (response) {
            var state = response.getState();
            var expenses = component.get("v.expenses");
            expenses.push(response.getReturnValue()); component.set("v.expenses", expenses);
        }


So, the cback function is visible from within the createExpense function.

Any ideas on how to call setCallback with a callback function?
  • March 01, 2018
  • Like
  • 0
I can't find a good example of a custom Apex class being set with default values on the Lightning component and then its values being updated in the helper function. The code below is not updating the object values retrieved from component.get even thought I have JSON.parse(JSON.stringify) to create a new editable object. What is the correct way to do this?
Apex class

public class Claim {

    public ID ContactID;
    public ID AccountID;
    public string RetireeNumber;
    public string recordType; 
  
    public Claim()
    {
        
    }
}


<aura:component controller="ClaimController">
   <aura:attribute name="claim" type="Claim"     
      default="{ContactID: '7890',
    AccountID: '12345',
    RetireeNumber': '6789',
    recordType: 'Rec Type 1',
    MedicalCodes: null}"
                   />

helper class

createMedicalCode: function(component...) 
{
        
        let claim = component.get("v.claim");
        console.log('claim:' + claim);
        claim.RetireeNumber = 'hello';
        claim.recordType = 'Claim';
        
        console.log('updated claim:' + claim);
   
        let newClaim = JSON.parse(JSON.stringify(claim));
        newClaim.RetireeNumber = 'hello';
        newClaim.recordType = 'Claim';
        console.log('newClaim' + newClaim);
        console.log('newClaim.RetireeNumber: '+ newClaim.RetireeNumber);
        console.log('newClaim["RetireeNumber"]: ' + newClaim["RetireeNumber"]);
       ...
}
     
})


The output on the console is:
 
claim:{ContactID: '7890',     AccountID: '12345',     RetireeNumber': '6789',     recordType: 'Claim',     MedicalCodes: null}
updated claim:{ContactID: '7890',     AccountID: '12345',     RetireeNumber': '6789',     recordType: 'Claim',     MedicalCodes: null} 
newClaim{ContactID: '7890',     AccountID: '12345',     RetireeNumber': '6789',     recordType: 'Claim',     MedicalCodes: null}
 
newClaim.RetireeNumber: undefined
newClaim["RetireeNumber"]: undefined

 
  • September 02, 2018
  • Like
  • 0
Hello, I am in the "Learn About Open Redirects" section of the  "App Logic Vulnerability Prevention" module in the Developer Advanced trail. I am stuck on the Open Redirects Basics Challenge because the changes I make to the completion URL parameter are not making it to the Save or Cancel methods: The completion value is still showing up as 'a07' no matter what I put at the completion parameter in the header.

Even before the challenge, the Open Redirects  Basics Demo is not working, I assume for the same reason the challenge page is not working. As given in the instructions, I enter '/apex/open_redirect_basics_demo?onSave=https://www.youtube.com/watch?v=dQw4w9WgXcQ', then I edit the Quantity field and click Enter but the page doesn't get redirected to youtube. Is there some kind of a setting I need to set so that upon clicking Save or Cancel, the new value of the onSave URL parameter is sent to the Save and Cancel methods?
  • March 19, 2018
  • Like
  • 0
In the Context Variable Considerations section of the Apex Developer Guide it is stated that for a before delete trigger:
Can update original object using an update DML operation: Allowed. The updates are saved before the object is deleted, so if the object is undeleted, the updates become visible.

Yet, the code below results in the exception System.FinalException: Record is read-only

Any ideas on how to accomplish this (Waypoint__c is a custom object from one of the trails modules. I added the text field field3__c to it)?
if(Trigger.isDelete)
        {
           
            List<Waypoint__c> lw = new List<Waypoint__c> {};
			for(Waypoint__c w : trigger.old)
            {
                lw.add(w);
            }
            for(Waypoint__c w : lw)
            {
                w.Field3__c = 'BeforeDel';
            }
            
            update lw;
  	}

 
  • March 14, 2018
  • Like
  • 0
On https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_expressions_operators_understanding.htm
it is stated that:

"Unlike Java, == in Apex compares object value equality, not reference equality, except for user-defined types."
"For sObjects and sObject arrays, == performs a deep check of all sObject field values before returning its result. Likewise for collections and built-in Apex objects." 

Why are the two asserts below failing then? If you look at the debug logs with the "Debug Only" option selected you should see that all 3 objects re identical.

Are the asserts below failing for you as well or is it just a glitch in my dev org?

// Two different ways to get a DescribeSObjectResult object 
        DescribeSObjectResult dsor1 = Account.SObjectType.getDescribe();
        DescribeSObjectResult dsor2 = Schema.sObjectType.Account;
        
        // Another way to get the DescribeSObjectResult using the Schema object
        List<DescribeSObjectResult> l =  Schema.describeSObjects(new List<String> {'Account'});
        DescribeSObjectResult dsor3 = l[0];
        
        System.assert(dsor1 == dsor2); // succeeds
       //System.assert(dsor1 == dsor3); // fails
      // System.assert(dsor2 == dsor3); // fails
       System.assert(dsor1.getsObjectType() == dsor3.getsObjectType()); // succeeds
       System.assert(dsor2.getsObjectType() == dsor3.getsObjectType()); // succeeds
        
        // If you look at the debug logs with the "Debug Only" option selected
        // you should see that the objects below are identical
        system.debug('dsor1: ' + dsor1);
        system.debug('dsor2: ' + dsor2);
        system.debug('dsor3: ' + dsor3);

 
  • March 13, 2018
  • Like
  • 0
Hello, I am new to Lightning and am going through the Lightning Components Basics module.

In the expensesHelper.js file would like to find out if it's possible to move the callback function definition inside the setCallback function to its own function and pass it in the arguments.

Instead of this:
({ 
    createExpense: function(component, expense) {
        var action = component.get("c.saveExpense");
        action.setParams({
            "expense": expense
        });
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                var expenses = component.get("v.expenses");
                expenses.push(response.getReturnValue());
                component.set("v.expenses", expenses);
            }
        })
        $A.enqueueAction(action);
    },
    
    
})

I would like to move the callback function defintion out into its own function like this:
 
({ 
    createExpense: function(component, expense) {
        var action = component.get("c.saveExpense");
        action.setParams({
            "expense": expense
        });
        action.setCallback(this, this.cbackfunction);
        $A.enqueueAction(action);
    },
    
    cbackfunction: function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                var expenses = component.get("v.expenses");
                expenses.push(response.getReturnValue());
                component.set("v.expenses", expenses);
            }
        }
    
})

WIth the code above I am getting the run-time error: "Error in $A.getCallback() [component is not defined]
   Callback failed: apex://ExpensesController/ACTION$saveExpense
   Failing descriptor: {c:expenses}"


I added a console log to make sure that "this.cbackfunction" exists and it does: 

   
console.log("this.cbackfunction: " + this.cbackFunction);
     this.cbackfunction: function (response) {
            var state = response.getState();
            var expenses = component.get("v.expenses");
            expenses.push(response.getReturnValue()); component.set("v.expenses", expenses);
        }


So, the cback function is visible from within the createExpense function.

Any ideas on how to call setCallback with a callback function?
  • March 01, 2018
  • Like
  • 0