Activity Forums Salesforce® Discussions First error: sObject type 'sObject' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name.

  • First error: sObject type 'sObject' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name.

    Posted by sushant on December 6, 2016 at 1:03 pm

    Hi All

    I am getting this error while using sObject type list in Batch Class

    global class TestBatch implements
    Database.Batchable<sObject>, Database.Stateful {
    list<id> useridlist = new list<id>();
    global TestBatch(list<id> idforlist){

    useridlist=idforlist;
    }

    global Database.QueryLocator start(Database.BatchableContext bc) {
    return Database.getQueryLocator('SELECT id,name FROM sObject WHERE id IN :useridlist' );
    }

    global void execute(Database.BatchableContext bc, List<sObject> scope){

    for(sObject a: scope)
    {
    a.put( 'name','Algo');
    }
    update scope;
    }

    global void finish(Database.BatchableContext bc){

    }

    }

    please give suggestions.

    Vikas Kumar replied 7 years, 11 months ago 2 Members · 2 Replies
  • 2 Replies
  • Vikas Kumar

    Member
    December 6, 2016 at 7:15 pm

    Hi Sushant

    This is the modified version of your code it works fine . you need to change sObject to Sobject ur code will work fine

    global class TestBatch implements
    Database.Batchable<Sobject>, Database.Stateful {
    list<id> useridlist = new list<id>();
    global TestBatch(list<id> idforlist){

    useridlist=idforlist;
    }

    global Database.QueryLocator start(Database.BatchableContext bc) {
    return Database.getQueryLocator('SELECT id,name FROM Sobject WHERE id IN :useridlist' );
    }

    global void execute(Database.BatchableContext bc, List<Sobject> scope){

    for(Sobject a: scope)
    {
    a.put( 'name','Algo');
    }
    update scope;
    }

    global void finish(Database.BatchableContext bc){

    }

    }

    Hope it Helps

  • Vikas Kumar

    Member
    December 7, 2016 at 6:49 pm

    hi sushant

    there will be some correction in your code you need to specify your sobject  because it create some ambiguity becz

    a.name can be either auto number or string so its create a situation which throws error. so if you wanted to update some fields of your object using batch you can call another batch class in ur class.

    you can do something like this

    global class SearchAndReplace implements Database.Batchable<sobject>{
    global String Query;
    global List<id>allObjIds ;
    global SearchAndReplace(List<id>allObjectIds){
    allObjIds=allObjectIds;
    }
    global Database.QueryLocator Start(Database.BatchableContext BC){
    query='SELECT Id,Name FROM Account WHERE Id in:allObjIds';
    return Database.getQueryLocator(query);
    }
    global void execute (Database.BatchableContext BC,List<Account>scope){
    for(Account obj:scope){
    obj.Name='Algoworks';
    }
    update scope;
    }
    global void finish (Database.BatchableContext BC){
    SearchAndReplaceContact objc = new SearchAndReplaceContact(allObjIds);

    }

    another class get called inside above class

    global class SearchAndReplaceContact implements Database.Batchable<sobject> {
    global String Query;
    global List<id>allObjIds ;
    global SearchAndReplaceContact(List<id>allObjectIds){
    allObjIds=allObjectIds;
    }
    global Database.QueryLocator Start(Database.BatchableContext BC){
    query='SELECT Id,Name FROM Contact WHERE Id in:allObjIds';
    return Database.getQueryLocator(query);
    }
    global void execute (Database.BatchableContext BC,List<Contact>scope){
    for(Contact obj:scope){
    obj.lastname='Algoworks';
    }
    update scope;
    }
    global void finish (Database.BatchableContext BC){
    }

    }

     

     

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos