0

Hi I have a problem with passing parameter into apex class. I need to pass there field value from object. This value is hidden and its not showing anywhere in component, its only saved in database.

    deleteTemporaryTransaction : function(cmp, event){
        var action = cmp.get("c.deleteTempTransactions");
        cmp.set("v.data", []);
        action.setParams

//how to add value HERE
({klipId : *value here* });

        action.setCallback(this, function (actionResult) {

        })
        $A.enqueueAction(action);
        console.log("delete temp");
    },
2
  • Can you explain more this:- I need to pass their field value from the object. This value is hidden and it is not showing anywhere in the component, its only saved in the database? Commented Sep 7, 2018 at 13:13
  • I have a object, where are many custom fields. I have an aura iterator which is showing me data. When i want to delete on button click, i need to pass specific value of one field there. For example i have field "CaseId__c" and i want to usite like this action.setParams ({klipId : {!data.CaseId__c });
    – David
    Commented Sep 7, 2018 at 13:24

1 Answer 1

1

You can pass the argument value in your apex controller through Client side controller as follows:-

({
    handClick : function(component, event, helper) {

         var ObjectWith5Fields = component.get("v.candidate");
        var action = component.get("c.saveRecord");
        action.setParams({
            "cand" : ObjectWith5Fields
        });
        action.setCallback(this, function(response) {
            var state = response.getState();
            if( state === "SUCCESS") {
                alert("hello from here");
            }
        } );
        $A.enqueueAction(action);
    }
})

Here, I am getting the Object value using

var ObjectWith5Fields = component.get("v.candidate");

and then calling the apex method as:-

var action = component.get("c.saveRecord");

and setting the value of argument using

action.setParams({ "cand" : ObjectWith5Fields });

And, Here is my apex Controller:-

public with sharing class SampleAppController {

    @AuraEnabled
    public static void saveRecord(Candidate__c cand){
        if(cand!= null){
            insert cand;
        }
        System.debug('candidate is-->>' + cand);

    }
}

If you want to use it like this action.setParams ({klipId : {!data.CaseId__c });

After getting the object value from Component, what you need is set as follows:-

action.setParams({
            "klipId " : ObjectWith5Fields.CaseId__c 
        });

here ObjectWith5Fields is the variable to store the object value, as you can see in Controller code.

6
  • Hi thanks for tip, i used it like this deleteTemporaryTransaction : function(cmp){ var claimedTransData = cmp.get("v.data"); var action = cmp.get("c.deleteTempTransactions"); action.setParams( {"klipId" : claimedTransData.KLIP_Subcase} ); console.log(claimedTransData.KLIP_Subcase__c); $A.enqueueAction(action); console.log("delete temp"); } but its still "undefined"
    – David
    Commented Sep 10, 2018 at 7:17
  • Does it solve your problem? Commented Sep 10, 2018 at 7:30
  • no, its still passing undefined value
    – David
    Commented Sep 10, 2018 at 7:44
  • Update your question with what you are actually trying to achieve and component code snippet. I want to look at that and then suggest you. Commented Sep 10, 2018 at 7:47
  • No its working fine now, your answer was useful. I had a typo in code.
    – David
    Commented Sep 10, 2018 at 9:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .