You need to sign in to do that
Don't have an account?
Nuno.Carvalho
Appex trigger , need help pls.
Hi guys,
Im trying to populate the account name lookup field on contracts with the right account , first of all i need to know if its possible to create this trigger because the account name lookup field is required and i can´t save it with any value as you guys know...
You can ask me what you need to know , i will try my best to help you, help me :)
Im trying to populate the account name lookup field on contracts with the right account , first of all i need to know if its possible to create this trigger because the account name lookup field is required and i can´t save it with any value as you guys know...
You can ask me what you need to know , i will try my best to help you, help me :)
If base on some logic you want to populate account name then you can write trigger as well.
If i'm right ,you are trying to populate account name from the contract's account object record associated with it right?
Create a custom field called AccountName on contract.
Trigger :
TriggerHandlerClass :
This trigger will execute as expected.
Also one easy solution to your question is
create a text formula field
eg :FormulaAccountNameField
assign Account.Name to that field on creation.
Let me know if this solution helps you.
Thanks and Regards,
Shiva RV
Where am i suppose to put the TriggerHandlerClass?
Sorry to bother you and thank you.
Nothing as such as calling it as bother.I will be happy if i made you to understand the code and help you resolve in your issue.Infact every developer love's it. By the way TriggerHandlerClass is an public apex class.This kind of concept of delegating the logic is best practise for trigger writing.
Let me know if you need further help.
Thanks and Regards,
Shiva RV
But do i put all the code in the same trigger?
Please create on apex class for TriggerHandlerClass (ContractTriggerHandler )
You can put all the code in the same trigger. But delegating is a better practise.
Also if you create a trigger like this trigger ContractTrigger on Contract (after update , before update)
then if you update the trigger in both before and after trigger ,then it will cause recursion error.
That is why the below code is used
if (Trigger.isInsert) {
//To avoid recursion
if (ContractTriggerHandler.runAI()) {
ContractTriggerHandler.processAfterInsert(Trigger.new);
}
}
else {
//To avoid recursion
if (ContractTriggerHandler.runAU()) {
ContractTriggerHandler.processAfterUpdate(Trigger.new);
}
}
}
else
you could have used
if (Trigger.isInsert) {
ContractTriggerHandler.processAfterInsert(Trigger.new); // or simply could have written all the code logics here.
}
Thanks and Regards,
Shiva RV