1

I'm using remote action to call apex function, and the issue is the parameter that passed might contain several white space, But I can see in the logs that several white spaces are being removed, and only 1 is left. Any idea how to avoid this issue? I thought to replace the white spaces before the invoke method with some characters and then in apex restore it, but perhaps there is better solution.

As example- I tried to enter value: "1 2 3" but in the remote function it received as: "1 2 3"

<apex:page controller="MyController">

    <apex:form>

        <apex:pageBlock>

            <apex:pageBlockButtons >

                <apex:commandButton value="Call Remote" oncomplete="callRemoteJS(); return false;"/>
            </apex:pageBlockButtons>

            <apex:pageBlockSection columns="1" id="pbSectionId">

                <textarea id="inputAreaid" />
            </apex:pageBlockSection>

        </apex:pageBlock>

    </apex:form>

<script>
function callRemoteJS(){
    try{
        var inputText = document.getElementById('inputAreaid').value;

        console.log('inputText :' +inputText );

        Visualforce.remoting.Manager.invokeAction(
            '{!$RemoteAction.MyController.remoteFunction}',
            inputText, 
            function(result, event){
                try{
                    //handle response
                }catch(err){
                    alert(err);
                }
            }
        );
    }catch(err){
        alert(err);
    }
}
</script>
</apex:page>

Class:

global class MyController{

    public MyController(){
    }

    @RemoteAction
    public static String remoteFunction(String testParam){

        System.debug('testParam:' + testParam);

        return 'ok';
    }
}

enter image description here

4

At first I thought it might be something to do with escape parameter in JavaScript remoting.

But issue here is the logs in developer console trims the extra spaces, if you double click on the line or view it in debug logs, you would see correct value with spaces.

enter image description here

  • Thanks. You're right. Actually I see this also in the object field... As in my remote I'm saving the data to object fields, and when view it in the layout it is shown without spaces, but when open the record in edit mode, it does show the spaces. – Liron C Jan 13 '18 at 18:31

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.