Ich möchte einen Kontodatensatz mit der Stapelklasse

erstellen. Benötigen Sie Ihre Hilfe, um einen Kontodatensatz mit der Stapelklasse zu erstellen.

global class batchClass implements Database.batchable<sObject>{ public String query; global Database.QueryLocator start(Database.BatchableContext BC){ return Database.getQueryLocator(Query); } global void execute(Database.BatchableContext info, List<Account> scope){ Account accsToUpdate=new Account(Name="ssa"); insert accsToUpdate; } global void finish(Database.BatchableContext info){ } } 

Ich habe so angefangen, ich weiß, dass es falsch ist. Bitte sagen Sie mir, was ich tun soll.

Kommentare

  • Sie Ich möchte ein Konto mit einer Stapelklasse erstellen. Also, was ist die Abfrage?
  • Ich bin müde von dem obigen Code ,,, Datensatz nicht erstellt ,, Ich möchte wissen, was das Problem dort ist
  • Wie führen Sie diese Stapelklasse aus? ?
  • von der Entwicklerkonsole
  • batchClass massupdate = new batchClass (); database.executeBatch (Bulkupdate);

Antwort

Wenn Sie keine Datensätze verwenden können, können Sie kann stattdessen eine iterable verwenden. Hier ist ein iterable-basiertes Beispiel:

public class CreateAccounts implements Database.Batchable<String> { public String[] start(Database.BatchableContext context) { return new String[] { "ssa" }; } public void execute(Database.BatchableContext context, String[] scope) { Account[] records = new Account[0]; for(String accountName: scope) { records.add(new Account(Name=accountName)); } insert records; } public void finish(Database.BatchableContext context) { } } 

Es liegt an Ihnen, zu bestimmen, wie die entsprechende Datenstruktur aussehen würde Der Hauptpunkt ist, dass eine Abfrage nicht die einzige Möglichkeit ist, einen stapelbaren Prozess zu starten.

Antwort

Überprüfen Sie Salesforce Dokument für die Ausführung der Stapelklasse Stapel-Apex

global class CreateAccountRecordsBatch implements Database.Batchable<sObject>{ global final String Query; global CreateAccountRecordsBatch(String q){ Query=q; } global Database.QueryLocator start(Database.BatchableContext BC){ return Database.getQueryLocator(query); } global void execute(Database.BatchableContext BC, List<Account> scope){ List<Account> accountList = new List<Account>(); for(Account acc : scope){ Account objA = new Account(Name = acc.Name); accountList.add(objA); } insert accountList; } global void finish(Database.BatchableContext BC){ } } //Execute Batch class from developer console // Query for 10 accounts String q = "SELECT Id, Name, Industry FROM Account LIMIT 10"; Id batchInstanceId = Database.executeBatch(new CreateAccountRecordsBatch(q), 5); 

Antwort

Nachfolgend finden Sie den Beispielcode, mit dem Sie Datensätze nach Stapelklassen erstellen können.

 global class InsertAccountContact implements Database.Batchable<sObject>{ global InsertAccountContact(){ // Batch Constructor } // Start Method global Database.QueryLocator start(Database.BatchableContext BC){ // Generate your string query on any object here with limit 10000 String Query = "select id,name from account limit 2"; //Query is Required on object which you want to run Batch return Database.getQueryLocator(Query); } // Execute Logic global void execute(Database.BatchableContext BC, List<sObject>objlist){ system.debug(">>>>>>execute>>>>>"+objlist); List<Account> acclist = new List<Account>(); list<Contact> conlist = new list<contact>(); for(Sobject obj: objlist){ Account acc = new account(); acc.name = "Account_CreatedByBatchClass"; acclist.add(acc); } insert acclist; for(Account acc : Acclist){ Contact con = new Contact(); con.lastname = "Contact_CreatedByBatchClass"; con.accountid = acc.id; conlist.add(con); } Insert conlist; } global void finish(Database.BatchableContext BC){ // Logic to be Executed at finish } } 

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.