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
MaheemSamMaheemSam 

conditionally update the ownerid in apex

Hi, 

  I need to update the lead owner id based on a condition else it must just follow the regular lead assingment rule. 

  Below is the code 

 
for(CTAP_Assessment__c ctap : newLst){

  
    if(ctap.Partner_Account__c !=  null && ctap.End_Customer_Country__c != 'USA'){
                  LeadOwner = partnerActs[0].ownerid;
               system.debug('Lead owner is assigned' + LeadOwner ); 
             }


   Lead l = new lead (Company = ctap.End_Customer_Name__c, 
                                  FirstName = ctap.Contact_First_Name__c, 
                                  LastName = ctap.Contact_Last_Name__c, 
                                  Email = ctap.Contact_Email__c,
                                  Phone = ctap.Phone__c,
                                  Title = ctap.Title__c,
                                  Industry = ctap.Industry__c,
                                  LeadSource = ctap.Lead_Source__c,
                                  Country = ctap.End_Customer_Country__c,
                                  State = ctap.state__c,
                                  Postalcode = ctap.postalcode__c,
                                  Employee_Size__c = ctap.Employee_Size__c                                 
                                  //,Ownerid = LeadOwner  // here is the problem it is showing null always Please suggest me how to set ownerid or update owner id conditionally                                   
                              );


  }

Thanks
Sudhir
Wilfredo Morillo 20Wilfredo Morillo 20
Is the leadOwner returning anything:
partnerActs[0].ownerid;?