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

trriger and can't get data which is what i want
my question is:
I have one custom obj - orderFromweb : It include such ordernumber, paymentstatus, paymentmethod.......
I have another custom object - orders : It only include ordernumber, and company info from contact
I wanna through trigger to automatically create an opportunity but i meet some problems
this is my code:
List<Opportunity> newOpp = new List<Opportunity>();
Opportunity op = new Opportunity();
OrderFromWeb__c ofw = [select Id, OrderNumber__c, PaymentMethod__c from OrderFromWeb__c limit 1];
Account acc = new Account();
for(Orders__c Order : Trigger.new) {
if(ofw.PaymentMethod__c == 'PayPal Standard' && ofw.OrderNumber__c == order.Name) {
op.Name = date.Today()+'_W:'+ Order.Name;
}
else {
op.Name = date.Today()+'_:PO' + Order.Name;
}
-----question is: 'if' conditon doesn't work, because Paymentmethod is PayPal Standard, so should be running op.Name = date.Today()+'_W:'+ Order.Name; but it running code in 'else',,,,,I think because system doesn't know which ofw and orders to do the comparing, so is that i set Id have problems??? I don't know,
if(ofw.PaymentMethod__c == 'PayPal Standard' && ofw.OrderNumber__c == order.Name)
{
op.PO_Number__c = Order.Name;
}
else
{
op.PO_Number__c = ofw.PO_number__c
}
same as last one,, running 'else' not right one,,,,,why??
thank you anyone can help me
I have one custom obj - orderFromweb : It include such ordernumber, paymentstatus, paymentmethod.......
I have another custom object - orders : It only include ordernumber, and company info from contact
I wanna through trigger to automatically create an opportunity but i meet some problems
this is my code:
List<Opportunity> newOpp = new List<Opportunity>();
Opportunity op = new Opportunity();
OrderFromWeb__c ofw = [select Id, OrderNumber__c, PaymentMethod__c from OrderFromWeb__c limit 1];
Account acc = new Account();
for(Orders__c Order : Trigger.new) {
if(ofw.PaymentMethod__c == 'PayPal Standard' && ofw.OrderNumber__c == order.Name) {
op.Name = date.Today()+'_W:'+ Order.Name;
}
else {
op.Name = date.Today()+'_:PO' + Order.Name;
}
-----question is: 'if' conditon doesn't work, because Paymentmethod is PayPal Standard, so should be running op.Name = date.Today()+'_W:'+ Order.Name; but it running code in 'else',,,,,I think because system doesn't know which ofw and orders to do the comparing, so is that i set Id have problems??? I don't know,
if(ofw.PaymentMethod__c == 'PayPal Standard' && ofw.OrderNumber__c == order.Name)
{
op.PO_Number__c = Order.Name;
}
else
{
op.PO_Number__c = ofw.PO_number__c
}
same as last one,, running 'else' not right one,,,,,why??
thank you anyone can help me
NOTE: This code has not been tested and may contain typographical / logical errors.
All Answers
NOTE: This code has not been tested and may contain typographical / logical errors.
Thanks !! It works....
I have another question is I hace a look up field which name is Account Name, there has a relationship between account and opportunity,,,, and in opportunity have a field name is Account Name but no API, which means I cannot get Like op.AccountName,,,only have AccountId, So how can I get Account Name from Account to fill this field in opportunity??? thanks
or
Hi, only opportunity have AccountId, and Account and Contact have it. order and ofw doesn't has...
I tried op.AccountId = order.Contacts__r.AccountId still doesn't working.... don't know why
by the way, you are so nice,,,thank you help:)
Or do I need set up a look up relationship between Orders and Account? or Contacts? to make easier to get Account Name to fill in to opportunity??
Account acct = new Account(name = 'Test');
insert acct;
ID acctID = acct.Id;
opportunity opp = new opportunity(AccountId = acctID);
I know it works,,,but the element of Name is given by me---'Test',,,,,I want name can automatically grab data from account, so what kind of query i need write?
WoW!!! That is wonderful!!! You are so helpful!!
I need tell everyone what you answerd that was all amazing:)
Thank you so much.
Could i ask you aonther problems??
If I need according to this opportunity to create a quote and quote line item,,,what should I do? do I need create a new trigger for these or just write below this code of opportunity?
can you give me some Idea or some example of code??? thank you so much!!
I wanna say you are good guy and I also learn alot from you:)
please:)
Sorry for the delay. The holiday weekend has put me behind this week.