We have created one vf page in custom object. From that, vf page we need to select an opportunity name from hardcoded picklist values and need to select the existing account where we need to create an opportunity, Also I have a input field in vf page. In this input field I need to populate the selected account field called salesperson. After selecting the existing account and picklist value I will get the selected account Salesperson field value in given input field. If I click create button then the opportunity will be created under the existing account. The opportunity owner should be the Salesperson the one which I selected from the vf page. As expected the opportunity has been created under the existing account but the opportunity owner was not the one which I selected. Steps I followed, 1.I have taken the salesperson value from Account using the below query.
public String Sales_pop1 {get;set;} Sales_pop1 =[select EXO_Sales_Rep__r.id, EXO_Sales_Rep_r.Name from Account where id=:siteObj.Account_c LIMIT 1].EXO_Sales_Rep__r.Name;
now Sales_pop1 variable will have the value of Salesperson name.
I have written a code to create an opportunity in the existing account. There I have mapped the Sales_pop1 field to Opportunity Owner field. The code is below
public void convertbutton1() {
try {
Opportunity opp = new Opportunity();opp.Site_Ref_No__c = siteObj.Site_Ref_No__c; opp.Name = siteObj.Name+'-'+string1;
opp.AccountId=siteObj.Account__c; //Mapping Selected lookup account id to Opportunity AccountId opp.Owner=Sales_pop1; //Mapping Salesperson name to Opportunity owner
opp.CloseDate=siteObj.Completion_Date__c;
opp.StageName=stage1; if(stage1 == 'No Contact Made') opp.Probability= 0; else if(stage1 == 'Conatct Made') opp.Probability= 10; else if(stage1 == 'Taking Off') opp.Probability= 25; else if(stage1 == 'Quotation with Customer ') opp.Probability= 50; else if(stage1 == 'Negotiation/Review') opp.Probability= 75; else if(stage1 == 'Closed Won') opp.Probability= 100; else if(stage1 == 'Closed Lost') opp.Probability= 0; try { insert opp; }
I got an error while passing the salesperson value to Opportunity owner.
Error Error: Compile Error: Illegal assignment from String to SOBJECT:User at line 312 column 9
Please help me out in this issue. Thanks in Advance.
Regards, Uday.