You need to sign in to do that
Don't have an account?
Call an URL/Web Service from Salesforce to fill up a field
Hi,
I'm a beginner with APEX, i just finished to administrate my company Salesforce but we need some APEX class and Trigger to be able to use Salesforce as we wish.
We have the basic product, and when the salesman will add a product to an opportunity we will ask him to put a "mpn number". So we want to use the mpm number who will define the real price of the product(it's a particular number linked to a product depends on the customization of this product)
The administrator of ou e-commerce give me an URL as this one
http://mycompany.com/mpn.getprice?id=[produit_uad_id]&mpn=[code_mpn]
i saw this:
public class HttpCalloutSample { // Pass in the endpoint to be used using the string url public String getContent(String url) { // Instantiate a new http object Http h = new Http(); // Instantiate a new HTTP request, specify the method (GET) as well as the endpoint HttpRequest req = new HttpRequest(); req.setEndpoint(url); req.setMethod('GET'); // Send the request, and return a response HttpResponse res = h.send(req); return res.getBody(); } }
but i still don't undsertand of i can use it with my opportunity product.
I'll try to find by myself, but if someone an help me it would be great!
Hi,
I tried but it look like not working.
I wanted to use the code below:
and i got this error message:
*************************************************
Apex script unhandled trigger exception by user/organization: 005E0000000iaWr/
GetRealPrice: execution of BeforeInsert
caused by: System.CalloutException: Callout from triggers are currently not supported.
Trigger.GetRealPrice: line 23, column 1
Trigger.GetRealPrice: line 9, column 1
There are some fundemental issues with your code and what you are trying to do:
1. find out if the API that you are calling to get the price has bulk mode (you send 50 items and you get data for 50 items back (or 100 or 200, you get the point - more than one at a time).
2. perform a callout for each but you have have to use batch apex (also some good reading material).
Hope this sets you on the right path.
i tried with a method alled @future but it still doesn't work.
I undestood, so my request is pretty bad, i was thinking that it will only take the opportunity line items from my current opportunity.
So i should make an other request , hmm for example
Id_UAD__c, MPN__c,UnitPrice FROM OpportunityLineItem
WHERE Opportunity IN (SELECT OpportunityLineItem FROM Opportunity )
??
my request still bad :s i tried to understand how can i get the OpportunityLineItem of my current Opportunity
what do you mean by current opportunity?
you are trying to update OpportunityLineItems - why do you need the opportunity?
Additionally, what if there are more than 10 line items in the trigger?
The correct way to do what you want (if there is no bulk API for whoever gives you prices)
is using batch apex - the rest of the attempts would really be a waste of your time.
Ok,
so every product on Salesforce are our "basic" products.
When a salesman will add a product to an opportunity he will also need to put the mpn( = unique ID for a product) who will call our website to get the real price, because the real price depend of every option set on the product .Salesforce doesn't allow us to put all of our product (because we have so many option on product).
So when i was talking about "the current opportunity" my meaning was the opportunity where my salesman is currently adding new product.
In trigger we can just work on 10 line?
Batch look the same isn't it?( i learn by working on the APEX workbook but i guess that i didn't really understood all in an half day)
in the Trigger will call this new class
but i know that something still doesn't work