+ Start a Discussion
mat_tone_84mat_tone_84 

fieldstonull multiple fields vbnet

Hi,
in vb.net i'm able to null a list of fields that i knows, but i'm looking for the way to repeat for each field of an object, for example, "opportunity" and check if the field is null. After that I can update my object.
Anyone can help me?

now i do this and work properly:
anull(0) = "custom_field_aasdfa__c"
anull(1) = "custom_field_basdfasb__c"
anull(2) = "custom_field_csdfac__c"
opportunityx.fieldstonull = anull
arrayopportunity(0) = opportunityx
saveresultx = client.update(arrayopportunity)
the problem is that i don't know which are the null field.
if I use "describeSObject" I can get the property of the field but not the value for check if it is null...
I think to do something like this:
for i = 0 to 500 'max number of the field into the opportunity
   if opportunityx.fieldname = "" then
       anull(z) = fieldname  <--- where i find it ?? 
end if
next i

 
Best Answer chosen by mat_tone_84
mat_tone_84mat_tone_84
I solve in this way:
For Each p As System.Reflection.PropertyInfo In oppok.GetType().GetProperties
                    If p.CanRead Then
                        Console.WriteLine("{0}:{1}", p.Name, p.GetValue(opportunityx, Nothing))
                    End If
                Next

 

All Answers

BalajiRanganathanBalajiRanganathan
I think you have to get the list of DescribeFieldResult for the Opportunity and check isNillable() method to know if that field can be null.

https://developer.salesforce.com/forums/ForumsMain?id=906F00000008qYdIAI
mat_tone_84mat_tone_84
i try to get the list of the field by Describefieldresult but when i found if the field is nillable or not , how can i use this list with the field of opportunity ?
Dim res As SFDC.DescribeSObjectResult = New SFDC.DescribeSObjectResult
        res = sfclient.describeSObject("opportunity")
        Dim listfield() As String 
        For i = 0 To res7.fields.Length - 1
            If res.fields(i).nillable = True Then
                    listfield(i) = res.fields(i).name
             end if
        next i

maybe i have to do something like this:
z = 0
dim opportunityx As SFDC.Opportunity = Nothing
Dim qr As SFDC.QueryResult = New SFDC.QueryResult
codsql = "select xxxx"
                qr = sfclient.query(codsql)
                If qr.size > 0 Then
                    For Each opportunityx In qr.records                     
                        for i = 0 to 500'max number of the field into the opportunity
                            if opportunityx.listfield(i) = "" then   <--- of course doesn't work
                                anull(z) = listfield(i)  
                                z = z +1
                            end if
                         next i
                    Next
                end if

 
mat_tone_84mat_tone_84
I solve in this way:
For Each p As System.Reflection.PropertyInfo In oppok.GetType().GetProperties
                    If p.CanRead Then
                        Console.WriteLine("{0}:{1}", p.Name, p.GetValue(opportunityx, Nothing))
                    End If
                Next

 
This was selected as the best answer