• Himanshu Chhabra 9
  • NEWBIE
  • 5 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi I am new to Salesforce Lightning. I am trying to insert a Task Records uisng Lightning Components But I am getting an error.

Below is my Code:
1.Apex Controller

public class SaveTaskRecords {

 @AuraEnabled
 public static Task save(Task ta) {
  insert ta;
  return ta;

 }
 @AuraEnabled
 public static Task getTask() {
  return [select Id, whoId, ActivityDate from Task Limit 1];
 }

 public static List < String > getTaskStatus() {
  List < String > options = new List < String > ();
  Schema.DescribeFieldResult fieldResult = Task.status.getDescribe();
  List < Schema.PicklistEntry > ple = fieldResult.getPicklistValues();
  for (Schema.PicklistEntry f: ple) {
   options.add(f.getLabel());
  }

  return options;
 }
}

2.Client Side Controller:

({
 saveTask: function(component, event, helper) {
  var newTask = component.get("v.newTask");
  var action = component.get("c.save");
  action.setParams({
   "ta": newTask

  });
  action.setCallback(this, function(a) {
   var state = a.getState();

   if (state === "SUCCESS") {
    var name = a.getReturnValue();
    alert("success");
   } else {
    console.log("Testt" + a.getReturnValue());
    alert("Failed");
    console.log("Testt" + a.getReturnValue());
   }
  });
  $A.enqueueAction(action)
 },

 doInit: function(component, event, helper) {
  var action = component.get("c.getTaskStatus");
  var inputsel = component.find("InputSelectDynamic");
  var opts = [];
  action.setCallback(this, function(a) {
   for (var i = 0; i < a.getReturnValue().length; i++) {
    opts.push({
     "class": "optionClass",
     label: a.getReturnValue()[i],
     value: a.getReturnValue()[i]
    });
   }
   inputsel.set("v.options", opts);

  });
  $A.enqueueAction(action);
 }
})

3. Lightning Component:

<aura:component  controller="SaveTaskRecords">
    <aura:attribute name="newTask" type="Task"  default="{ 'sobjectType': 'Task',
                     'OwnerId': '','Status':'','Subject':'',}"/>
    <form>
        <force:inputField  value="{!v.newTask.OwnerId}" />
        <force:inputField aura:id="contactField" value="{!v.newTask.Status}" />
        <force:inputField aura:id="contactField" value="{!v.newTask.Priority}" />
        <force:inputField aura:id="contactField"  value="{!v.newTask.WhoId}" />
        <ui:inputDate aura:id="contactField" label="Today's Date" class="slds-input" value="{!v.newTask.ActivityDate}" displayDatePicker="true" />
        <lightning:button aura:id="contactField" label="Save Task" onclick="{!c.saveTask}"/>
    </form>
</aura:component>

Can any one please help?
Hi

I want my trigger to check a custom checkbox field (called Cancelled) when my opportunity stage changes from closed won to closed lost.
I know we can get that information from Opportunity Stage History reports also we can create a workflow rule (below)

1 AND(
2 ISCHANGED(IsWon),
3 PRIORVALUE(IsWon),
4 IsClosed,NOT(IsWon))

From a knowledge perspective how can I achieve this via trigger?

Thanks