You need to sign in to do that
Don't have an account?
Richard Rodriguez 1
Scheduled Apex Class to update record on a related object (attached via Lookup field)
I have a Custom (Managed) object called Individual Email Result (et4ae5__IndividualEmailResult__c) which contains a Lookup field to a Contact record (et4ae5__Contact__c) and I want to create a schedulable Apex Class to execute daily and update all of the related Contact records (with specific data from the fields of the Individual Email Result record) when it detects that a particular Individual Email Result checkbox (MC_ANY_Sent__c) equals 'true'.
Here is the code that I have so far:
Error: Compile Error: Variable does not exist: et4ae5__Contact__c at line 25 column 39
Line 25 is the 'update individualemailresults.et4ae5__Contact__c;' line.
I don't need to update the Individual Email Result record, as it isn't being changed, so I'm only looking to update the Contact record in the Lookup field (et4ae5__Contact__c), which is the default Salesforce Contact object, where all of the changes have been made.
Any ideas?
Here is the code that I have so far:
public class MCANYSent implements Schedulable, Database.Batchable<sObject>{ public void execute( SchedulableContext context ) { Database.executeBatch( this ); } public Database.QueryLocator start( Database.BatchableContext context ) { return Database.getQueryLocator ( 'SELECT Id, MC_ANY_Sent__c, et4ae5__DateSent__c, Name, et4ae5__FromName__c, et4ae5__FromAddress__c, et4ae5__Contact__c' + 'FROM et4ae5__IndividualEmailResult__c' + 'WHERE MC_ANY_Sent__c = true' ); } public void execute( Database.BatchableContext context, List<et4ae5__IndividualEmailResult__c> individualemailresults ) { for ( et4ae5__IndividualEmailResult__c ier : individualemailresults ) { ier.et4ae5__Contact__r.MC_Date_of_Last_ANY_Sent__c = ier.et4ae5__DateSent__c; ier.et4ae5__Contact__r.MC_Last_Email_Title__c = ier.Name; ier.et4ae5__Contact__r.MC_Last_Email_Sender__c = ier.et4ae5__FromName__c + '(' + ier.et4ae5__FromAddress__c + ')'; } update individualemailresults.et4ae5__Contact__c; } public void finish( Database.BatchableContext context ) { // nothing to do here } }However, when I try to save this, I am getting the following error;
Error: Compile Error: Variable does not exist: et4ae5__Contact__c at line 25 column 39
Line 25 is the 'update individualemailresults.et4ae5__Contact__c;' line.
I don't need to update the Individual Email Result record, as it isn't being changed, so I'm only looking to update the Contact record in the Lookup field (et4ae5__Contact__c), which is the default Salesforce Contact object, where all of the changes have been made.
Any ideas?
Please try like below. You dont need to wait for schedule run. If you just want to make sure that batch is working fine or not and this is ONLY AND ONLY FOR SANDBOX then you can simpliy use below script and run in developer console.
database.execute(new MCANYSent());
Let me know if still you are getting same error.
Thanks
Hemant
All Answers
Please try below code this will help you to achive whatever you try to achive as i am also from same recruitment industry so i know what you are trying to achive here.
Please let me know if you have any question or concern. You can directly contact me on my email id as well if need any other assistance in salesforce.
Thanks
Hemant
Email : sonihemant.jaipur@gmail.com
Error: Compile Error: IN operator must be used with an iterable expression at line 30 column 36
Line 30 is the line which reads "for(Contact oContact : [SELECT Id, Name, MC_Date_of_Last_ANY_Sent__c, MC_Last_Email_Title__c, MC_Last_Email_Sender__c FROM Contact Where Id IN : mapContactIdWiseEmailResult]){"
26/12/2019 2:00 PM Batch Apex Failed First error: unexpected token: MC_ANY_Sent__c
Any ideas?
Please try like below. You dont need to wait for schedule run. If you just want to make sure that batch is working fine or not and this is ONLY AND ONLY FOR SANDBOX then you can simpliy use below script and run in developer console.
database.execute(new MCANYSent());
Let me know if still you are getting same error.
Thanks
Hemant
Finally. I've been working on this for much longer than I've posted here.
I hope you realise that I'm now coming to you FIRST everytime I need help. :)
You're the best around. Nothing's ever gonna keep you down.