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
Vigneshwaran LoganathanVigneshwaran Loganathan 

Illegal assignment from Cycle_Plan_vod__c to Id

Hi Everyone, 

I'm facing "Illegal assignment from Cycle_Plan_vod__c to Id". Below is my code, 

I'm getting the values for colx from excel and should assign it to Cycle_plan_vod__c (Lookup in Cycle plan target) field. When i assign External id, I'm facing the error. I cant assign cyp.id as it returns null..!

Schema.sObjectType objectDefTar = Schema.getGlobalDescribe().get('Cycle_plan_Target_vod__c').getDescribe().getSObjectType();
sObject thisObjTar = objectDefTar.NewsObject();

if(cycPlanTargetFields.contains(headerNameTar) && headerNametar=='Cycle_Plan_vod__c')
                      {
                           system.debug('*****here' + headerNameTar);
                          Cycle_plan_vod__c cyp = new Cycle_plan_vod__c(External_ID_vod__c = colx);
                          
                          thisObjTar.put(headerNameTar , cyp);                        
                      }
Nayana KNayana K
Seems like you have to query records matching with external Id first so that you can get the SF record Id.  Then assign.