0

apex

public class Edit_Controller {
@AuraEnabled public static List<OpportunityLineItem> ItemList {get; set;}

@AuraEnabled 
public static List<PriceBookEntry> Oppline(List<String> lstId,String OppId){
    system.debug('lstId'+lstId);
    system.debug('OppId'+OppId);
    List<PriceBookEntry> Unit = [SELECT Id,Name,Product2.Unit__c,Product2.Unit__r.Occupancy_Status__c
                                 FROM PriceBookEntry where Id = :lstId and IsActive = true];
    List<OpportunityLineItem> ItemList = new List<OpportunityLineItem>(); 
    system.debug('allUnit'+allUnit);
    String msg = '';
    if(allUnit.size()>0){
        for(PriceBookEntry items : allUnit){
            OpportunityLineItem newOppLine = new OpportunityLineItem();
            newOppLine.OpportunityId = OppId;
            //newOppLine.Product2 = items.Name;
            newOppLine.Product2Id = items.id;
            newOppLine.Quantity = 1;
            newOppLine.UnitPrice = 100;
            ItemList .add(newOppLine);
            system.debug('ItemList '+ItemList ); 
        }
     }
    return allUnit;
}

js -- I need to get ItemList List from apex but js not receive

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

action.setParams({ "OppId" : getOppId , lstId : ListData });
action.setCallback(this, function(response) {
    // store the response return value (wrapper class insatance)  
  **var result = response.getReturnValue();**
    var state = response.getState();
    console.log('result ---->' + JSON.stringify(result.optyLineItemList));
    // set the component attributes value with wrapper class properties.   
    if (component.isValid() && state === "SUCCESS") {
      **component.set("v.Oppline", result.ItemList );**
        console.log("Oppline=",Oppline);
    } else {
        console.log("Failed with state: " + state);
        alert('Failed in calling server side action');
    }
});
  • 1
    Hi Roedo, welcome to SFSE. It looks like your Apex code is returning a non-existent variable. You also might want to explain in a little more detail what you are trying to accomplish and what result you are getting. – AvailableName Feb 19 at 7:47
  • This code should not compile at the first place. There's no declaration for allUnit. Then for your issue, you are not getting the return value in JS, because you are not returning that from Apex. You are expecting ItemList in JS, whereas you are returning allUnit. – Jayant Das Feb 19 at 13:54
0

try changing your JS code to

action.setParams({ lstId : ListData, "OppId" : getOppId});
action.setCallback(this, function(response) {
// store the response return value (wrapper class insatance)  
var state = response.getState();
if (component.isValid() && state === "SUCCESS") {
    var result = response.getReturnValue();
    console.log('result ---->' + JSON.stringify(result));   
} else {
    console.log("Failed with state: " + state);
}
});

Make sure,

  • ListData and getOppId are already defined and have values
  • As it is JS which makes them case sensitive so validate that as well.

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.