+ Start a Discussion
Shri BEShri BE 

update Rest API

Hi All,
I need to update Account by comparing the email using Postman REST Api.
Below is my code which works fine but I have 1 issue. i.e.
It is updating all fields even though I update 1 or 2 fields from JSON response.

I update city but remaining all fields has become NULL after update.

Apex Class:
global with sharing class insertAccount
    //Update Method
    global static String fetchAccount(String name, String phone, String mobile, String email, String city, String state, String country, String postal)
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;        

        Account acc = new Account();
        //Query to get Matching Email from Account
        acc = [SELECT Id, Email__c FROM Account WHERE Email__c =:email];

        acc.Name = name;
        acc.MobilePhone__c = mobile;
        acc.Email__c = email;
        acc.Billingcity = city;
        acc.BillingState = state;
        acc.BillingCountry = country;
        acc.BillingPostalcode = postal;
        acc.phone = phone;
        update acc;

        return acc.Id;
JSON Resonse:
    "name" : "Testing",
    "city" : "Dubai",
    "email" : "test@gmail.com"