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

Unable to update records using batch Apex
Here i am trying to append "Updated" to all of my accounts but no luck.
public class INFSimpleBatchExp implements Database.Batchable<sobject> {
public Database.QueryLocator start(database.BatchableContext bc )
{
String query = 'select id, name from Account';
return Database.getQueryLocator(query);
}
public void execute (Database.BatchableContext bc, List<Account> scope )
{
for(Account acc : scope)
{
acc.name = acc.name + 'updated';
}
update scope;
}
public void finish(Database.BatchableContext bc)
{
}
}
----------------------------------------------------------------------------------------------------------------------
I am using following statemets in Developer console
INFSimpleBatchExp inF = new INFSimpleBatchExp();
Database.executeBatch(inF, 200);
Anyone kindly let me know where it went wrong?
wwwwwwThanks,
Prakki
public class INFSimpleBatchExp implements Database.Batchable<sobject> {
public Database.QueryLocator start(database.BatchableContext bc )
{
String query = 'select id, name from Account';
return Database.getQueryLocator(query);
}
public void execute (Database.BatchableContext bc, List<Account> scope )
{
for(Account acc : scope)
{
acc.name = acc.name + 'updated';
}
update scope;
}
public void finish(Database.BatchableContext bc)
{
}
}
----------------------------------------------------------------------------------------------------------------------
I am using following statemets in Developer console
INFSimpleBatchExp inF = new INFSimpleBatchExp();
Database.executeBatch(inF, 200);
Anyone kindly let me know where it went wrong?
wwwwwwThanks,
Prakki
All Answers
Batch class should be global instead of public.You need to change class and method to global
This code is working fine in my org
If this answer helps you,please mark it as best answer to help others :)
Thanks
------------------------------------------------------------------------------------------------------------
global class INFSimpleBatchExp implements Database.Batchable<sobject> {
global Database.QueryLocator start(database.BatchableContext bc )
{
String query = 'select id, name from Account';
return Database.getQueryLocator(query);
}
global void execute (Database.BatchableContext bc, List<Account> scope )
{
for(Account a : scope)
{
a.name = a.name +'updated';
}
update scope;
}
global void finish(Database.BatchableContext bc)
{
}
}
Id batjobId = Database.execute(new INFSimpleBatchExp(), 200);
Could you check debug log what error you are getting So i can help you out. this code is working fine in my org.
Regards,
Prakash
global class INFSimpleBatchExp implements Database.Batchable<sobject> {
global Database.QueryLocator start(database.BatchableContext bc )
{
String query = 'select id, Primary_Email_amgn__c from Account';
return Database.getQueryLocator(query);
}
global void execute (Database.BatchableContext bc, List<Account> scope )
{
for(Account acc : scope)
{
acc.Primary_Email_amgn__c='';
}
update scope;
}
global void finish(Database.BatchableContext bc)
{
AsyncApexJob a = [Select Id, Status,ExtendedStatus,NumberOfErrors, JobItemsProcessed,TotalJobItems, CreatedBy.Email from AsyncApexJob where Id =:BC.getJobId()];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'arpitguptacom1310@gmail.com'};
mail.setToAddresses(toAddresses);
mail.setSubject('Match Merge Batch ' + a.Status);
mail.setPlainTextBody('records processed ' + a.TotalJobItems + 'with '+ a.NumberOfErrors + ' failures.');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
Getting below error :
SUCCESS: (
{
errorCode = "NOT_FOUND";
message = "The requested resource does not exist";
}
)
While upating the firstName in my salesforce
let postBody = ["FirstName": "Express Logistics"]
let data: Data? = try? JSONSerialization.data(withJSONObject: postBody, options: [])
var urlRequest = NSMutableURLRequest()
if let aString = URL(string: "instance_url/services/data/v20.0/sobjects/Lead/Account") {
urlRequest = NSMutableURLRequest(url: aString)
}
//create the Method "POST"
urlRequest.httpMethod = "PATCH"
urlRequest.setValue("application/json;charset=UTF-8", forHTTPHeaderField: "content-type")
urlRequest.setValue("Bearer access_token", forHTTPHeaderField: "Authorization")
urlRequest.httpBody = data
DB URL given as :- "instance_url/services/data/v20.0/sobjects/Lead/Account"
working in ios swift
Thanks.