You need to sign in to do that
Don't have an account?
Darkangel8
batch class to update lookup relationship fields with latest values get displayed
Want to create a batch class on contact object having lookup with account. When contact mobile number get updated then latest mobile umber will get reflected in account object. Please help to code this.
Hi Dhanashree,
Please find the code. I hope it will get you job done(Just Change the fields as per your need)
A trigger which will be fired whenever a contact is updated/Inserted and update the account and a batch you can either schedule or trigger on an ad-hoc request.
Note :- I have implemented custom logic where the batch will pick only those records which are updated after the last batch run date/Time (after the first time). This will ensure that redundant records are not processed.
For this logic to work you need to create a custom setting which will have a field to store the last run batch date/time.
Please mark this as best answer if it solves your issue.
Trigger :- updateCallOnAcctTrigger
Batch Class :- updateAccountNoBatch
All Answers
Have you formulated any approach or have an idea how to proceed with this ?
If not we can help but our suggestion would be to start yourself first and if you stumble upon any issue we will help you out.
Just a question, as multiple contacts might be associated with an account, how should one select which no to update on the Account from Contact.
Actually i am learning Apex so I don't have idea. I have created a custom object whose lookup with Account Object. I want to create a batch class where I can update mobile field value that will get reflected to Account object field. But condition is Only latest updated mobile number will get reflected on Account object.
Hi Dhanashree,
Please find the code. I hope it will get you job done(Just Change the fields as per your need)
A trigger which will be fired whenever a contact is updated/Inserted and update the account and a batch you can either schedule or trigger on an ad-hoc request.
Note :- I have implemented custom logic where the batch will pick only those records which are updated after the last batch run date/Time (after the first time). This will ensure that redundant records are not processed.
For this logic to work you need to create a custom setting which will have a field to store the last run batch date/time.
Please mark this as best answer if it solves your issue.
Trigger :- updateCallOnAcctTrigger
Batch Class :- updateAccountNoBatch
Glad i could help you out. Please mark this as a best answer so that others could get help as well from this .
Please modify the below lines in your batch class (Sorry i made some mistakes) :-
Replace
if(ct.Phone != null) with if(ct.Phone != null && (!mapAccountsToProcess.containsKey(ct.AccountId)))
Remove all the "limit 1" clause from all the queries in the class and make sure the queries end with lastmodifieddate desc.
Hope this helps.
Hi kd Komal,
Want to create a batch class on the custom object (enquiry__c) having lookup with the account. When enqiry__c lookup field(City__c and State__c) get matched with same field in Account object then Account name will get reflected in dealer(lookup field with account object) in enquiry__c object. Please help to code this.