You need to sign in to do that
Don't have an account?
LALALA
trigger update issue
I have 2 custom object which are OrderFromWeb and PayPal Record.
my question is when Order Number in PayPal Record == Order Number in OrderFromWeb, then update Payment Status from Pending to Paid in OrderFromWeb.
my code:
trigger UpdatePaymentStatus on PayPal_Record__c (after update) {
OrderFromWeb__c ofw;
for(PayPal_Record__c pr: Trigger.new )
{
if(ofw.OrderNumber__c ==pr.OrderNumber__c)
{
ofw.PaymentStatus__c='Paid';
}
}
}
my question is when Order Number in PayPal Record == Order Number in OrderFromWeb, then update Payment Status from Pending to Paid in OrderFromWeb.
my code:
trigger UpdatePaymentStatus on PayPal_Record__c (after update) {
OrderFromWeb__c ofw;
for(PayPal_Record__c pr: Trigger.new )
{
if(ofw.OrderNumber__c ==pr.OrderNumber__c)
{
ofw.PaymentStatus__c='Paid';
}
}
}
try with below code .
Try to change the exact api name of the order number in Pay_Pal_Record__c .
One thing is there any record with null value in OrderNumber__c ?
All Answers
Is there any relationship between these two objects,Please post the relationship name if possible .
Hi, what you mean by relationship? i just create two custom object, but should be no relationship between them,,,,,you mean the relationship like look up or master relation???
@Manoj Kumar jena
two object, data of one object is from a email, other one from another email, those two have the same custom field which is OrderNumber, so when Order Number from PayPal Record object == Order Number from OrderFromWeb, then update paymentStatus from pending to paid in OrderFromWeb Object.
Ok fine ,Please clarify my queries below .
1.You have two data sheet you need to upload you need to write trigger if order number match then you need to set the field PaymentStatus__c to paid on OrderFromWeb__c record .
2.Which record you will upload first is there any sequence ?Means PayPal_Record__c first or OrderFromWeb__c first ?
3.Is OrderNumber__c in each object is unque and read only ?why asking if some one will change then what will happen ?
1 is yes.
2 because salesforce record info into OrderFromWeb first, so should be upload OrderFromWeb first.
3 I set up as defalut, so should be a read only.
I think the trigger you need to write on insert evet not update .
If possible you can add filter in line number 3 if you want to check only those record of OrderFromWeb__c you have inserted today .
If you want to check with all record or only recently created record .
Thank you you example code, but still can't change Payment Status__c from Pending to Paid in OrderFromWeb.
seems like didn't trigge this trigger? but no any issue on code......i dont know why
04:45:04:129 EXCEPTION_THROWN [13]|System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []
FATAL_ERROR System.NullPointerException: Attempt to de-reference a null object
that is the problems from my debug
The exception is caused by not giving the Id of OrderFromWeb while updating the record. FYI : For performing update and delete DMLs on any record we must supply Id. Please try below mentioned code instead:
try with below code it will be better then iterating for loop inside for loop ,I think it will solve your problem .
still have problems,,,,,,when i debug will have 4 problems and in my OrderFromWeb object still didn't change my paymentstatus from pending to paid,
problems:
20:01:22:174 FATAL_ERROR System.NullPointerException: Attempt to de-reference a null object
20:01:22:000 FATAL_ERROR Trigger.PaymentStatusUpdate: line 5, column 1
20:01:22:174 FATAL_ERROR System.NullPointerException: Attempt to de-reference a null object
20:01:22:000 FATAL_ERROR Trigger.PaymentStatusUpdate: line 5, column 1
try with below code .
Try to change the exact api name of the order number in Pay_Pal_Record__c .
One thing is there any record with null value in OrderNumber__c ?
yes,,,have possible is nullvalue
I will say Thank you first, because you have good patient..
Then, I debug these code still the same problems...i don't know why....
this is my debug code:
PayPal_Record__c record = new PayPal_Record__c(OrderNumber__c = '2000157');
insert record;
Is this correct to excute this trigger?
In my opinion, I think your code already change the paymentStatus from pendding to paid in list,,,but in update this step have problems,,,,,it can't put these info to database, so finally still didn't change anything
@Manoj Kumar jena
Oh god!!!! It works!!!! Thank you very much....
you know it is my problems........In my Object of OrderFromWeb have one didn't have ordernumber which mean in this field it is null!!! so that's why can't update....