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
Ishan Singh 4Ishan Singh 4 

In some leads a field name 'state' is blank i want to update those field's state with default and then execute my main field update in batch class

 for(Lead l: scope)
        {
            
            if(l.State!=''){ //State is not empty
                l.State__c =l.State__c;
            }else{    //State is empty
                l.State__c ='Default';}
            
            
            l.Age__c = l.Current_Age__c;
            
        }
        update scope;
    }
Best Answer chosen by Ishan Singh 4
@anilbathula@@anilbathula@
Hi Ishan,

I think you are trying to update State__c with State.
Try the below code:-
 
for(Lead l: scope)
        {
            
            if(l.State!=''){ //State is not empty
                l.State__c =l.State;
            }else{    //State is empty
                l.State__c ='Default';}
            
            
            l.Age__c = l.Current_Age__c;
            
        }
        update scope;
    }
Thanks
Anil.B
 

All Answers

@anilbathula@@anilbathula@
Hi Ishan,

I think you are trying to update State__c with State.
Try the below code:-
 
for(Lead l: scope)
        {
            
            if(l.State!=''){ //State is not empty
                l.State__c =l.State;
            }else{    //State is empty
                l.State__c ='Default';}
            
            
            l.Age__c = l.Current_Age__c;
            
        }
        update scope;
    }
Thanks
Anil.B
 
This was selected as the best answer
Ishan Singh 4Ishan Singh 4
Thanks Anil,
If date field i.e, dateOfBirth__c is empty then I to update it with 1991-01-01. Can you give any solution?
Ishan Singh 4Ishan Singh 4
@anilbathula@
Thanks Anil,
If date field i.e, dateOfBirth__c is empty then I to update it with 1991-01-01. Can you give any solution?The above solution is not working for this requirement. 
 
@anilbathula@@anilbathula@
Try this code:
If(l.dateOfBirth__c==null){
date myDate = date.newInstance(1991, 01, 01);
l.dateOfBirth__c=mydate;
}