Git Product home page Git Product logo

Comments (14)

jesperfj avatar jesperfj commented on June 29, 2024

I don't think this is supported by REST API. A quick Google brings up workarounds like this one. If you think there's a way to do it in REST API, let me know and I'll take a look at docs.

from force-rest-api.

sfdaniele avatar sfdaniele commented on June 29, 2024

Thanks for the quick answer!

I had seen that, what's unclear to me is whether this class is just patching a lead and triggering a conversion or whether it's doing something more than that through the API upon calling Database.convertLead.

from force-rest-api.

jesperfj avatar jesperfj commented on June 29, 2024

from force-rest-api.

sfdaniele avatar sfdaniele commented on June 29, 2024

Ok. The answer here seems to suggest that there is an endpoint called your_instance_url/services/apexrest/convertlead where I can POST {"leadId" : lead_id}. Is my understanding correct? Do the endpoints under Apex Rest use the same authentication mechanism as the Force API?

If so, I'd have to re-use your authentication and client infrastructure to make that call. That most likely would require me to send a PR to you and change the client.

If all of the above is correct, could I do that? I'd have to dig into your code to figure out where to plug in.

Thanks!

from force-rest-api.

jesperfj avatar jesperfj commented on June 29, 2024

from force-rest-api.

sfdaniele avatar sfdaniele commented on June 29, 2024

Got it! I'll play around with it and report back, if it works perhaps we can add it to the README for future reference.

from force-rest-api.

sfdaniele avatar sfdaniele commented on June 29, 2024

Alright, I'm making some progress but encountering issues as well.

First, I had to temporarily work around ForceApi because the public request method prepends uriBase() to the path (session.getApiEndpoint()+"/services/data/"+config.getApiVersionString()).

The work around is ugly and it involves calling the private method apiRequest directly (it looks like the interface of ForceApi would need to change for this to work properly).

The second issue is that I can't seem to be able to call Apex.

  @Override public void convertLead(String salesforceLeadId) {
    try {
      // This is the ugly workaround
      Method method = forceApi.getClass().getDeclaredMethod("apiRequest", HttpRequest.class);
      method.setAccessible(true);
      // For simplicity, just try to GET a Lead through Apex. 
      HttpRequest httpRequest = new HttpRequest()
          .url(forceApi.getSession().getApiEndpoint() + "/services/apexrest/Lead/" + salesforceLeadId)
          .method("GET")
          .header("Accept", "application/json")
          .header("Content-Type", "application/json");
      Object result = method.invoke(forceApi, httpRequest);
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
      throw Throwables.propagate(e);
    }
  }

Invoking this causes a Caused by: com.force.api.ApiException: [{"errorCode":"NOT_FOUND","message":"Could not find a match for URL"}]. I've Googled it and it looks like sometimes this error is related to the existence of a namespace that needs to be included in the Apex URL. However, my organization doesn't have a namespace as far as I call tell by looking at the result of forceApi.query("SELECT NamespacePrefix FROM Organization").

@jesperfj I realize that this is getting in the weeds and I really appreciate your help here. It looks like there aren't many resources online to do this in Java so there isn't much documentation to go after.

from force-rest-api.

sfdaniele avatar sfdaniele commented on June 29, 2024

To add to my comment above, after reading a bit more about Apex it looks like I'll have to wire up the endpoint to convert a lead on the Salesforce side before I can call it, is that so?

If that's the case, then the solution would be to:

  1. Get a SF Developer account
  2. Create an Apex class that converts a lead to an account and add a rest resource for it
  3. Modify the code above to call this newly created endpoint

from force-rest-api.

jesperfj avatar jesperfj commented on June 29, 2024

from force-rest-api.

jesperfj avatar jesperfj commented on June 29, 2024

Oh, I didn't see your updated response. Yes, you will have to deploy the Apex class first.

from force-rest-api.

sfdaniele avatar sfdaniele commented on June 29, 2024

Ok!

from force-rest-api.

sfdaniele avatar sfdaniele commented on June 29, 2024

Hi,

I was finally able convert a lead into an account and it works! I'm still having to work around the fact that apiRequest is not public and request prefixes a /services/data path. Right now the only way to use the Apex API is to use apiRequest through reflection.

If possible, it would be awesome to change the ForceApi's interface so that there is a way to call arbitrary (non /services/data) endpoints.

The hardest part of this entire endeavor was figuring out how to create the Apex class and deploy it to production as I'm not that familiar with Salesforce. If you want to add information on how to integrate with Apex in your readme, I've written down some notes here. Feel free to use those.

Thanks!

from force-rest-api.

jesperfj avatar jesperfj commented on June 29, 2024

I see.

When I did the raw crud methods, I reused apiBase() which appends /services/data/<version>. I wonder if Apex REST is the only type of endpoint that doesn't need a version number? That would affect how this should be addressed.

This is certainly a bug. The crud methods were intended to be used with Apex REST for sure.

from force-rest-api.

sfdaniele avatar sfdaniele commented on June 29, 2024

I don't know. I'm new to the Salesforce API but I wouldn't be surprised if there were more endpoints under services.

from force-rest-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.