0

I have a problem that i've been trying to work around for a while now. Basically i have a list of objects (some have id's some don't, the ones that don't have them will be inserted instead of being updated).

If i change a value that already have been on the list (for ex. Daily_dead__c) with some previous value, it's getting updated. But if i change value of a field that previously have been null, the value being passed to js controller of component is also null.

That happens only for previously null fields.

Any idea what could this be?

<aura:attribute name="flockStatsList" type="Flock_stats__c[]" />

<aura:iteration items="{!v.flockStatsList}" var="fls" >
<tr>
    <td>
    {!if(fls.Day__c == null, fls.DayHidden__c, fls.Day__c)}
    </td>
     <td>
        <ui:inputText value="{!fls.Daily_dead__c}" updateOn="keyUp"/>
    </td>
    <td>
        <ui:inputText value="{!fls.Daily_selection__c}" updateOn="keyUp"/>
    </td>
    <td>
        <ui:inputText value="{!fls.Daily_feed_consumed__c}" updateOn="keyUp"/>
    </td>
    <td>
        <ui:inputText value="{!fls.Daily_water_consumption__c}" updateOn="keyUp"/>
    </td>
    <td>
        <ui:inputText value="{!fls.Avg_body_weight__c}" updateOn="keyUp"/>
    </td>
    <td>
        <ui:inputText value="{!fls.Number_of_weighings__c}" updateOn="keyUp"/>
    </td>
    <td>
        <ui:inputText value="{!fls.Feed_delivery_from_farm_to_house__c}" updateOn="keyUp"/>
    </td>
    <td>
        <ui:inputText value="{!fls.Feed_code__c}" updateOn="keyUp"/>
    </td>
    <td>
        <ui:inputText value="{!fls.Note__c}" updateOn="keyUp"/>
    </td>
 </tr>
</aura:iteration>

There is more code to this but its not relevant.

And aura js controller:

saveRecords: function(component, event, helper){

                    var spinner = component.find('spinner');
                    $A.util.removeClass(spinner, "slds-hide");

                    var New = component.get("v.flockStatsList");
                    var Old = component.get("v.flsListOld");

                    console.log('Data '+New);

                    //New = JSON.stringify(New);
                    //Old = JSON.stringify(Old);

                    //console.log('Data '+New);

                     for(var j=0; j<=49; j++)
                    {
                        New[j].sobjectType = "Flock_stats__c";
                    }

                    console.log(New);

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

                    action.setParams({ 
                        'flNew' : New
                    });
                action.setCallback(this, function(response) {
                    var data = response.getReturnValue();
                    var state = response.getState();
                    var errors = action.getError();
                    if (errors!= 0 && errors.length>0) {
                        console.log("error " + errors[0].message);
                    }
                    var spinner = component.find('spinner');
                    $A.util.addClass(spinner, "slds-hide");
                });
      $A.enqueueAction(action);
    },

Apex controller:

 @AuraEnabled
public static String saveRecordsApex(List<Flock_stats__c> flNew){


    system.debug('FlNew VALUE!!: '+flNew);

    //List<Flock_stats__c> flNewJSON = new List<Flock_stats__c>();
    //List<Flock_stats__c> flOldJSON = new List<Flock_stats__c>();
    //
    //flNewJSON = (List<Flock_stats__c>)JSON.deserializeStrict(flNew,List<Flock_stats__c>.class);
    //flOldJSON = (List<Flock_stats__c>)JSON.deserialize(flOld,List<Flock_stats__c>.class);


    List<Flock_stats__c> flockStatsListToUpsert = new List<Flock_stats__c>();



    for(Flock_stats__c flsList : flNew)
    {
        if(flsList.Daily_dead__c != null || flsList.Daily_selection__c != null || flsList.Daily_feed_consumed__c != null || flsList.Daily_water_consumption__c != null || flsList.Number_of_weighings__c != null || flsList.Feed_delivery_from_farm_to_house__c != null
            || flsList.Feed_code__c != null || flsList.Note__c != null)
        {
            system.debug('For loop Daily Dead: '+flsList.Daily_dead__c + flsList.Number_of_weighings__c);
            flockStatsListToUpsert.add(flsList);
        }
        else
        {
            system.debug('WEIRD For loop Daily Dead: '+flsList.Daily_dead__c);
        }
    }
    for(Flock_stats__c fsDebug : flockStatsListToUpsert)
    {
    system.debug('PanelStatystykWrapperController flockStatsListToUpsert Id and Daily Dead: '+fsDebug.Id + fsDebug.Daily_dead__c + fsDebug.Date__c);
    }

    try
    {
        upsert flockStatsListToUpsert;
    }
    catch(Exception e)
    {
        return JSON.serialize(e);
    }

    return 'Success';
}

}

Code you see here is not working because somehow apex controller gets error: "cant read sobject type" or something along those lines.

That happens if i try to send list of object type from component to apex. If i stringify it in component, send and deserialize it in apex, it's creating data but missing what i explained before.

  • 3
    Can you share some code that creates this problem? – Jeff Bennett Apr 12 '17 at 15:31
  • Please always do share the relevant code as well so that we can help you what you are doing wrong. – itzmukeshy7 Apr 12 '17 at 15:39
0

if your are getting data from server side and the fields/var are null they are NOT sent to the component. And setting them in the component does not allow you to pass them back to the server

I think this will help you(As I have not seen your code).

issue with SOQl query

Post some snippets for more clarification.

|improve this answer|||||
  • Link you provided explained my problem but if i create class wrapper i might stumble on problem i got earlier, which is this question: salesforce.stackexchange.com/questions/169396/… – LinQ Apr 13 '17 at 5:49
  • I've been iterating there over class wrapper that had 1 integer and 1 object per instance, would iterating over 1 instance containing whole list help? – LinQ Apr 13 '17 at 5:50

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.