I found out I did not need a trigger. I can use a workflow rule
You can as long as the Agent Email is of type: Email. Here is how you can do that:
1. Setup | Create | Workflows & Approvals | Workflow Rules
2. New Rule
3. Select the Object: Opportunity
4. Evaluation Criteria: created and every time it's edited to subsequently meet the criteria
5. Rule Criteria: criteria are met
6. Criteria:
7.
Stage equals Agent Accepted
8. Click Save & Next
9. From under Immediate Workflow Actions, click Add Workflow Action select Email Alert
10. Specify the Email Template
11. Select the Recepient as Email Field
12. Select the Agent Email
13. Click Save
14. Hit Done
15. Activate
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;
} }
Best Answer
If you want to have something from Lightning components trigger an email, you have some options.
Workflow
When a record is saved, you can use a workflow rule to trigger sending an email. If the save is done as a result of your component, then great. It still works.
Apex
Here you don't have to depend upon a record save. You can arbitrarily send email. But you are required to abide by the maximum outbound email limit.
Callout to External Email Service
Again, this is via Apex, but instead of using our email service, you could make a callout to an external email provider.
In the end, none of these really has anything to do with Lightning Components. Nor should they. Lightning Components is a client-side Javascript component framework. It runs in the browser/web view.