我目前正在开发OpportunityLineItem的触发器,Salesforce上的每一个产品都是我们的“基础”产品。
当销售人员将产品添加到商机时,他还需要输入mpn (=产品的唯一ID ),该mpn将呼叫我们的网站以获得实际价格,因为实际价格取决于产品上设置的每个选项。我的触发器正在调用一个类来发出请求,到目前为止它是有效的!但是当我想添加相同的productID和mpn时,它将不起作用。
问题:
销售人员将添加一个产品OpportunityLineItem,但该产品已经在他当前的机会OpportunityLineItem中,因此它将不起作用。
首先,我的触发器不会得到价格,因为我的SOQL请求将返回多个结果。
下面是我的触发器:
trigger GetRealPrice on OpportunityLineItem (after insert) {
for(OpportunityLineItem op : Trigger.new){
RequestTest.getThePrice(op.Id_UAD__c,op.MPN__c,op.OpportunityId);
}
}这里是调用的类;
public class RequestTest {
//Future annotation to mark the method as async.
@Future(callout=true)
public static void getThePrice(Decimal idUad, String mpnProduct,String opID){
// Build the http request
Http http = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('http://www.site.com/mpn.getprice?id='+idUad+'&mpn='+mpnProduct);
req.setMethod('GET');
String result;
HttpResponse res = http.send(req);
System.debug(res.getBody());
result = res.getBody();
Decimal price = Decimal.valueof(result);
System.debug(opID);
OpportunityLineItem op = [SELECT UnitPrice FROM OpportunityLineItem
WHERE Id_UAD__c = :idUad
AND OpportunityId = :opID
AND MPN__c = :mpnProduct] ;
System.debug('you went through step1');
op.UnitPrice = price;
System.debug('This is the opportunity price'+op.UnitPrice);
update op;
}
}发布于 2012-07-03 02:09:51
由于您要遍历触发器中的每个行项目,因此需要传递行项目ID。然后更改方法以处理每个行项目的更新:
trigger GetRealPrice on OpportunityLineItem (after insert) {
for(OpportunityLineItem op : Trigger.new){
RequestTest.getThePrice(op.Id_UAD__c,op.MPN__c,op.Id);
}
}
...
public class RequestTest {
//Future annotation to mark the method as async.
@Future(callout=true)
public static void getThePrice(Decimal idUad, String mpnProduct,String opLineID){
...
Decimal price = Decimal.valueof(result);
System.debug(opID);
OpportunityLineItem op = [SELECT UnitPrice FROM OpportunityLineItem
WHERE Id = :opLineID] ;
op.UnitPrice = price;
System.debug('This is the opportunity price'+op.UnitPrice);
update op;
}
}https://stackoverflow.com/questions/11263145
复制相似问题