1) You are pushing to newVote
which is of type Public_Article_Rating__c it is not an array
2) Assuming you constructed your vote code based on this example
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/qs_aotp_app.htm
You are missing an array attribute of type Public_Article_Rating__c
Add this line to your component:
<aura:attribute name="votes" type="Public_Article_Rating__c[]"/>
Update:
Component:
<aura:component controller="ArticleVotingcontroller" implements="forceCommunity:availableForAllPageTypes" >
<aura:attribute name="votes" type="Account[]"/>
<aura:attribute name="newVote" type="Account"
default="{'sobjectType':'Account',
'Name':'',
'prao6308__RSSFEEDUPDATER__c':'',
'AccountNumber':''
}"/>
<form>
<div id="ratingArea">
<span>Was this article helpful?</span>
<ui:inputCheckbox aura:id="voteUp" label="Yes"
value="{!v.newVote.prao6308__RSSFEEDUPDATER__c}"/>
<ui:inputText aura:id="accounname" label="name" value="{!v.newVote.Name}"/>
<ui:inputNumber aura:id="articleComments" label="Comments"
value="{!v.newVote.AccountNumber}"/>
<br/>
<ui:button label="Submit" labelClass="label"
press="{!c.createVote}"/>
</div>
</form>
</aura:component>
Client side controller:
({
createVote : function(component, event, helper) {
var newVote = component.get("v.newVote");
console.log(newVote);
helper.createVote(component, newVote);
}
})
helper:
({
createVote : function(component, vote) {
this.upsertVote(component, vote, function(a){
var accs = component.get("v.votes");
accs.push(a.getReturnValue());
console.log('here'+accs);
component.set("v.votes", accs);
});
},
upsertVote : function(component, vote, callback){
var action = component.get("c.saveVote");
action.setParams({
"vote": vote
});
//If upsert of the account is success I want to alert the account Id back to the user.
action.setCallback(this, function(response)
{
var state = response.getState();
if (state === "SUCCESS")
{
alert("From server: " + response.getReturnValue());
}
else if (state === "ERROR")
{
var errors = response.getError();
if (errors)
{
if (errors[0] && errors[0].message)
{
console.log("Error message: " +
errors[0].message);
}
}
else
{
console.log("Unknown error");
}
}
});
$A.enqueueAction(action);
}
})
server side controller:
public class ArticleVotingcontroller { @AuraEnabled
public static String saveVote(Account vote){
upsert vote;
system.debug('#####'+ vote);
return vote.Id;
} }
By a "null error", I'm assuming you mean a null pointer exception. If that's the case, you'll want to use a try-catch block where you catch the null-pointer exception. I'd also recommend you change your If condition to isEmpty
. Your code in the server side controller would look something like this:
try{
if(!isEmpty(caseRecord.Freight_AWB_Number__c){
requestJson = getRequestString(username, password, caseRecord.Freight_AWB_Number__c);
}
}catch(nullpointerexception e){
// show error AWB Number not provided. Lightning work to be done
msg = 'AWB Freight Number cannot be null';
errH = new ErrorHandler(false,msg);
return errH;
}
Best Answer
Your JSON
[{"name":"xxx","documentId":"xxx"}]
looks like an array, not an object.Change the way you get the docId to
var docId = uploadedFiles[0]["name"];
orvar docId = uploadedFiles[0].name;
and the loop to
for (var key in uploadedFiles[0]) {