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
Uttirna DasUttirna Das 

How can I resolve System.DmlException: Update failed. First exception on row 0 with id 00Q7F000001xDVEUA2; first error: REQUIRED_FIELD_MISSING,

Error is--- 

System.DmlException: Update failed. First exception on row 0 with id 00Q7F000001xDVEUA2; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Geolocation (Latitude), Geolocation (Longitude)]: [Geolocation (Latitude), Geolocation (Longitude)]
Error is in expression '{!Updatelocation}' in component <apex:commandButton> in page geolocation: Class.Geolocation.Updatelocation: line 13, column 1
Class.Geolocation.Updatelocation: line 13, column 1




My code is--- 

public with sharing class Geolocation {
    Public Decimal Lat {get; set;}
    Public Decimal lon {get; set;}
    Public Id lid {get; set;}
    public PageReference Updatelocation(){
       
         lid = ApexPages.currentPage().getParameters().get('id');
         Lead l= new Lead();
         
         l.id= lid;
         l.Geolocation__Latitude__s = lat;
         l.Geolocation__Longitude__s = lon;
        update l;
       
        return new PageReference('javascript:window.close()');
    }
}
Pavit SiddhuPavit Siddhu

Hello , before Update check required field like lastname, company are required

so enter these fields with your fields then update l; 
 

Amol Salve 14Amol Salve 14
Hello Uttirna,
   As per your code you get id from lead record then create new lead record and assign that id to lead and update Geolocation__Latitude__s, Geolocation__Longitude__s  this field with new value but what about required field from Lead record like LastName, Compony and Lead Status so you have to provide this field value also or you can update you code this following code this will also solve your problem

public with sharing class Geolocation {
    Public Decimal Lat {get; set;}
    Public Decimal lon {get; set;}
    Public Id lid {get; set;}
    public PageReference Updatelocation(){
       
         lid = ApexPages.currentPage().getParameters().get('id');
         Lead l= [Select Id, Geolocation__Latitude__s ,Geolocation__Longitude__s From Lead Where Id =:  lid ];
         l.Geolocation__Latitude__s = lat;
         l.Geolocation__Longitude__s = lon;
        update l;
       
        return new PageReference('javascript:window.close()');
    }
}
Thank you,
Amol Salve
Salesforce Devloper