質問

My trigger is giving me an "Illegal assignment from Id to SOBJECT:User' error.

The trigger is supposed to create a new opportunity when the field in the custom object is a certain value. I want to input some fields from the object into the opportunity.

trigger MDwinning2 on MD_Meeting__c (after update) {
List <Opportunity> oppToInsert = new List <Opportunity> ();
    for (MD_Meeting__c m : Trigger.new) {
    if (m.SAL__c==True) {    
    Opportunity o = new Opportunity ();   
    o.OwnerId = m.Sales_Director__c;
    o.Name = m.Name;
    o.StageName = 'Generate Opportunity';
    o.Market_Developer__c = m.Market_Developer__c;
    o.AccountId = m.Account__c;
    o.Type = 'Sales - New Business';
  o.CloseDate = System.Today()+150;
  o.MeetingLookup__c = m.Id;
    oppToInsert.add(o);
    }//end if
}//end for o
//try {
//        insert oppToInsert; 
//    } catch (system.Dmlexception e) {
//       system.debug (e);
//    } 
}
役に立ちましたか?

解決

Change

    o.Owner = m.Sales_Director__c;
    o.Account = m.Account__c;

To

o.OwnerId = m.Sales_Director__c;
o.AccountId = m.Account__c;

他のヒント

I've wrote this answer for further discussion because the trouble didn't fixed

trigger MDwinning2 on MD_Meeting__c (after update) {
    List <Opportunity> oppToInsert = new List <Opportunity> ();
    for (MD_Meeting__c m : Trigger.new) {
        if (m.SAL__c == True) {
            Opportunity o = new Opportunity ();
            o.OwnerId = m.Sales_Director__c;
            o.Name = m.Name;
            o.StageName = 'Generate Opportunity';
            o.Market_Developer__c = m.Market_Developer__c;
            o.AccountId = m.Account__c;
            o.Type = 'Sales - New Business';
            o.CloseDate = System.Today() + 150;
            o.MeetingLookup__c = m.Id;
            oppToInsert.add(o);
        }
    }
    insert oppToInsert;
}

try this code and if error will appear again please post error msg in comment

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top