Ability to convert lead into account?
Hi! I wasn't sure what was the best way to contact you.
Is there a way to convert a lead into an account through the client? If so, would you be able to add it to the readme as an example?
Thanks!
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.
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.
It’s an Apex class so it’s not using REST API. I believe an Apex solution is being proposed because there is no way to do it via REST API directly. The Apex class is exposed as a rest endpoint which can be called via a standard REST http call.
On Mon, Dec 4, 2017 at 10:19 AM sfdaniele [email protected] wrote:
Thanks for the quick answer!
I had seen that, what's unclear to me is whether this class https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dml_convertLead.htm 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.
— You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/jesperfj/force-rest-api/issues/64#issuecomment-349054397, or mute the thread https://github.com/notifications/unsubscribe-auth/AARUrMRtSRexMZVWoONhk-mX6Nok5jCSks5s9DevgaJpZM4Q1B3P .
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!
force-rest-api supports calling custom endpoints like that one and reusing the autentication and marshalling logic. See the plain get/put/post/delete methods on ForceApi.
On Mon, Dec 4, 2017 at 10:33 AM sfdaniele [email protected] wrote:
Ok. The answer here https://developer.salesforce.com/forums/?id=906F0000000D6SBIA0 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!
— You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/jesperfj/force-rest-api/issues/64#issuecomment-349059091, or mute the thread https://github.com/notifications/unsubscribe-auth/AARUrHCdDk92W5aUbUvV-9CKUIT9Noaaks5s9DsJgaJpZM4Q1B3P .
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.
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.
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:
- Get a SF Developer account
- Create an Apex class that converts a lead to an account and add a rest resource for it
- Modify the code above to call this newly created endpoint
I'll take a look at it. The raw crud methods are relatively new and less battle tested. There might be some issues with them.
On Mon, Dec 4, 2017 at 12:26 PM sfdaniele [email protected] wrote:
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:
- Get a SF Developer account
- Create an Apex class that converts a lead to an account and add a rest resource for it
- Modify the code above to call this newly created endpoint
— You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub https://github.com/jesperfj/force-rest-api/issues/64#issuecomment-349094216, or mute the thread https://github.com/notifications/unsubscribe-auth/AARUrOVfC7-DbgQcMBEU85ZlqFmjadtjks5s9FVWgaJpZM4Q1B3P .
Oh, I didn't see your updated response. Yes, you will have to deploy the Apex class first.
Ok!
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!
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.
I don't know. I'm new to the Salesforce API but I wouldn't be surprised if there were more endpoints under services.