0

here is my code in which i am trying to pass lookup values and owner so that i can create an order record. but i m facing error for contractor lookup field-- "

Error: Compile Error: Illegal assignment from Id to Contract at line 11 column 15"

and for owner--

"Error: Compile Error: Illegal assignment from User to Name at line 12 column 16"

Code of class in which i have written a trigger

public class order_Creation
{
    public static void osCreated(List<Opportunity> op)
    {
       List <Order> orderToInsert = new List <Order>(); 
      for(Opportunity o : op){        
         if(o.StageName == 'Closed Won'){      
               Order v = new Order();         
               v.Account = o.Account; 
               v.EffectiveDate = System.today();
              v.Contract = o.Contract_Number__c; 
               v.Owner = o.owner; 
               orderToInsert.add(v);
         }
       }



      try {
          insert orderToInsert;    
      } 
      catch (system.Dmlexception e) {
          system.debug (e);
      }


   }

}
  • 1
    v.Contract = o.Contract_Number__c; instead use v.ContractId = o.Contract_Number__c; – Ratan Paul Feb 1 '16 at 15:39
  • thanks it works, but what about owner – RAT__ Feb 1 '16 at 15:41
  • 1
    It will be ownerId – Ratan Paul Feb 1 '16 at 15:42
4

Change

v.Contract = o.Contract_Number__c; 
 v.Owner = o.owner; 

to

 v.ContractId = o.Contract_Number__c; 
 v.OwnerId = o.ownerId; 

Always check field API name..

  • i have tried this its working no error is there but its not creating contract record, have given all required values – RAT__ Feb 2 '16 at 4:10
  • @RAVIGAUTAM don't use try catch and check.. you will get error then – Ratan Paul Feb 2 '16 at 5:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.