function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Fred13Fred13 

Not passing values from JS controller to Apex

Hi.  I have been working on a cloning process that allows me to copy a record x number of times and then saving those copies as new records.

I am stuck on saving the records and returning to the original component.

I have the records saved in an attribute on the javascript controller but they are not getting passed to the controller  I suspect that my syntax is off or that I cannot pass multiple values.  So I have two problems that I'm asking for help with:
1. why am I getting a null pointer error on my apex class (the variable I'm passing to the apex class is not getting populated)
2. How can I pass the account ID back to my component (GroupStructures) so I can navigate back here after the save.

Any help would be greatly appreciated!!!

Here is the Component and Apex Class
({
	createClones: function(component, GroupStructures) {
    //Save the expense and update the view
    this.upsertGS(component, GroupStructures, function(a) {
        var groupstructures = component.get("v.newGroupStructures");
        groupstructures.push(a.getReturnValue());
        component.set("v.newGroupStructures", groupstructures);
    });
},
    
    upsertGS : function(component, GroupStructures, callback) {
        //set the return page
      	var evt = $A.get("e.force:navigateToComponent");
		evt.setParams({
            componentDef: "c:GroupStructures",
            componentAttributes :{ 
              recordId:groupstructure.Account__c
             }
        });
  var action = component.get("c.saveGroupStructure");
	  action.setParams({ 
          //I have confirmed that the values are in my variable in the js controller
      group_structure__c: GroupStructures
	  });
  if (callback) {
      action.setCallback(this, callback);
  }
  $A.enqueueAction(action);
        ///navigate back to groupstructures page
        evt.fire();
},
public class GSClone {
	@AuraEnabled

	public static group_structure__c saveGroupStructure (group_structure__c gs) {
    //public static group_structure__c saveGroupStructure (groupstructure gs) {
	system.debug ('### I got in the apex class' + gs);

	insert gs;
	return gs;
    
    }
}




 
Raj VakatiRaj Vakati
Try this'
 
({
	createClones: function(component, GroupStructures) {
    //Save the expense and update the view
    this.upsertGS(component, GroupStructures, function(a) {
        var groupstructures = component.get("v.newGroupStructures");
        groupstructures.push(a.getReturnValue());
        component.set("v.newGroupStructures", groupstructures);
    });
},
    
    upsertGS : function(component, GroupStructures, callback) {
        //set the return page
      	var evt = $A.get("e.force:navigateToComponent");
		evt.setParams({
            componentDef: "c:GroupStructures",
            componentAttributes :{ 
              recordId:groupstructure.Account__c
             }
        });
  var action = component.get("c.saveGroupStructure");
  
   action.setParams({ firstName : cmp.get("v.firstName") });
     action.setParams({ 
      gs: GroupStructures
	  });
  if (callback) {
      action.setCallback(this, callback);
  }
  $A.enqueueAction(action);
        ///navigate back to groupstructures page
        evt.fire();
},

 
Raj VakatiRaj Vakati
({
	createClones: function(component, GroupStructures) {
    //Save the expense and update the view
    this.upsertGS(component, GroupStructures, function(a) {
        var groupstructures = component.get("v.newGroupStructures");
        groupstructures.push(a.getReturnValue());
        component.set("v.newGroupStructures", groupstructures);
    });
},
    
    upsertGS : function(component, GroupStructures, callback) {
        //set the return page
      	var evt = $A.get("e.force:navigateToComponent");
		evt.setParams({
            componentDef: "c:GroupStructures",
            componentAttributes :{ 
              recordId:groupstructure.Account__c
             }
        });
  var action = component.get("c.saveGroupStructure");
  
      action.setParams({ 
      gs: GroupStructures
	  });
  if (callback) {
      action.setCallback(this, callback);
  }
  $A.enqueueAction(action);
        ///navigate back to groupstructures page
        evt.fire();
},

 
Fred13Fred13
Unfortunately, I'm still gettin a null pointer on the apex class.  thanks!!

Fred