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
Randy RoseRandy Rose 

Collection and field definition

I'm interating through an sObject and Opportunity Id exists in the sObject.

I want to move some Opportunities to a collection and a custom field (e.g. campaign) and then when done iterating through the sObject do a bulk update for the Opportunity.

What type of collection should this be and how do I define the field in the collection (these opportunites already exits)?

Example

Lets call sObject campaigns
<list><map> Opps;
for (Campaigns  campaign:coCampaigns :) {
     Opps (collection?) = campaign.get('campaign__Opportunity__c')
     Opps.campaign (collection?) = campaign.get('campaign__c')
}

update Opps (collection);

 
pconpcon
Your psuedo code doesn't make much sense in the terms of Apex.  I will give you the following code that shows how to use lists in Apex, but if you want more clarification around how to use them in your specific instance, please include more information.  A diagram (or screenshot) of your object definition would be helpful.
 
// Create list
List<MyObject__c> objList = new List<MyObject__c>();

//Add to list
objList.add(new MyObject__c(Id = 'xxxx', Field__c = 'Update');

//Update the objects
update objList;