You need to sign in to do that
Don't have an account?
Chris - ARI
Expression cannot be a Statement
Im sure this is a simple mistake as I do not have much coding experience. It says my error is on line 5.
I am trying to update the field GUI on the account if it is blank. I want it to update with the Candian GUI if there is an accout populated in the related field "Canada_Account".
I am trying to update the field GUI on the account if it is blank. I want it to update with the Candian GUI if there is an accout populated in the related field "Canada_Account".
trigger Update_GUI on Account (before insert, before update) { for(Account acc : Trigger.new){ if(acc.GUI__c = null){ if(acc.Canada_Account__c != null){ acc.GUI__c == acc.Canada_Account__r.GUI__c; } } } }
Let us know if this will help you
All Answers
Let us know if this will help you
Please try to update your code like below Let us know if this will help you
U should make a query to fetch the GUI__c field on the Canada_Account__c.
should be .... from account where id in :setaccid.....
"AND operator can only be applied to Boolean expressions:
Please update your code like below
Please let us know if this will help you
Thanks
Amit Chaudhary
Sorry to be a bother, but now I have 2 more questions.
1. I believe I need this code to fire after update and after insert to ensure the GUI field always populates. Simply changing up the first line of the code doesn't work. How do I accomplish this?
2. I want to add more countries. UK, Mexico, Gemany etc... I want the code the first check Canada and if there is nothing in the field to go to the UK etc.... How do I scale this code?
Before triggers will do this for you if u change any fields in trigger.new.
You can implement the trigger framwork like below
Please create one handler class like below
Update your Trigger like below Please check below post for more information
1) http://amitsalesforce.blogspot.in/2015/06/trigger-best-practices-sample-trigger.html
NOTE:- code is not tested may be you will get some syntex error
Let us know if this will help you
Thanks
Amit Chaudhary
When creating a new account it throws this error:
Review all error messages below to correct your data.
Apex trigger Update_GUI caused an unexpected exception, contact your administrator: Update_GUI: execution of AfterInsert caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Account.GUI__c: Class.AccountTriggerHandler.OnAfterInsert: line 21, column 1
List<Account> lstAccount = [select id,Canada_Account__r.GUI__c, UK_Account__r.GUI__c fromaccount where id in :setAccId ];
Let us know if this will help you