+ Start a Discussion
SFDC User2382943SFDC User2382943 

Create Opportunity from Custom Object

I have a custom object that I would like to create and save an opportunity from with a few of the fields. I think my problem is that I'm including contact lookup fields? I'm getting a save error that says "Illegal assignment from Id to SOBJECT:User"

How can I make this trigger work?

trigger meeting on MD_Meeting__c (after update) {
    List <Opportunity> oppToInsert = new List <Opportunity> ();
    for (MD_Meeting__c m : Trigger.new) {
        if (m.SD_Action__c=='Generate Opportunity') {   
        Opportunity o = new Opportunity ();  
        o.Owner = m.Sales_Director__c;
        o.Market_Developer__c = m.Market_Developer__c;
        o.Account = m.Account__c;
        o.Type = 'Sales - New Business';
    o.CloseDate = System.Today()+150;
    o.MeetingLookup__c = m.Name;
        o.add(o);
        }//end if
    }//end for o
    try {
        insert oppToInsert;
    } catch (system.Dmlexception e) {
        system.debug (e);
    }
}
willardwillard
Try adding Id in front of Owner and Account, i.e., OwnerId and AccountId.
SFDC User2382943SFDC User2382943
Thank you. That fixed the error but a new one appeared for this part:   o.add(o); It says "Method does not exist or incorrect signature: [SOBJECT:Opportunity].add(SOBJECT:Opportuntiy)
MagulanDuraipandianMagulanDuraipandian
Replace o.add(o); with oppToInsert.add(o);

If this solves your problem, kindly mark it as the best answer.

Regards,
Magulan
http://www.infallibletechie.com
SFDC User2382943SFDC User2382943
I updated the Owner and Account IDs, replaced the insert language, and added the Opportunity Name.

Now, there is no error message, but not opportunity is inserted when the object is updated. Nothing happens and I can't tell why?