2

I'm new to salesforce development. I've developed a lightning component from which i need to insert or delete a particular entry on clicking a checkbox. Delete if the entry exists already and insert if it doesn't

This is how my app look like

This is how my app look li

This is the client side js Controller method i'm using..

    updateAvailability: function(cmp, evt, helper) {
        var product_id = evt.getParam("product_id");
        var task_id = cmp.find('task_id').get("v.value");
        var account_id = cmp.find('account_id').get("v.value");
        var activity_id = cmp.find('activity_id').get("v.value");
        helper.updateAvailability(cmp, product_id, activity_id, task_id, account_id);
    }

This is the client side js helper method i'm using..

updateAvailability: function(cmp, product_id, activity_id, task_id, account_id) {
    var action = cmp.get("c.updateAvailability");
    console.log('task_id : ' + task_id);
    console.log('account_id : ' + account_id);
    console.log('activity_id : ' + activity_id);
    console.log('product_id : ' + product_id);
    action.setParams({
        "product_id": product_id,
        "activity_id": activity_id,
        "task_id": task_id,
        "account_id": account_id
    });
    $A.enqueueAction(action);
}

and this here is the apex method in server.

@AuraEnabled
public static void updateAvailability(String product_id, String activity_id, String task_id, String account_id) {
    try {
        Task_Ledger__c taskDetail;
        try{
            // delete if the entry exists already
            taskDetail = [SELECT Id, Task__c, Account__c, Action__c, Product__c, Measure_value__c FROM Task_Ledger__c WHERE Task__c = :task_id AND Action__c = :activity_id AND Account__c = :account_id AND Product__c  = :product_id AND Measure_value__c = '1'];
            System.debug('dlt');
            delete taskDetail;
        }
        catch (System.QueryException e){
            // insert
            System.debug(e);
            taskDetail = new Task_Ledger__c(Task__c = task_id,Account__c = account_id, Action__c = activity_id, Product__c = product_id);
            taskDetail.Measure_value__c = '1';
            System.debug('upsert');
            upsert taskDetail;
        }
    } catch(Exception e) {
        System.debug('Message: ' + e.getMessage());
    }
}

This is the main component i'm using

<aura:component controller="TaskController" implements="force:appHostable">

    <!-- Salesforce's Lightning Design : Installed Package -->
    <ltng:require styles="/resource/slds0101/assets/styles/salesforce-lightning-design-system.min.css"/>
    <!-- Handle component initialization in a client-side controller -->
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

    <!-- Event for updateing Availabilty Details Page corresponding to activity Detail id  -->
    <aura:handler name="updateAvailability" event="c:updateAvailability" action="{!c.updateAvailability}" />

    <aura:attribute name="activityDetails" type="Activity_Detail__c[]"/>

    <aura:attribute name="curr_activity" type="String"/>
    <aura:attribute name="curr_task" type="String"/>
    <aura:attribute name="curr_account" type="String"/>

    <div class="container">
        <ui:inputText class="slds-hide task_id" aura:id="task_id" value="{!v.curr_task}" />
        <ui:inputText class="slds-hide account_id" aura:id="account_id" value="{!v.curr_account}" />
        <ui:inputText class="slds-hide account_id" aura:id="activity_id" value="{!v.curr_activity}" />

        <ul class="slds-list--vertical slds-has-cards slds-col--padded slds-p-top--large">
            <aura:iteration var="activityDetail" items="{!v.activityDetails}">
                <li class="slds-list__item slds-tile__detail">
                <!-- BOF Nested Component -->
                <c:AvailabilityDetails activityDetail="{!activityDetail}" />
                <!-- EOF Nested Component -->
                </li>
            </aura:iteration>
        </ul>
        <br/>
    </div>
</aura:component>

This is the nested component AvailabilityDetails

          <aura:component >
             <aura:attribute name="activityDetail" type="Activity_Detail__c"/>

    <aura:registerEvent name="updateAvailability" type="c:updateAvailability"/>

    <div class="slds-grid ">
        <div class="slds-col slds-text-heading--label">{!v.activityDetail.Product_Name__c}</div>
        <div class="slds-col">
            <div class="slds-form-element slds-float--right">
                <label class="slds-checkbox" for="{!v.activityDetail.Id}">
                    <input name="checkbox" type="checkbox" id="{!v.activityDetail.Id}" onclick="{!c.updateAvailability}"/>
                    <span class="slds-checkbox--faux"></span>
                    <span class="slds-form-element__label"></span>
                </label>
            </div>
        </div>
    </div>
</aura:component>

This is my event file

    <aura:event type="COMPONENT">
        <aura:attribute name="product_id" type="String"/>
    </aura:event>

This is js controller file for calling event

    ({
      updateAvailability : function(component, event, helper) {
        var product_id = event.target.id;
        var uav = component.getEvent("updateAvailability");
        uav.setParams({ "product_id": product_id }).fire();
      }
    })

When i check this from my developer console's 'executable anonymous window', it's working fine..

Nothing happens when i run this from the Salesforce1 app.

Logs are showing in Force.com Developer Console i click from the Salesforce1 app or from the preview app in browser but debug messages are not showing..

Is there any syntax error with the helper method or any issues with way the apex method is used?

When running from chrome, i get this warning message in console

WARNING: Action failed: todo_list$controller$updateAvailability
15
  • Did you check if any javascript errors show up in javascript console?
    – Patlatus
    Feb 11 '16 at 9:23
  • hi @Patlatus, i got this warning message WARNING: Action failed: todo_list$controller$updateAvailability
    – sreejith
    Feb 11 '16 at 9:31
  • do you see 'task_id :' string parameter in javascript console and other javascript logs in console?
    – Patlatus
    Feb 11 '16 at 10:23
  • Yes.. I'm getting all of them.. I took them and executed from Force.com Developer console's 'executable anonymous window'. It's working fine there..
    – sreejith
    Feb 11 '16 at 10:36
  • Can you share component file as well? Feb 11 '16 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.