1

I am not familiar with Angular js.

I have few qestions:

a) How to pass the Query param from angular js to salesforce?

b) Here with my code and it is not working.

VF Page:

<apex:page controller="angular3">
<script>
    var ngApp= angular.module('ngApp', []); 
        ngApp.controller('ContactCtrl' ,['$scope',function ($scope) {
            angular3.getLead(
                    function(result, event) {
                        $scope.lead = result;
                        $scope.fname = result.FirstName;
                        console.log(result);
                        console.log($scope.lead);
            });
        }]);
</script>

<body>
    <div class="bootstrap" ng-app="ngApp" ng-controller="ContactCtrl" >
    {{lead}}
        <h2 align="left">Create New Appointment</h2>
        <p>First name: {{fname}}</p>
        <table th="Customer Information">
            <tr>
                <td>First Name {{fname}} </td>
                <td>Last Name {{ lead.LastName }}</td>
            </tr>
            <tr>
                <td>Street {{ lead.street }}</td>
                <td>City {{ lead.city }}</td>
            </tr>
            <tr>
                <td>State {{ lead.state }}</td>
                <td>Zip Code {{ lead.zip }}</td>
            </tr>
        </table>
    </div>
<apex:stylesheet value="//cdn.jsdelivr.net/webjars/bootstrap-sf1/0.1.0-beta.6/css/bootstrap-namespaced.css"/>
<apex:includeScript value="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.11/angular.min.js"/>

Controller:

global class angular3 {

@RemoteAction
global static Lead getLead() { //(Id LeadId) {

    return [SELECT Id, Address, City, Company, Country, Description, Email, Fax, FirstName, Name, Industry, LastName,  Latitude, LeadSource, 
    Longitude, MobilePhone, OwnerId, Phone, Rating, Salutation, State, Status, Street, title, Website, PostalCode FROM Lead where Id = '00Q4100000J6CGn'];
}}

Please help me on this.

Thanks.

1 Answer 1

1

On b), in this case you need to notify Angular to run its digest cycle by adding:

$scope.$apply();

to the end of the callback function you pass to angular3.getLead. This is because you are making the server call through Salesforce code rather than Angular's built in $http service that handles that automatically.

On a), you pass the parameters to the @RemoteAction by placing them before the callback function:

angular3.getLead(
    $scope.leadId,
    function(result, event) {
        ...
    }
});


@RemoteAction
global static Lead getLead(Id leadId) {
    ...
}

and you will need to have the id available in the JavaScript to pass; above I'm assuming it has been added to the scope.

(Think that the name angular3 is going to be confusing in the long term so is worth changing; this is Angular 1.x code and Angular 3 is a near future version of the framework.)

You must log in to answer this question.

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