You need to sign in to do that
Don't have an account?
arasu
I have the following apex code that throws this error:
Inline query has too many rows for direct assignment, use FOR LOOP
Inline query has too many rows for direct assignment, use FOR LOOP
Hi,
I have the following apex code that throws this error:
Inline query has too many rows for direct assignment, use FOR LOOP
Code:
WebService static Integer processRecordsToInsert(List<ID> pupcid,List<ID> palliid,String preason) { Integer success=0; Integer failure=1; try{ List<Partner_Relationship__c> insertedPR = new List<Partner_Relationship__c>(); List<Account> insertedAcc = new List<Account>(); Savepoint sp_insert = Database.setSavepoint(); Partner_Relationship__c prd = new Partner_Relationship__c(); //Get the list of Card UPCs that are not in Partner Relationship object List <Card_UPC__c> lupc=[Select id from Card_Upc__c where id NOT IN :pupcid]; //loop thru each UPC, only 2 UPCs therefore loops only 2 times for(Card_UPC__c upcdata:[Select Id from Card_Upc__c where Id IN :pupcid ] ){ //loop thru each Alliance, only 2 Alliances therefore loops only 2 times for(Account accdata:[Select id from Account where Id IN :palliid] ){ prd = new Partner_Relationship__c(Card_Upc__c=upcdata.Id,Alliance_Account__c=accdata.Id,Status__c='Card Partner Discontinued'); insertedPR.add(prd); } } Database.SaveResult[] lsr = Database.insert(insertedPR,true); return success; }catch (DmlException e) { throw e; return failure; }catch (Exception e) { throw e; return failure; } }
Appreciate all your valuable feedbacks on this.
Thanks
Thanks
For example:
for (Account ac : account) {
ac.Name = 'Acme1';
}
What is the error message? What are you attempting to do? Are you writing this code in a Trigger?
Firstly, remove "for update" -- this isn't a database.
After you modify a value, use the update command to save the change.
global class B03WebService {
WebService static boolean updateOpportunityLineItem(){
pportunityLineItem[] opportunityList = [select Id,s__mitosakuban__c from
OpportunityLineItem where s__mitosakuban__c =:mitoSakubanBef for update];
try{
Database.SaveResult[] SR = database.update(opportunityList);
for(Database.SaveResult lsr:SR){
if(!lsr.isSuccess()){
updateFlg = false;
break;
}
}
}catch (System.DmlException e) {
throw e;
}catch (System.Exception e) {
throw e;
}
return updateFlg;
}
}
Message Edited by jrotenstein on 06-05-2008 04:37 PM
pportunityLineItem[] opportunityList = [select Id,s__mitosakuban__c from
OpportunityLineItem where s__mitosakuban__c =:mitoSakubanBef for update];
try{
for (OpportunityLineItem opportunity : opportunityList) {
opportunity.s__mitosakuban__c = 'fff';
opportunity.s__delete_flg__c = true;
for(Database.SaveResult lsr:SR){
break;
}
}
}catch (System.DmlException e) {
}catch (System.Exception e) {
}
return updateFlg;
}
}
If so, does it mean that whenever you call the webservice, you want to update all Opportunities where s__mitosakuban__c =:mitoSakubanBef and set s__mitosakuban__c = 'fff' and s__delete_flg__c = true ?
Then your problem might be that the SELECT is returning too many rows. Can you think of a way to return less rows? Perhaps change your query to:
[select Id, s__mitosakuban__c from OpportunityLineItem where s__mitosakuban__c =:mitoSakubanBef and (s__mitosakuban__c <> 'fff' or s_deleted_flg__c = false)]
That way, it will only return rows that need updating. That might keep it under 1000 rows.
1
pportunityLineItem[] opportunityList = [select Id,s__mitosakuban__c from
OpportunityLineItem where s__mitosakuban__c =:mitoSakubanBef for update];
OpportunityLineItem where s__mitosakuban__c =:mitoSakubanBef for update];
updateFlg = false;
break;
}