Comments (14)
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.
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.
from force-rest-api.
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.
from force-rest-api.
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.
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.
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
from force-rest-api.
from force-rest-api.
Oh, I didn't see your updated response. Yes, you will have to deploy the Apex class first.
from force-rest-api.
Ok!
from force-rest-api.
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.
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.
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)
- Add formula to DescribeSObject.Field
- Force REST API - giving below exception
- BUG with get knowledgeArticles HOT 3
- Return http responses instead of void calls
- updateSObject: "The Id field should not be specified in the sobject data" HOT 1
- Missing instance_url and id in ApiSession HOT 2
- Support for jdk 10 HOT 1
- Support for Blob data HOT 2
- Redirect not working HOT 1
- did not save the the id of the created object. any way to update the object?
- Test failure on v46 HOT 2
- Support for Salesforce Platform Events HOT 1
- Adding support for batch size for SOQL HOT 5
- Provide support for Rest Resource calls. HOT 1
- JDK 8, mvn install -DskipTests is failing. HOT 1
- Username and password are not escaped in soap login.
- Is support search api now? HOT 4
- Add support for Headers HOT 1
- autoRenew in ForceAPI.java not working
- Add support for JWT Bearer Flow HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from force-rest-api.