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

isset() function in trigger
I am creating a before insert trigger which pulls some parent fields into a new child record (Opportunity Fields into Quote). I am pulling two custom fields custom1__c and custom2__c. When creating the quote, the user can specify values that they would like for custom1__c and custom2__c. However if the trigger is automatically pulling data from the opportunity for these fields, any input that the user inputs for either of these fields will be overwritten by the trigger.
So, I need to add some sort of conditional statement which checks for user input before overwriting.
In PHP there is a function named isset() which checks to see if a variable is set. I'm wondering if there is something similar for APEX. I think I've seen something about it before, but I can't seem to get the syntax correct.
Here's what I would like to do:
trigger trgOppQuote on Quote (before insert) { ID ParentOppRecordId = Trigger.new[0].OpptyID__c; list<Opportunity> ParentRecord = [SELECT Field1__c, Field2__c FROM Opportunity WHERE id = :ParentOppRecordId ]; String Field1 = ParentRecord[0].Field1__c; String Field2 = ParentRecord[0].Field2__c; for (Quote q : Trigger.new) { if(!isset(Trigger.new[0].custom1__c)) q.custom1__c = Field1; if(!isset(Trigger.new[0].custom2__c)) q.custom2__c = Field2; } }
Thanks in advance for any help!
Instead of
Try
All Answers
It appears to have something to do with the fact that the variable being evaluated is not a string.
Instead of
Try
That's actually what I ended up doing and it works great, I just forgot to post it as the answer here.
Thanks for your response! :)