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

Get field update (on parent object) with last record (from a child object)
Hi, I am absolutely not an Apex expert, and my issue cannot be resolved by the Salesfoce Standard. So if you could help me, it would be great!
I would like to get field update (for example "Contract_Type__c") on parent standard object "Contact" with a field ("Contract_Type_Bis") from the last record on a child custom object "Contract". The link between these 2 objects is only a look-up relationship. I can't use the master detaill relationship because i already used it 2 times with Contacts object.
I tried to use an Apex code from an another threat here : http://salesforce.stackexchange.com/a/23566
But it wasn't worked, and I didnt understand very well the logic.
Thanks again!
In the below example I'm capturing field from the contact and update to the Account Object, so whenever new contact is created for the Account then we will update the Account record with the latest contact record value. You just want to channe the objects and fields to work for your scenarios, the procedure remains same.
1. Go to Setup->Create->Workflow & ApprovalProcess->Processbuilder
2. Click New and set the Name of your Process
3. Select your child object under the section "Choose Object and Specify When to Start the Process"
4. Select the "Only When record is Created Option"
3. Then under the criteria you can set the condition if you want to excute only for certain records[ In the below example I'm checking for the condition Parent record relation ship is not null]
5. Then in the immediate action select 'Update Records' under the object chose the object in which you want to update.
6. Then in the 'Set Object' Variable select the child field value which you want to copy and map it to the Parent object field.
7. Then Activate to Process.
Thanks,
Karanraj
All Answers
You can use a trigger for this..query the parent and then in inner query you can query the last insert record by mentioning limit 1 desc creadteddate..
selecte id (select Id from contartc orderby createddate desc limit 1)from Contact where Id In :contactId
Please try with this and let me know if it helps you..
thanks,
Sandeep
In the below example I'm capturing field from the contact and update to the Account Object, so whenever new contact is created for the Account then we will update the Account record with the latest contact record value. You just want to channe the objects and fields to work for your scenarios, the procedure remains same.
1. Go to Setup->Create->Workflow & ApprovalProcess->Processbuilder
2. Click New and set the Name of your Process
3. Select your child object under the section "Choose Object and Specify When to Start the Process"
4. Select the "Only When record is Created Option"
3. Then under the criteria you can set the condition if you want to excute only for certain records[ In the below example I'm checking for the condition Parent record relation ship is not null]
5. Then in the immediate action select 'Update Records' under the object chose the object in which you want to update.
6. Then in the 'Set Object' Variable select the child field value which you want to copy and map it to the Parent object field.
7. Then Activate to Process.
Thanks,
Karanraj
I tried to execute your code Sandeep but it wasn't a success..
Karanraj, like you I though it was possible to make that with Process Builder. But when i want to select the field required to update in the Parent object, i don't find it in tthe picklist... I can only choose standard fields i guess...
Make sure that you have choose correct object in the update records process.
I have somewhat similar problem, also related to the Contract object and I am hoping to be able to do it with Process Builder, but not sure how, and I get stuck midway using the example above.
In my case: When a contract is created, a "Primary" checkbox field is auto-checked on.
When I clone a contract, the clone gets the "Primary" checkbox automatically checked. I need to find a way to uncheck the "Primary" checkbox of the clone source.
(Example: I have contract ID000130. I create a clone contract ID000147, the "Contract Cloned" field in this clone contains ID000130. Now ID000147 is Primary, how can I uncheck the "Primary" box for ID000130)?
(For information: I have a lookup relationship from Contract to Contract and everytime a Contract is cloned, I have a field "Contract_Cloned_c" which is populated with the CloneSourceID().)