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

Batch apex causing an issue - "Constructor not defined: [BatchSISstagingObject].()"
Can anyone help me out in writing batch apex that will create or update records.I never worked on batch apex so struggling here I have two objects
1) SIS_Staging__c
2) Contact
Both objects are having same field Siscode__c, so on inserting records in SIS_Staging__c, I need to check if any contact records are having same Siscode__c or not, if yes then I need to update else I need to create Contact.
I tried below code but when I run batch apex in anonymous window then I am getting below error.
"Constructor not defined: [BatchSISstagingObject].()"
My code is below.
1) SIS_Staging__c
2) Contact
Both objects are having same field Siscode__c, so on inserting records in SIS_Staging__c, I need to check if any contact records are having same Siscode__c or not, if yes then I need to update else I need to create Contact.
I tried below code but when I run batch apex in anonymous window then I am getting below error.
"Constructor not defined: [BatchSISstagingObject].()"
My code is below.
global class BatchSISstagingObject implements Database.Batchable<sObject>{ List <SIS_Staging__c> mapSisobject = new List <SIS_Staging__c> (); List <Contact> contactlist1 = new List <Contact> (); global BatchSISstagingObject(List <SIS_Staging__c> sisobjectUpdate) { mapSisobject=sisobjectUpdate; } global Database.QueryLocator start(Database.BatchableContext BC) { return DataBase.getQueryLocator([SELECT Id, SIS_Student_ID__c FROM Contact ]); } global void execute(Database.BatchableContext BC , List <Contact> contactlist) { for (SIS_Staging__c acct : mapSisobject){ for (Contact con : contactList){ if (con.SIS_Student_ID__c == acct.Name){ contactlist1.add(new Contact( Id = con.Id, FirstName = acct.First_Name__c, LastName = acct.Last_Name__c )); } } } update contactlist1; } global void finish(Database.BatchableContext BC){ } }
Will this work?
All Answers
As you can see in your code you have parameterised constructor:
global BatchSISstagingObject(List <SIS_Staging__c> sisobjectUpdate) {
mapSisobject=sisobjectUpdate;
}
and you are not passing any parameter while running batch class.
This is reason you are getting error.
Either you need to pass List <SIS_Staging__c> of this object while running your batch class from anonymous window
List<SIS_Staging__c> stagingList;
BatchSISstagingObject objClass = new BatchSISstagingObject(stagingList);
Database.executeBatch(objClass);
------------------------------------
or you need to remove this parameterised constructor.
My requirement is I need to run this batch everyday at 11 PM, for all the records in staging object, I need to check whether contact exists or not, if exists I need to update contact else I need to create contact
On Staging object, I have a field "Name", and on Contact I have field "SIS_Student_ID__c", so when my batch runs, I need to check for each staging record I have matching contacts or not
Condition is "Stagingobject.Name = Contact.SIS_Student_ID__c", if it matches then I need to update the contact, if it does not match then I need to insert the contact.
Will this work?
Batch apex will look into existing Contacts for Contact.SIS_Student_ID__c == SIS_Staging__c.Name, if records matches then I need to update Contacts else I need to create a Contact.
now I have relationship between Contact and opportunity, ie lookup relationship, so for the contacts which I inserted or updated in above code, I need to see whether opportunity exists or not if exists then i need to update opportunity else I need to create opportunity
Map<ContactId,Opportunity> and one for Map<ContactId,StagingObject>.
Iterate over first Map,see whether it has opportunity or not if yes then update that oppty using using second Map because you will get related staging object using second map other wise create new oppty
I have a similar requirement. Can you please help
From the staging object, putting the data into 2 differnet objects having M-D relationship.Then checking for duplciates in Master object and if no duplciates create master and child record.