You need to sign in to do that
Don't have an account?
LALALA
Problem of how to assign value to field on Quote Line Item?
Hi, Everyone:)
I am new for salesforce, now I am doing about quote line Item.
my question is I am already get all value from another object which is I need assign those value to quote line Item, but I don't know how to assign value? I don't know what is pricebookEntryId and product2Id on quote line Item........can anybody give me some idea or sample?
Thanks you very much:)
I am new for salesforce, now I am doing about quote line Item.
my question is I am already get all value from another object which is I need assign those value to quote line Item, but I don't know how to assign value? I don't know what is pricebookEntryId and product2Id on quote line Item........can anybody give me some idea or sample?
Thanks you very much:)
You'll want to modify the query to to get the right Product2 and PricebookEntry. Then you'll pick the right one for each Quote to generate your QuoteLineItem. The logic to pick those is up to you and your organizational needs.
@pcon
Hi, this is my code.
trigger CreateQuoteLineItemFromQuote on Quote (after insert) {
List<QuoteLineItem> qList = new List<QuoteLineItem>();
Map<String, OrderLineItem__c> oliMap = new Map<String, OrderLineItem__c>();
//Get all OfwId from Quote
List<Id> ofwIdList = New List<Id>();
for(Quote q : trigger.new)
{
ofwIdList.add(q.QuoteOfw__c);
}
//Get all OrderLineItem from ofw
List<OrderFromWeb__c> ofwList = [select Id,ofwOrderLineItem__c,
ofwOrderLineItem__r.Price__c,
ofwOrderLineItem__r.ProductionName__c,
ofwOrderLineItem__r.Quantity__c,
ofwOrderLineItem__r.Total_Inc_tax__c,
ofwOrderLineItem__r.SKU__c
from OrderFromWeb__c
where id in:ofwIdList];
map<Id,OrderLineItem__c> ofwIdoliMap = new Map<Id,OrderLineItem__c>();
for(OrderFromWeb__c ofw: ofwList)
{
ofwIdoliMap.put(ofw.Id, ofw.ofwOrderLineItem__r);
}
//end
for (OrderLineItem__c oli: [select SKU__c, olitoquote__c from OrderLineItem__c where olitoquote__c in :trigger.newMap.keySet()])
{
oliMap.put(oli.olitoquote__c ,oli);
}
//Problem:
List<OrderLineItem__c> SKU = new List<OrderLineItem__c>([select id, sku__c from OrderLineItem__c where id in: ofwIdList]);
Map<Id, Product2> ProductMap = new Map<Id, Product2>(
[select Id from Product2 where ProductCode =:SKU]);
List<PricebookEntry> pkList = [
select Id from PricebookEntry
where Product2Id in: ProductMap.keySet()
];
for (Quote q : trigger.new)
{
QuoteLineItem qli = new QuoteLineItem();
qli.Product2Id = ProductMap.get(q.QuoteOfw__c).id;
qli.PricebookEntryId =
//qli.PricebookEntryId = ofwIdoliMap.get(q.quoteOfw__c).Product_Name__c;
qList.add(qli);
}
insert qList;
}
I already can get all data from orderLineItem, but how can match sku code with product code from product? and productName from product ..... some thing like that and then according these such as product2ID, pricebookEntryID to create Quote Line Item? thank you so much:)
NOTE: This code has not been tested and may contain typographical or logical errors.
@pcon
Hi, thank you for help.
I think I just need 'quntity' from OrderLineItem, So I add one code: qli.Quantity = Decimal.valueOf(ofwIdoliMap.get(q.QuoteOfw__c).Quantity__c);
but when I create order object it will show a problem:
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger CreateOppFromOrder caused an unexpected exception, contact your administrator: CreateOppFromOrder: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CreateQuoteFromOpp: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CreateQuoteLineItemFromQuote: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.CreateQuoteLineItemFromQuote: line 70, column 1: [] Trigger.CreateQuoteFromOpp: line 88, column 1: []: Trigger.CreateOppFromOrder: line 79, column 1
So, what should I do next?
thank you, and have a nice weekend:)
please help me to solved above last problems,,,thank you very much
and CreateQuoteFromOpp. Please use the "Add a code sample" button (icon <>) and make sure that the lines mentioned in the backtrace line up correctly. If they do not line up correctly, please make sure you tell me what lines they are now in your newly pasted code.
thank you so much:)
By adding some null checks you'll make sure that you don't get this exception.
Now I didn't get this exception,, but in QuoteLineItem still empty, didn't according my data of OrderLineItem to create Quotelineitem,,
olitoquote__c also is empty, do I need create a trigger for it?,,I dont know why. Thank you help alot,,,,, only this problem, please please help me,,,I think you are the best one in developer community:)
I find OrderLineItem__c oli = ofwIdoliMap.get(q.QuoteOfw__c); in oli is null, so quoteLineItem cannot according to oli to create quotelineitem,
because only here if I delete : If(oli==null){continue} it will showing exception, another two I delete this code didn't occur any problem
Now I set a trigger to get QuoteOfw__c, and already get value,,,but OrderLineItem still empty,,,,,don't know why
I find out, olitoquote__c is null too, this is lookup field in OrderLineItem, but only I create orders__c object, then quote created, then olitoquote__c can have value, because all value from quote,,,,so what can i do? can i set trigger for it? or I need change this lookup for them?