You need to sign in to do that
Don't have an account?

Change the value of a field using SOQL
Hello
I wonder how can I pass all my opportunities to the value of one field to another.
I have the Amount field and want to pass its value to a field to type Currency.
Is that possible? If so could show me how?
Thanks
You don't use SOQL to update records in Salesforce. You use SOQL to query records.
You use DML statements in Apex to update the records.
Apex Code (This should work, but I'm freetyping it):
String searchNames = 'test name';
List<Opportunity> oppties = [Select Id, Amount, CloseDate, StageName from Opportunity where Name =: searchNames];
List<Opportuinty> copiedOppties = new List<Opportunity>();
for(Opportunity oppty : oppties)
{
Opportunity newOppty = new Opportunity();
newOppty.Name = oppty.Name + ' COPIED';
newOppty.Amount = oppty.Amount; // Copy the Value from one field to another
newOppty.CloseDate = oppty.CloseDate;
newOppty.StageName = oppty.StageName;
copiedOppties.add(newOppty); // Add the record to the list of new opportunities
}
if(copiedOppties.size() > 0)
insert copiedOppties; // Insert the new "copied" opportunities