function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Madhu3006Madhu3006 

Regarding the scheduler class

Hi Everone,

I wrote this code for scheduler class ,but when i look in below path
 Setup->Monitoring->Scheduled Jobs i am not able be to see my class .


global class Schecudlertestaccount22  implements Schedulable  {
    Schecudlertestaccount22  c = new Schecudlertestaccount22();
    global void execute(SchedulableContext ctx) {
        
        String sch = '0 6 * * * ? ';
        
        system.schedule('Schecudlertestaccount', sch, c);
        
        Account acct= new Account();
        //acct.Type
        acct=[SELECT id, Type from Account where Type='Other'];
        acct.Site='www.abc.com';
        update acct;
    }

}

Can any one pl suggets on this


Regards
madhu

Best Answer chosen by Admin (Salesforce Developers) 
Naidu PothiniNaidu Pothini
acct=[SELECT id, Type from Account where Type='Other']; // will return more than one Account record

 use something like this instead

 

acct=[SELECT id, Type from Account where Type='Other' LIMIT 1];

 

All Answers

venkateshyadav1243venkateshyadav1243

Hi Madhu

 

try in developer console

 

 

copy this and excute in developer console

 

 Schecudlertestaccount22  c = new Schecudlertestaccount22();
        String sch = '0 6 * * * ? ';
        system.schedule('Schecudlertestaccount', sch, c);

 

 

regards

venkatesh.

Madhu3006Madhu3006

caused by: System.QueryException: List has more than 1 row for assignment to SObject

when the below code excutes i am getting the error

 

global class Schecudlertestaccount22 implements Schedulable {
//Schecudlertestaccount22 c = new Schecudlertestaccount22();
global void execute(SchedulableContext ctx) {


Account acct = new Account();
acct=[SELECT id, Type from Account where Type='Other'];
acct.Site='www.abc.com';
update acct;
system.debug(acct);
}

}

 

Regards

Madhu

venkateshyadav1243venkateshyadav1243

Hi Madhu

 

i think you are getting these error becuase your condition is not meeting condition

means this

 

acct=[SELECT id, Type from Account where Type='Other'];

 

please check in account is there any record type=other

 

and once check in the debug log what you are getting the update records.

 

Regards

venkatesh.

Naidu PothiniNaidu Pothini
acct=[SELECT id, Type from Account where Type='Other']; // will return more than one Account record

 use something like this instead

 

acct=[SELECT id, Type from Account where Type='Other' LIMIT 1];

 

This was selected as the best answer
Madhu3006Madhu3006

Problem: Initial term of field expression must be a concrete SObject: LIST<Account>

Suppose if they are 10 records and i need to update i created a list and But i  am getting the error below

global class Schecudlertestaccount22 implements Schedulable {
//Schecudlertestaccount22 c = new Schecudlertestaccount22();
List<Account> acct = new List<Account>();
Set<Id> ids=new Set<Id>();
global void execute(SchedulableContext ctx) {
acct=[SELECT Id from Account where Type='Other' limit 1];
for(integer i=0; i <acct.size();i++)
{
for(Account acctt:acct)

{
ids.add(acct.Id);
//acctt.Site = 'www.abc.com';
}

}
update acct;
}
}

 

How i need to write that code can some one pl help me out 

 

Naidu PothiniNaidu Pothini
global class Schecudlertestaccount22 implements Schedulable
{
	List<Account> accts = new List<Account>();

	global void execute(SchedulableContext ctx) 
	{
		accts = [SELECT Id from Account where Type='Other'];

		for(Account acc : accts)
		{
			acc.Site = 'www.abc.com';
		}

		update accts;
	}
}

 is this what you are looking for?