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
Jeremy DeseezJeremy Deseez 

Put values of Opportunity List into a custom Object List

Hello everyone,

I've got a Classe named 'ManageUser". In this class, a method extract all opportunities for users.
I've got an other Class named 'ManageFAST". In this class, I need to copy the values of the Opportunity List.
And I don't know how to do it.
Here is my code.

ManageUser : 
public Boolean loadOpportunityList(Date quarter){
		String query = ManageOpp.OPP_QUERY;
		query += ' WHERE Owner.Id =: id';
		if(quarter != null){
			query += ' AND CloseDate >=: quarter';
		}
		List<Opportunity> oppList = Database.query(query);
		if(oppList.isEmpty()){
			return false;
		}
		myOppList = new List<ManageOpp>();
		for(Opportunity opp : oppList){
			myOppList.add(new ManageOpp(opp));
		}
		return true;
	}


	public Boolean loadOpportunityList(){
		return loadOpportunityList(null);
	}

public List<ManageOpp> getOpportunityList(){
		return this.myOppList;
	}

ManageFAST : 
public List<FAST__c> 						fast{get;set;}
	private List<FAST_OPP__c> 					fastOppList;
	private List<ManageOpp>						manageOppList{get;set;}
	private manageUser 							oppUser;
	public Date 								quarter;

public ManageFAST() {
		fast = new List<FAST__c>();
		oppUser = new ManageUser();
	}

	public void loadFAST(){
		List<FAST__c> fast = new List<FAST__c>();
		fast = [SELECT Id, Sales_ID__c, Forecast_Manager_ID__c, Quarter_Date__c, Commit_Manager__c, Transactionnal_Amount_Forecast_Exit__c, Transactionnal_Amount_Optimistic__c, Transactionnal_Amount_Pessimistic__c FROM FAST__c];
	}

public void initFASTOppList(){
		oppUser.load(UserInfo.getUserId());
		//quarter = Date.newInstance(1960, 2, 17);
		oppUser.loadOpportunityList(quarter);
		

		for(FAST_OPP__c fo : oppUser.getOpportunityList())
		{
		}
 





	}

Thanks
Alba RivasAlba Rivas
Hi,

Your oppUser.getOpportunityList() returns a List<ManageOpp>, not a List<FAST_OPP__c>, so, if you are going to iterate through it, you must do it in the next way:
 
for(ManageOpp manageOpportunity : oppUser.getOpportunityList())
{
...
}

Then I understand that your ManageOpp class should have a variable in which the opportunity that you have passed to its constructor is stored? Then you can do something like:

for(ManageOpp manageOpportunity : oppUser.getOpportunityList())
{
  FAST_OPP__c fastOpp = new FAST_OPP__c();
  fastOpp.Name = manageOpportunity.opp.Name;
  // ...Assign any fields that you need
  fastOppList.add(fastOpp);
}
Jeremy DeseezJeremy Deseez
Hi,

Ok I understand now. Thank you :)
I've a trouble with my List<ManageOpp>, I want to put the received values of this List into an other List, but it's not the same type of List. How I can do it ?

Regards
Alba RivasAlba Rivas
You have to go through your list and copy the values, field to field (or variable to variable), as in the for loop I've written above.
Jeremy DeseezJeremy Deseez
Thanks, I make it, it's work.
But now I'm stuck to compare two List. I have a List wich get the Opportunity of a User, and an other List with Opportunity in Object FAST_OPP.
 
public FAST__c 										fast{get;set;}
	public List<FAST_OPP__c> 							fastOppList{get;set;}
	private List<ManageOpp>								manageOppList{get;set;}
	private manageUser 									oppUser;
	public Date 										quarter;

	public ManageFAST() {
		fast = new FAST__c();
		fastOppList = new List<FAST_OPP__c>();
		oppUser = new ManageUser();
		oppUser.load(UserInfo.getUserId());
		quarter = Date.newInstance(2017, 2, 17);
		loadFAST();
		loadFASTOPP();
		initFASTOppList();
	}


	public void loadFAST(){
		List<FAST__c> fastList = new List<FAST__c>();
		fastList = [SELECT Id, Sales_ID__c, Forecast_Manager_ID__c, Quarter_Date__c, Commit_Manager__c, Transactionnal_Amount_Forecast_Exit__c, Transactionnal_Amount_Optimistic__c, Transactionnal_Amount_Pessimistic__c FROM FAST__c WHERE Sales_ID__c =: oppUser.getId() LIMIT 1];
		if(fastList.isEmpty()){
			fast = new FAST__c();
			fast.Sales_ID__c = oppUser.getId();
			fast.Transactionnal_Amount_Pessimistic__c = 0;
			fast.Transactionnal_Amount_Optimistic__c = 0;
			fast.Transactionnal_Amount_Forecast_Exit__c = 0;
			fast.Commit_Manager__c = 0;
			fast.Quarter_Date__c = quarter;


		} else {
			fast = fastList.get(0);
		}
	}


	public void loadFASTOPP(){
			fastOppList = [SELECT Id, Opp_ID__c, IsClosed__c, Type__c FROM FAST_OPP__c WHERE FAST_ID__c	=: fast.Id ];
	}

	public void initFASTOppList(){
		oppUser.loadOpportunityList(quarter);
		for(ManageOpp mo : oppUser.getOpportunityList())
		{
			if(!fastOppList.contains(mo.getOppId())){
				FAST_OPP__c fastOpp = new FAST_OPP__c();
				fastOpp.Opp_ID__c = mo.getOppId();
				fastOpp.IsClosed__c = mo.getIsClosed();
				fastOpp.Type__c = '';
				fastOppList.add(fastOpp);
			}

			System.debug('FIRST USER DEBUG BEFORE ADD TO FAST_OPP__c' + fastOppList);
			//upsert fastOppList;
			
		}

		System.debug('SECOND USER DEBUG AFTER ADD TO FAST_OPP__c' + fastOppList);


	}
Error : Method does not exist or incorrect signature: [List<FAST_Opp__c>].contains(Id)

Why I can't compare the Id ?

Regards
 
Alba RivasAlba Rivas
Convert it to a set: 

new Set<FAST_Opp__c>(fastOppList).contains(mo.getOppId());

Regards