-3

controller:

    public class Gss_CsHelathCheckExtension {
    ApexPages.StandardSetController setCon;
    public String[] lstSelUserDataIds{get; set;}
    public Gss_CsHelathCheckExtension(ApexPages.StandardSetController standardController)
    {
        system.debug('---constructor--');
        this.setCon =standardController;
        lstSelUserDataIds = new String[]{};
            for(case selectedRec : (List<case>)setCon.getSelected())
        {
            lstSelUserDataIds.add(selectedRec.id);
            system.debug('---lstSelUserDataIds--'+lstSelUserDataIds);
        }
    }
  }

Component:

<!-- caselist value from vf page
 <aura:attribute name="caselist" type="String[]"/>

Js side:

var action=component.get("c.getCaseDetails");
action.setParams({
     "caseIDStr":component.get("v.caselist"),
});
action.setCallback(this,function(response) {
   var state=response.getState();
   if(state==='SUCCESS'){
       component.set("v.caseSerExcList",response.getReturnValue());
   }
});
$A.enqueueAction(action);  

Server side:

@AuraEnabled
public static List<object> getCaseDetails(String [] caseIDStr){
 system.debug('caseIDStr---->'+caseIDStr);
  //for this query id values are not passing.If I do hardcode it will work
   if(!caseIDStr.isEmpty()){
        clist=[Select Id, 
CaseNumber,GSS_Business_unit__c,GSS_Support_Level__c,owner.Name from Case 
     where Id IN:caseIDStr];
    }
    system.debug('clist --->'+clist);

    for(Case c: clist ){
        caseSerExcList.add(new CaseAssociatedSerExc(c));
    }
    system.debug('caseSerExcList--->'+caseSerExcList);
}

enter image description here

7
  • 1
    Did my answer make sense? Feb 10 '19 at 23:08
  • 2
    I would encourage you to restore the original context of your question and accept one of the good answers you've received, understand the problem that's been illuminated by them, and move forward with debugging based on that understanding - looking now at where you have differences between JSON and non-JSON values.
    – David Reed
    Feb 11 '19 at 3:14
  • 1
    That is not at all what I meant. I'm going to stop here.
    – David Reed
    Feb 11 '19 at 3:23
  • 3
    It kind of sucks - I spent a good bit of time reformatting that question so it made sense (and didn't get downvoted)... and then it all got blown away. Feb 11 '19 at 6:13
  • 2
    I would roll back to a specific edit and clear this up if i had any idea which edit would make sense. As it is, Annappa, you should know how to be a good citizen of SFSE by now. You've been on this site for two years. Please do not completely change what you are asking after you have already received answers. You should perhaps revisit the tour and reread How to Ask. Right now, your post contains nothing but code. It would have been dramatically improved by including words describing what you are trying to achieve, as well as the verbatim error message in your post body.
    – Adrian Larson
    Feb 11 '19 at 14:22
1

Since v.caselist is already an array, you don't need to encode it:

var action=component.get("c.getCaseDetails");
action.setParams({
     "caseIDStr": component.get("v.caselist"),
});
action.setCallback(this,function(response) {
   var state=response.getState();
   if(state==='SUCCESS'){
       component.set("v.caseSerExcList",response.getReturnValue());
   }
});
$A.enqueueAction(action);  

Also, arguably, since they are ID values, use the correct data type:

public static List<object> getCaseDetails(Id[] caseIDStr){
4
  • Updated the question. Feb 11 '19 at 3:02
  • I will reopen this question Feb 11 '19 at 3:49
  • The only reason I don't normally do this is because if you pass a bad id, all you get is a Internal Server Error, whereas if you handle it yourself, you at least have a little more to go on... probably doesn't matter much in the end. I guess I just REALLY don't trust the built in serialization at this point. Feb 11 '19 at 6:15
  • @CasparHarmer True, but, barring any programming mistakes, the only way you'd get an internal server error is users monkeying with the data as it goes to the server. Except for those situations where the platform itself is causing the problem (e.g. Integer values were frequently failing), it is preferable to use the correct data type. In fact, there was a recent question about this behavior (they're fixing parsing in Spring 19), where I advised on using the correct data types, and that's why.
    – sfdcfox
    Feb 11 '19 at 6:19
3

The problem is that you are passing a single string of all the caseIds, rather than an array caseIds. This occurs because you are calling JSON.stringify on the list in Javascript.

When the single string gets to Apex, it is processed single character by single character - you are iterating like this: "5", "0", "0".... ect

So you can either:

  • Not call stringify and send the raw Javascript array
  • Call it (sometimes a good idea with serialization wackyness in lightning) - but then convert back to a List in Apex.

I myself would call stringify and rehydrate in Apex.

So your Apex method could be:

public static sObject[] getCaseDetails(String caseIds){

Id[] caseIdList = (Id[].class)JSON.deserialize(caseIds,Id[].class)
//you are done - don't forget to include a try / catch here

Note, I normally would return an object that can indicate an error and also return back data. Currently you can't do this, as your return type can only return back a list of sObjects.

So if you want to improve this method, try returning back a result object with a data object and a success boolean and a message. This is normally sufficient for almost every scenario.

I also generally serialize the data object into a string, so it can then have a payload of any data type.

3
  • im getting follwing exception:Illegal assignment from System.Type to List<Id> Feb 11 '19 at 1:35
  • Look at Annappa's other question, I actually figured out the data was wrong upstream; your specific answer wouldn't have worked because the [] characters really were there (it was all a red herring from Visualforce encoding the string for Lightning Out).
    – sfdcfox
    Feb 11 '19 at 6:21
  • 1
    True... but I provided an answer that should have worked, given the question that was asked. Feb 11 '19 at 6:58

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.