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
Daley HuangDaley Huang 

How to avoid overwrite specific fields when upsert recode?

LastName and Company fields no nulls allowed, but I not want to overwrite if the recode is existing when upsert data, how to handle it?

list<Lead> objLead = new List<Lead>();
for (Integer i = 0; i < OpenIDList.size(); i++)
        {
            objLead.add(
                New Lead(
                    LastName = 'LName',
                    company = 'Company A',
                    OpenID__c = '000001',
                  )
            );

        }

        try {
            upsert objLead OpenID__c;
        } catch (DmlException e) {

        }
SamirKhanSamirKhan
Check for Null/black before assigning the value to your fields.
 For example : -

if(!(ObjName.fieldName != null && String.isNotBlank(String.valueOf(ObjName.fieldName))){
     //assign the values here
}