• Benjamin Rush
  • NEWBIE
  • 10 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
I am wanting to set up REST web services inside of Salesforce that can get, create, and change records for a particular object (leads in this case) whenever it is invoked. I will be invoking these methods from an external website. The POST (create) method I will be using is shown below. I will obviously be adding functionality to the web services themselves. I am only looking to figure out how to actually call them rather than how to write them.
@RestResource(urlMapping='/lead/*')
global class MyWebService {
    @HttpPost
    global static id postLead(string firstName, string lastName, string leadSource, string status) {
        lead newLead = new Lead();
        newLead.FirstName = firstName;
        newLead.LastName = lastName;
        newLead.LeadSource = leadSource;
        newLead.Status = status;
        insert newLead;
        return newLead.id;
}
Then in my javascript (jQuery allowed) code on the external site, I would presumably be creating HttpRequest objects that call these methods; however, I can't seem to get anywhere on this topic. I've tested a plethora of different parameters, but my general code is along the lines of
$.ajax(
    method:"get",
    cache:false,
url:"https://myinstance.lightning.force.com/services/apexrest/lead/leadIdHere",
    success: function(data) {
       alert(data);
    }
);
I know that this is in part because you need to authenticate, but I can'r seem to figure out what the URI for that method would be, not how to retain it. I've tried going through this with JSForce (https://jsforce.github.io) but haven't had any luck there (although I was able to get login authentication working with that.

I am just looking to call a simple REST web service that has been written inside of Salesforce from an external webpage using JavaScript.
 
I have a standard object, "Account", with a custom pick list, "Number", that contains 5 vaules: First, Second, Third, Fourth, and Fifth.

I also have a custom object, "Number", that has 5 records: First, Second, Third, Fourth, and Fifth.

I want to change the pick list "Number" field to be a lookup relationship field that relates to the "Number" custom object.

The only way that I know for certain I could do this is to:
1. Create a new custom field on the "Account" object named "NumberTemporary"
2. Run a script that populates "NumberTemporary" with the current "Number" value
3. Change the "Number" pick list field from a pick list to a lookup relationship
4. Run a script that populates "Number" with the id of the record that corresponds to the "NumberTemporary" value
5. Delete the "NumberTemporary" field

This solution comes with the limitation of only being able to update 10,000 records at a time, and just seems like a dirty way to get it done. I will do this if need be, but I was wondering if there is any better approach.

Thank you!
I am wanting to set up REST web services inside of Salesforce that can get, create, and change records for a particular object (leads in this case) whenever it is invoked. I will be invoking these methods from an external website. The POST (create) method I will be using is shown below. I will obviously be adding functionality to the web services themselves. I am only looking to figure out how to actually call them rather than how to write them.
@RestResource(urlMapping='/lead/*')
global class MyWebService {
    @HttpPost
    global static id postLead(string firstName, string lastName, string leadSource, string status) {
        lead newLead = new Lead();
        newLead.FirstName = firstName;
        newLead.LastName = lastName;
        newLead.LeadSource = leadSource;
        newLead.Status = status;
        insert newLead;
        return newLead.id;
}
Then in my javascript (jQuery allowed) code on the external site, I would presumably be creating HttpRequest objects that call these methods; however, I can't seem to get anywhere on this topic. I've tested a plethora of different parameters, but my general code is along the lines of
$.ajax(
    method:"get",
    cache:false,
url:"https://myinstance.lightning.force.com/services/apexrest/lead/leadIdHere",
    success: function(data) {
       alert(data);
    }
);
I know that this is in part because you need to authenticate, but I can'r seem to figure out what the URI for that method would be, not how to retain it. I've tried going through this with JSForce (https://jsforce.github.io) but haven't had any luck there (although I was able to get login authentication working with that.

I am just looking to call a simple REST web service that has been written inside of Salesforce from an external webpage using JavaScript.
 
I have a standard object, "Account", with a custom pick list, "Number", that contains 5 vaules: First, Second, Third, Fourth, and Fifth.

I also have a custom object, "Number", that has 5 records: First, Second, Third, Fourth, and Fifth.

I want to change the pick list "Number" field to be a lookup relationship field that relates to the "Number" custom object.

The only way that I know for certain I could do this is to:
1. Create a new custom field on the "Account" object named "NumberTemporary"
2. Run a script that populates "NumberTemporary" with the current "Number" value
3. Change the "Number" pick list field from a pick list to a lookup relationship
4. Run a script that populates "Number" with the id of the record that corresponds to the "NumberTemporary" value
5. Delete the "NumberTemporary" field

This solution comes with the limitation of only being able to update 10,000 records at a time, and just seems like a dirty way to get it done. I will do this if need be, but I was wondering if there is any better approach.

Thank you!