You need to sign in to do that
Don't have an account?

Inserting products
Hi all,
I have an app that users can add products to a quote through a wizard that grabs prices from a database and then uploads them to SF.com. It isn't woring and I don't know what I am doing wrong. I am querying all the ids and information from the corresponding pricebook in SF.com. I am attaching my code. Any help would be greatly appreciated.
Thanks in advance.
Rhonda
string sQueryProductID = "Select ID From Pricebook2 where Name = '" + sPriceListName + "'";
sForce.QueryResult qrProd = binding.query(sQueryProductID);
string sPricebookID = string.Empty;
string sPriceBookEntry = string.Empty;
string sProdID = string.Empty;
if (qrProd.size > 0)
{
sForce.Pricebook2 objProd = (sForce.Pricebook2)qrProd.records[0];
sPricebookID = objProd.Id.ToString();
}
sForce.SaveResult sr = new sForce.SaveResult();
for (int x = 0; x < sUSPrice.Length; x++)
{
float dTotal = float.Parse(sQuantities[x].ToString()) * float.Parse(sUSPrice[x].ToString());
string sQueryProdID = "Select ID, Name From Product2 where ProductCode = '" + sProdCode[x] + "'";
sForce.QueryResult qrProdID = binding.query(sQueryProdID);
if (qrProdID.size > 0)
{
sForce.Product2 objProd2 = (sForce.Product2)qrProdID.records[0];
sProdID = objProd2.Id.ToString();
}
string sQueryProduct = "Select ID From PricebookEntry where Product2Id = '" + sProdID + "'";
sForce.QueryResult qrProdEntry = binding.query(sQueryProduct);
if (qrProdEntry.size > 0)
{
sForce.PricebookEntry objProd = (sForce.PricebookEntry)qrProdEntry.records[0];
sPriceBookEntry = objProd.Id.ToString();
}
sForce.OpportunityLineItem oli = new sForce.OpportunityLineItem();
oli.ProductId = sProdID;
oli.Description = sDesc[x];
oli.OpportunityId = oppId;
oli.PricebookEntryId = sPriceBookEntry;
oli.Quantity = double.Parse(sQuantities[x]);
oli.QuantitySpecified = true;
oli.UnitPrice =double.Parse(sUSPrice[x]);
oli.UnitPriceSpecified = true;
sr = binding.create(new sForce.sObject[] {oli})[0];
I have an app that users can add products to a quote through a wizard that grabs prices from a database and then uploads them to SF.com. It isn't woring and I don't know what I am doing wrong. I am querying all the ids and information from the corresponding pricebook in SF.com. I am attaching my code. Any help would be greatly appreciated.
Thanks in advance.
Rhonda
string sQueryProductID = "Select ID From Pricebook2 where Name = '" + sPriceListName + "'";
sForce.QueryResult qrProd = binding.query(sQueryProductID);
string sPricebookID = string.Empty;
string sPriceBookEntry = string.Empty;
string sProdID = string.Empty;
if (qrProd.size > 0)
{
sForce.Pricebook2 objProd = (sForce.Pricebook2)qrProd.records[0];
sPricebookID = objProd.Id.ToString();
}
sForce.SaveResult sr = new sForce.SaveResult();
for (int x = 0; x < sUSPrice.Length; x++)
{
float dTotal = float.Parse(sQuantities[x].ToString()) * float.Parse(sUSPrice[x].ToString());
string sQueryProdID = "Select ID, Name From Product2 where ProductCode = '" + sProdCode[x] + "'";
sForce.QueryResult qrProdID = binding.query(sQueryProdID);
if (qrProdID.size > 0)
{
sForce.Product2 objProd2 = (sForce.Product2)qrProdID.records[0];
sProdID = objProd2.Id.ToString();
}
string sQueryProduct = "Select ID From PricebookEntry where Product2Id = '" + sProdID + "'";
sForce.QueryResult qrProdEntry = binding.query(sQueryProduct);
if (qrProdEntry.size > 0)
{
sForce.PricebookEntry objProd = (sForce.PricebookEntry)qrProdEntry.records[0];
sPriceBookEntry = objProd.Id.ToString();
}
sForce.OpportunityLineItem oli = new sForce.OpportunityLineItem();
oli.ProductId = sProdID;
oli.Description = sDesc[x];
oli.OpportunityId = oppId;
oli.PricebookEntryId = sPriceBookEntry;
oli.Quantity = double.Parse(sQuantities[x]);
oli.QuantitySpecified = true;
oli.UnitPrice =double.Parse(sUSPrice[x]);
oli.UnitPriceSpecified = true;
sr = binding.create(new sForce.sObject[] {oli})[0];
So the queries about are not always returning the correct one. I'm not sure how to distinguish one from the other.
Thanks.
Rhonda
Here is my code.
sForce.Opportunity oop = new sForce.Opportunity();
oop.Id = oppId;
oop.Local_Currency_Amount__c = dLocalTotal;
sr = binding.update(new sForce.sObject[] {oop})[0];
Thanks,
Rhonda