You need to sign in to do that
Don't have an account?
Saloni Khedkar
Trigger for comparing two field values from different object
I have a custom object which has a list of products, country field and checkbox- inactive.
Use case:
When I create an opportunity and add OpportunityLineItem, The line item should compare with the products field from the custom object.
Also, the Opportunity should look at Bill to country from the account attached and compare with the country field from the custom object.
And if the record matches and the "Inactive" checkbox from the custom object is true, then it should throw an error and not allow to save the opportunity.
For example,
Custom object:
Product: Pencil
Country: Mexico
Inavtive: True
Opportunity:
OpportunityLineItem: Pencil
Account - Bill to Country: Mexico
ERROR FLAG
Can this be achievable ? If so, can i receive some help on building the trigger ?
Thank you in advance.
Use case:
When I create an opportunity and add OpportunityLineItem, The line item should compare with the products field from the custom object.
Also, the Opportunity should look at Bill to country from the account attached and compare with the country field from the custom object.
And if the record matches and the "Inactive" checkbox from the custom object is true, then it should throw an error and not allow to save the opportunity.
For example,
Custom object:
Product: Pencil
Country: Mexico
Inavtive: True
Opportunity:
OpportunityLineItem: Pencil
Account - Bill to Country: Mexico
ERROR FLAG
Can this be achievable ? If so, can i receive some help on building the trigger ?
Thank you in advance.
We can write trigger to handle this scenario:
Please refer the below code:
am considering Product__c as Custom Object in below code
Thanks,
Maharajan.C
All Answers
We can write trigger to handle this scenario:
Please refer the below code:
am considering Product__c as Custom Object in below code
Thanks,
Maharajan.C
Thank you for helping me with the code. I did try this however, the error message did not apprear.
I do have a question on one of the lines:
for(Product__c prod : [Select Id,Inactive__c,Product__c,Country__c from Product__c])
here on this line, you have considered the object Product__c which being the custom object. However, you have used Product__c (same field in the select statement). I am little confused here.
Also, can you give a short description on flow ? I am new to coding.
Thanks a lot for all your help.
Looking forward.
I was able to execute the code.
If the Inactive value is FALSE, what would be the changes in the code?
Thank you so much for helping. I really appreciate the efforts.
Hi @Maharajan
The code workks great
I am trying to add another condition where it should fire the same error.
The condition now compares the Custome table with the product table.
I am trying to add another condition where if the product is not in the custom table but billing country is 'United states of America'
can this condition be accomodated in the same code?