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
sandeep3385sandeep3385 

Updating a column of a table

can anyone tell me how to update a column of  a table through apex classes?

 

I have created a method for updating and i used update(list type variable) command. It is throwing a run time error like "Illegal view ID update. The ID must begin with / "

 

what does this mean? please suggest...

Best Answer chosen by Admin (Salesforce Developers) 
parkerAPTparkerAPT

Make sure that you properly bind your action with something in your controller,

 

action="{!theColumnRefreshAction}"

 

rather than

 

action="theColumnRefreshAction

 

 

See the followingthread for more details:

Possible Solution

All Answers

aalbertaalbert
Can you please provide the code snippet that is causing the error?
sandeep3385sandeep3385

Here is the method that i ve included in an apex class:

 

public PageReference updatecheck() {
 

    list<Product_PT__c> updates = new list<Product_PT__c>();
  list<Product_PT__c> values;
 
  integer k = 0;
 
  values = [select  id, check__c from Product_PT__c where check__c = TRUE  limit 50];
  Integer j = [select count() from Product_PT__c where check__c = TRUE];
 
  for(k =0; k<j; k++){
 
values[k].check__c = FALSE;
updates.add(values[k]);
    } 
  update updates;
  return null;
  }

 

aalbertaalbert

Well, the first issue I see is that you are only querying 50 Product_PT__c records in the first SOQL query and then your FOR loop will iterate through potentially more than 50 recors since there is no LIMIT clause on the 2 query (select count()...)

 

So my first question is:  What does j equal in your scenario?

And why not change the for loop to read:

   for(k =0; k<values.size(); k++){

 

 

sandeep3385sandeep3385

The count that i have right now is well below the limit. I am not worrying about that. The fact is I got the error before i put the limit clause.

 

what i think might be the reason is there is an id that is associated with every record. so i have to retrieve those ids and update the same while updating another column of the table. Do u have any idea about how to retrive the record ids in apex method. In javascript we can use GETRECORDIDS method. In apex coding, i dont know.

parkerAPTparkerAPT

Make sure that you properly bind your action with something in your controller,

 

action="{!theColumnRefreshAction}"

 

rather than

 

action="theColumnRefreshAction

 

 

See the followingthread for more details:

Possible Solution

This was selected as the best answer
sandeep3385sandeep3385
Hey Thanks a lot...Its working!!!