Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Salesforce by (11.9k points)

I am working on Salesforce1 (Aura platform). I am trying to pass values from client-side (javascript) to server-side controller(Apex-code). I tried by using setParams(); in JavaScript and @key annotation in Apex but @key is not supported in Apex.

Thanks in advance.

I am giving sample code here...

APPLICATION code:

 <aura:application>

      <PlumQ:example/>

     </aura:application>

COMPONENT code:

<aura:component model="PlumQ.ExampleServerSideController">

  <aura:attribute name="firstName" type="String" default="HELLO worlD"/>

  <ui:inputtext label="Name" aura:id="id1" value="{!v.firstName}" placeholder = "enter name" />

   <ui:button label="Native Aura Button" press="{!c.echo}"/>

</aura:component>

**client-side-controller(JAVASCRIPT):**

 ({

   "echo" : function(component) {

          alert('in client-Side-process');

          var b =component.get("v.firstName");

          alert('firstnaaaaame:::::::::::::'+b);

           var a = component.get("m.serverEcho");

           alert('After ServerSide Process');

          a.setParams({ firstName : component.get("v.firstName") });

           a.setCallback(this, function(action) {

                        if (action.getState() === "ERROR") {

                                     alert("Server Error: " + action.getError()[0].message);

                          }

                        else{

                                     alert("From server: " + action.getReturnValue());

                       }

});

             $A.enqueueAction(a);

} })

server-side-controller(APEX CLASS):

  public class ExampleServerSideController {

  @AuraEnabled

  public static String serverEcho(@Key("firstName") String firstName){

  System.out.println("In Example Trival controllerrrrr"+firstName);

  return ("From server: " +firstName);

   }

  }

1 Answer

0 votes
by (32.1k points)

From what I understand you cannot use bind variables as part of the GEOLOCATION:

String q = 'SELECT id, name, latlng__Latitude__s, latlng__Longitude__s ' +

            'FROM Account ' +

            'WHERE DISTANCE(latlng__c, GEOLOCATION(' + userLat + ',' +  userLong + '),' \'mi\') < 50 ' +

            'ORDER BY DISTANCE(latlng__c, GEOLOCATION(' + userLat + ',' +  userLong + '),' \'mi\') ' +

            'LIMIT 5';

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...