You need to sign in to do that
Don't have an account?
Mak One
I want to provide null value to fields dynamically. Means whatever fields have to be nullified will come from a List.
I have to do something like this:
Object__c obj; //Initiated in Constructor
List<String> fieldNames=new List<String>{'Field1__c, Field2__c, Field3__c};
for (String str: fieldNames) {
obj.<str>=null
}
update obj;
So, it will be obj.Field1__c=null; obj.Field2__c=null ...
Can we do this in Salesforce Apex?
Object__c obj; //Initiated in Constructor
List<String> fieldNames=new List<String>{'Field1__c, Field2__c, Field3__c};
for (String str: fieldNames) {
obj.<str>=null
}
update obj;
So, it will be obj.Field1__c=null; obj.Field2__c=null ...
Can we do this in Salesforce Apex?
sObject sObj = Schema.getGlobalDescribe().get('Object__c').newSObject() ;
List<String> fieldNames=new List<String>{'Field1__c, Field2__c, Field3__c};
for (String str: fieldNames) {
sObj.put(str , null) ;
}
insert sObj;
Regards,
All Answers
sObject sObj = Schema.getGlobalDescribe().get('Object__c').newSObject() ;
List<String> fieldNames=new List<String>{'Field1__c, Field2__c, Field3__c};
for (String str: fieldNames) {
sObj.put(str , null) ;
}
insert sObj;
Regards,
Directly
obj.put(str,null) is also working.