You need to sign in to do that
Don't have an account?
Depton
Contract = active then get the info in the account
Hi all,
I would like to populate an account custom field with "active contract” if at least one of the contracts related to this account is still active
I guess I can use a formula to look at the deadline of the contract and say "still active" or "ended"
But then I should look at all the account contracts and if one of the contracts is "still active", have the account custom field populated with "active contract"
Any ideas?
Thank you!!!:)
Sounds like you would need to use a trigger for this.
Create a trigger on the contract object, and then right the code to check for your criteria.
I think here I have called the Contracts to see those contracts that are still active......
The_Contract_is__c is a formula field that looks at the end date and works fine.
What would be the next step? and what if there is more than 1 active?
I do not mind to get the total of active contracts in the account......
How do i relate these Contracts with the Accounts now?
Well, it sounds like your checkbox on the account is if "at least one contract is still active."
Triggers are kind of confusing as there you can't assume that only one record is being processed. I'm not going to write all the code for you, but here are the steps you would need to take:
1. Loop through the Contracts that are causing the trigger to run. (Trigger.new)
2. Put all of their account id's in a list.
3. Query all Contracts where who's AccountId's are in the list from step 2, and that are still active. And put them in a map of AccountId to Contract
That might look like this:
4. Query all the appropriate Accounts.
5. Do a loop through the accounts:
5. Update the accounts.
I got here at the moment but I am getting an error with the SOQL:
Error: Compile Error: only aggregate expressions use field aliasing at line 14 column 16
am I on the right way? :))
Thanks!!
Change "Set<String>" to "List<Id>"
Also, put a comma between "Account" and "Name" in your query.