2

wrapperList Iterating Issues

Error : System.JSONException: N/A at [line:1, column:45]

I have corrected that passing parameter. But still I am getting that error.

Client side javascript:

SaveRecord: function(component,event,helper){

        var idvalue1=component.find("o").get("v.value");
        var OppcenterId1=component.get("v.thepro");
        var propId=component.get("v.recordId");
        var wraper=component.get("v.wrplst");
        var saveAction=component.get("c.saveSpace");
        saveAction.setParams({
            "SelectSpaceRecord" : idvalue1,
            "proId":propId,
            "centerId":OppcenterId1, 
            "wrplst":JSON.stringify(wraper),
        });
      saveAction.setCallback(this, function(response) {
      var state = response.getState();
        if (component.isValid() && state === "SUCCESS") {
            component.set("v.isdisplay",false);
        } 
        else if (component.isValid() && state === "ERROR") {
            var errors = response.getError();
            if (errors) {
                if (errors[0] && errors[0].message) {
                    console.log("Error message: " +
                                errors[0].message);
                     var toastEvent = $A.get("e.force:showToast");
                    if (toastEvent) {
                        toastEvent.setParams({
                            "title": "Please Correct the values",
                            "message": errors[0].message,
                            "type": "error",
                            "mode": "pester"
                        });
                        toastEvent.fire();
                    } 
                    else 
                    {
                        alert(errors[0].message);
                    }
                }
            } 
        }
    });
    $A.enqueueAction(saveAction);
    } 
}

************server side********************

//save Logic starts here
@AuraEnabled
public static void saveSpace(string SelectSpaceRecord,string proId,string centerId,string wrplst)
{

    system.debug('@@@enter the savespace method@@@@');
    system.debug('before searlize wrplst value@@@@'+wrplst);
    List<spaceWrapper>wrperlst=(List<spaceWrapper>)JSON.deserialize(wrplst,List<spaceWrapper>.class); //Here Iam getting Error
    system.debug('@@@After Deseralize @@@'+wrperlst);

    Decimal n=0;
    Decimal totZopa=0; 
    Decimal TotProposedSpc=0;
    List<Space_Selected__c> splist=new List<Space_Selected__c>();
    Proposal__c prs=new Proposal__c();
    prs=[select id,opportunity__c,opportunity__r.Max_Approved_Price__c,opportunity__r.Centre__c,Minimum_Approved_Price__c,(select Id,Name,Booked_To_Date__c,Conference_Credits__c,No_of_Desks__c,Cost__c,Price_Unit__c from Line_Items__r) from  Proposal__c where Id =:proId];
    system.debug('@@@prs value @@@'+prs.opportunity__r.Max_Approved_Price__c);
    decimal prMax=prs.opportunity__r.Max_Approved_Price__c;  


    for(spaceWrapper sw1:wrperlst)
    {

        if(sw1.isSelected)
        {
            if(sw1.Price!=null && sw1.NoOfDesks!=null)
            {

                n=(sw1.Price*sw1.NoOfDesks)+n;
            }
            if(sw1.ZopaLimit!=null)
            {
                totZopa=sw1.ZopaLimit+totZopa;
            }
        }
    }
    if(n!=null &&prMax!=null  && n<prMax && prMax>0)
    {
        AuraHandledException e = new AuraHandledException('Proposed Price Should Not be Less than Zopa limit');
        e.setMessage('Proposed Price Should Not be Less than Zopa limit');
        system.debug(e);
        throw e;
    }
    else if(n!=null && n<totZopa && prMax==null)
    {
        AuraHandledException e = new AuraHandledException('Proposed Price Should Not be Less than Zopa limit');
        e.setMessage('Proposed Price Should Not be Less than Zopa limit');
        system.debug(e);
        throw e;
    }
    else
    {
        for(spaceWrapper sw1:wrperlst)
        {
            system.debug('***I am calling Sw1****');
            if(sw1.isSelected)
            {
                system.debug('sw1 selected value==>'+sw1.isSelected);
                Space_Selected__c spacesel=new Space_Selected__c();
                spacesel.Name=sw1.spsRec.Name;
                spacesel.ZOPA_Limit__c=sw1.ZopaLimit; 
                spacesel.One_Time_Set_Up_Desk__c=sw1.onetimeSetupCost;
                spacesel.Price_Unit__c=sw1.Price;
                spacesel.Unit_Type__c =sw1.UnitType;
                spacesel.No_of_Desks__c=sw1.NoOfDesks;
                spacesel.Space_Cost_Unit__c=sw1.SpacePrice;
                spacesel.Cost__c=sw1.Price*sw1.NoOfDesks;
                spacesel.Proposal__c=proId;
                spacesel.Centre__c =centerId;           /* center__c value  */
                system.debug('***center__c lookup value***'+spacesel.Centre__c);
                spacesel.Space__c=sw1.spsRec.Id;      /* Space__c value   */
                system.debug('***space_c loolup value***'+ spacesel.Space__c);
                /*  proposal id pssing  */
                system.debug('***Proposal_C lookup value***'+ spacesel.Proposal__c);
                spacesel.Conference_Credits__c=sw1.conference;
                spacesel.Priniting_Credits__c=sw1.Printing;
                spacesel.Booked_To_Date__c=sw1.bookedTo;
                spacesel.Booked_From_Date__c=sw1.bookedFrom;
                String recTypeId = '';

                recTypeId = Schema.getGlobalDescribe().get('Space_Selected__c').getDescribe().getRecordTypeInfosByName().get(sw1.spsRec.RecordType.Name).getRecordTypeId();
                if(!String.IsBlank(recTypeId))
                {
                    spacesel.RecordTypeId=recTypeId;
                } 
                splist.add(spacesel);
                system.debug('splist value===>'+splist);

            }
        }
        if(!splist.isEmpty()){
            insert splist; 
            system.debug('****Insert splist value*****'+splist);
        }
    }

}

If I make any value as null in wrplst.

It shows error in this line

(List<spaceWrapper>)JSON.deserialize(wrplst,List<spaceWrapper>.class);

How can I resolve it?

2
  • console.log your stringified list. Grab the JSON and validate it using an online validator. There is a good chance you'll find the error. Check for nulls, or strangely formatted JSON syntax. – Caspar Harmer Jan 31 '17 at 9:22
  • Can you add whole code of spaceWrapper class. is spaceWrapper class an inner class – Pranay Jaiswal Jan 31 '17 at 9:32
1

The order of parameters that you are passing and the apex class accepting the parameters should exactly match .

In your case you are sending params in wrong order .The variable names should also match.

saveAction.setParams({
                       "proId":propId,
                       "centerId":OppcenterId1, 
                       "wrplst":JSON.stringify(wraper),
                        "SelectSpaceRecord" : idvalue1
                   });
4
  • On mobile can someone help format my code . – Mohith Shrivastava Jan 31 '17 at 5:04
  • Thanks Mohith Shrivastava ... I just Updated the post now still I'am getting that error – Annappa Jan 31 '17 at 5:28
  • Add the whole code – Mohith Shrivastava Jan 31 '17 at 5:30
  • I have added the whole code.Please check it – Annappa Feb 1 '17 at 7:11

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.