You need to sign in to do that
Don't have an account?
Jay Parikh 36
Hi -- Urgent Req apex trigger
Hi -- I have one xyz custom object and which is related with account object now i have req where on account object there will be 3 or 4 xyz object records and i want to create a new fields which is called first record and latest record checkbox which is based on created date of xyz records how will i achieve ??
for example :: on account there will be xyz object has a , b , c records based on creation date it will checked a record first records box true and same with the latest one ?????
for example :: on account there will be xyz object has a , b , c records based on creation date it will checked a record first records box true and same with the latest one ?????
finally !! We have nailed this one down!
Here is how,
1) Relationship: = Parent Object: Account and Child Object: Contact
2) Two Fields on parent (Account) object named: First Contact Id, and Latest Contact Id. (These are simple text fields and make them locked at page layout and hidden if you want)
3) Two formula fields on Child (Contact) object named First Contact, and Latest Contact. Both of them would be a formula fields with return type as checkbox.
Formulas for both fields:
For First_Contact__c field For Latest_Contact__c field 4) Now, have this following trigger on Child (Contact) object.
Trigger Code: See it in Action:
This trigger would work in all conditions such as When you insert the Contact, update it or delete it and even undelete it.
Hope this helps jay and if it solves the puzzle then please mark it as Best Answer so it can help others with the similar issue.
Thank You Sir!
All Answers
if this solve you problem plz maked as best answer . i didn't get a single one . if any issue i will again reply
I refactored your for loop . Please try the code and let me know if it works.
I am using this code but it is getting
CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, FirstLpCal: maximum trigger depth exceeded
this error
I am not sure this suggesation would still lead to recursion though...
First have a two fields on parent obeject named EarliestChildId, and LatestChildId.
Rememer this trigger below, which was updaitng Latest_Purchased__c& Early_Purchased__c on Account object..? Very similar way get the Id of those records into EarliestChildId, and LatestChildI fields. Now have a processbuilder on Account which would update only those records whoes IDS are on EarliestChildId, and LatestChildId field.
Again, this is just an idea sharing..
finally !! We have nailed this one down!
Here is how,
1) Relationship: = Parent Object: Account and Child Object: Contact
2) Two Fields on parent (Account) object named: First Contact Id, and Latest Contact Id. (These are simple text fields and make them locked at page layout and hidden if you want)
3) Two formula fields on Child (Contact) object named First Contact, and Latest Contact. Both of them would be a formula fields with return type as checkbox.
Formulas for both fields:
For First_Contact__c field For Latest_Contact__c field 4) Now, have this following trigger on Child (Contact) object.
Trigger Code: See it in Action:
This trigger would work in all conditions such as When you insert the Contact, update it or delete it and even undelete it.
Hope this helps jay and if it solves the puzzle then please mark it as Best Answer so it can help others with the similar issue.
Thank You Sir!