1

This is my apex controller:

public class EventsController {

    public String JsonMap{get;set;}
    public Map<ID, Map<Integer, List<Event_Product__c>>> prod_quantity{get;set;}

    public PageReference ManageAttendee(){
        //Code ......   
        system.Debug(prod_quantity);
        JsonMap=JSON.serialize(prod_quantity);  
    }

    @RemoteAction
    public static ASPHPP__ASPayment_TXN__c getPaymentTXNs(String prod_quantity_2){
        system.Debug(prod_quantity_2);
    }

}

The data on the prod_quantity in ManageAttendee is this:

{a0428000006OyU1AAK={1=(Event_Product__c:{Id=a0428000006OyU1AAK, Name=Event Product-0023, Event_Product_Name__c=Summit General Admission, Price__c=10.00, Minimum_Quantity__c=1, Maximum_Quantity__c=10, Attendee_Custom_Fields__c=Anonymous__c;First_Name__c;Last_Name__c;Email_Address__c})}}

Then I passed to VF page using JsonMap.

<apex:page sidebar="false" showheader="false" standardStylesheets="false" docType="html-5.0" controller="EventsController">


    <script>
        window.onload = processPayment;     
        var prod_quantity_2 = JSON.parse('{!JsonMap}');

        function processPayment(){   
            setTimeout(Visualforce.remoting.Manager.invokeAction(    
            '{!$RemoteAction.EventsController.getPaymentTXNs}',    
            prod_quantity_2,    
            function(result, event) {    
                if(result == null){   
                    // Code .....   
                }else{   
                    // Code .....   
                }                   
            }), 2000);    
        }

    </script>
</apex:page>

The data of the prod_quantity_2 on the @RemoteAction is this:

{a0428000006OyU1AAK={1=[{attributes={type=Event_Product__c, url=/services/data/v34.0/sobjects/Event_Product__c/a0428000006OyU1AAK}, Id=a0428000006OyU1AAK, Name=Event Product-0023, Event_Product_Name__c=Summit General Admission, Price__c=10, Minimum_Quantity__c=1, Maximum_Quantity__c=10, Attendee_Custom_Fields__c=Anonymous__c;First_Name__c;Last_Name__c;Email_Address__c}]}}

It is different with the previous data of prod_quantity.. Is there other way to pass a map into a vf page then to the RemoteAction? Or can I access the map directly to the RemoteAction since they are in the same controller?..

1 Answer 1

1

One way i would do is using serialize and deserialize approach .Note although I have not tried but I am merely guess the below should do the trick assuming salesforce will recognize complex type

public class EventsController {

public String JsonMap{get;set;}
public Map<ID, Map<Integer, List<Event_Product__c>>> prod_quantity{get;set;}

public PageReference ManageAttendee(){
    //Code ......   
    system.Debug(prod_quantity);
    JsonMap=JSON.serialize(prod_quantity);  
}

  @RemoteAction
public static ASPHPP__ASPayment_TXN__c getPaymentTXNs(String prod_quantity_2){
    system.Debug(prod_quantity_2);
     Map<ID, Map<Integer, List<Event_Product__c>>> m = new Map<ID, Map<Integer, List<Event_Product__c>>>();
      m = (Map<ID, Map<Integer, List<Event_Product__c>>>)JSON.deserialize(paramMAPJSON,Map<ID, Map<Integer, List<Event_Product__c>>>.class);
   }

 }

<apex:page sidebar="false" showheader="false" standardStylesheets="false" docType="html-5.0" controller="EventsController">


<script>
    window.onload = processPayment;     
    //var prod_quantity = JSON.parse('{!JsonMap}');

    function processPayment(){   
        setTimeout(Visualforce.remoting.Manager.invokeAction(    
        '{!$RemoteAction.EventsController.getPaymentTXNs}',    
        '{!JSENCODE(JsonMap)}',    
        function(result, event) {    
            if(result == null){   
                // Code .....   
            }else{   
                // Code .....   
            }                   
        }), 2000);    
    }

</script>

2
  • Hi.. Thanks to your answer.. I got Idea because of it.. I make some changes.. Map<ID, Map<Integer, List<Event_Product__c>>> m= new Map<ID, Map<Integer, List<Event_Product__c>>>(); m= (Map<ID, Map<Integer, List<Event_Product__c>>>)JSON.deserialize(prod_quantity_2,Map<ID, Map<Integer, List<Event_Product__c>>>.class); and also I removed the JSENCODE so in the passing from jscript I use this '{!JsonMap}' Commented Oct 14, 2015 at 8:32
  • JSENCODE is necessary from security perspective .Also the other was typo and I just corrected it Commented Oct 14, 2015 at 14:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .