2

In Visualforce controllers, we have ApexPages.currentPage().getHeaders() to get info like user-agent, etc... Is there any equivalent for Lightning controllers? I know this info can be found from $Browser on the front end, but I can't find a way to access it from Apex.

  • As you can't access this directly on the server side then send it from the client. BTW what you are trying this user agent string? – itzmukeshy7 Jan 5 '18 at 6:29
0

You can use $Browser and get the information needed and pass that as a parameter to the apex method when you make a call to the server.

({
    checkBrowser: function(component) {
        var action = component.get("c.getUserAgent");

        action.setParams({
           device: $A.get("$Browser.formFactor")
        });

        action.setCallback(this, function(a) {
          if (a.getState() === "SUCCESS") {
            component.set("v.contact", a.getReturnValue());
          } else if (a.getState() === "ERROR") {
            $A.log("Errors", a.getError());
          }
        });

      $A.enqueueAction(action);
     }
})
  • So the only way to do this is to go through every single server call in my entire application and add a parameter? We'd like to log some diagnostic info in the event of an exception on the server side, but it looks like there's still no viable infrastructure to do that. – Jim Madrigal Jan 5 '18 at 13:36

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.