2
votes

I just want to ask if any developer knows how to save a record in the field; and then retrieve it through visual force.

Scenario: I have some fields in a custom object that have been updated in the apex class i.e. if I System.Debug those fields it shows me some values. To be specific, these values are different for each account.

Problem: The problem is that I can access the values of the fields in that class; but when I write a SOQL in workbench or force.com explorer to view the values of fields in the custom object through particular account id, it does not show me the results. So I want to be able to save the results in the fields and then access them using SOQL. The whole point of saving them is so that I can query using visual force and display them.

What I have tried: I have tried creating a new instance of the custom object and then using the put method to save the values but that did not work.

Abc__c abc = new Abc__c();
abc.account_id__c = Account.id;

abc.Number = 20; 
System.Debug(abc);

This prints out 20. But when I go to the workbench, it does not! Any kinds of help is really appreciated.

2

2 Answers

8
votes

You need to call update so that the row is sent back to the database, e.g.

Abc__c abc = new Abc__c(Id='someExistingRecordId');
abc.account_id__c = Account.id;
abc.Number = 20; 
update abc;
0
votes

Except before trigger event, you need to do the DML action to reflect the changes in database. For before trigger you don't need to do the DML, just you can assign the value to specific field, before trigger will update the value in database