• manish arora 26
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Hello I'm trying to write a test class for Rest API post Method which i wrote, need help in writing test method. This gives me System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call:". Please help
trigger RadarFirst on Patient_Satisfaction__c (after update) {
for (Patient_Satisfaction__c cc : Trigger.new){
if(cc.Patient_Relation__c!= Trigger.oldMap.get(cc.id).Patient_Relation__c && cc.Patient_Relation__c != null) {
      if(cc.Patient_Relation__c.contains('Referred to Privacy Office')){
      RadarUpdate.postcallout(cc.id);
      }
  }
}
}
 
public class RadarUpdate {
    @future (callout=true)
	public static void postcallout(string Id) { 
	Patient_Satisfaction__c c = [select id, Name, Reporter_Phone__c,Reporter_First_Name__c,Reporter_Last_Name__c, Reporter_Email__c,
    Description_of_Feedback__c from Patient_Satisfaction__c where Patient_Relation__c ='Referred to Privacy Office' order by lastmodifiedDate desc limit 1];
    JSONGenerator gen = JSON.createGenerator(true);
	gen.writeStartObject();
	gen.writeObjectField('name', c.Name);
	gen.writeObjectField('incident_group_id', 7387);
    gen.writeObjectField('description',c.Description_of_Feedback__c);
	gen.writeFieldName('submitted_by');
	gen.writeStartObject();
	gen.writeStringField('given_name',c.Reporter_First_Name__c);
	gen.writeStringField('surname', c.Reporter_Last_Name__c);
	gen.writeStringField('phone',c.Reporter_Phone__c);
    gen.writeStringField('email',c.Reporter_Email__c);
	gen.writeEndObject();
	String jsonS = gen.getAsString(); 
	System.debug('jsonMaterials'+jsonS);
    Http http = new Http();
	HttpRequest request = new HttpRequest();
	request.setEndpoint('https://api.radarfirst.com/incidents');
	request.setMethod('POST');
	request.setHeader('Content-Type','application/json;charset=UTF-8');
	request.setHeader('User-agent', 'Salesforce-integration-client');
	request.setHeader('Authorization','Bearer 123');
    request.setBody(jsonS);
	// Set the body as a JSON object
	HttpResponse response = http.send(request);
	if (response.getStatusCode() != 201) {
    System.debug('The status code returned was not expected: ' +
        response.getStatusCode() + ' ' + response.getStatus());
	} else {
    System.debug(response.getBody());
	}
    }
}
@isTest
public class RadarUpdateTest{

    static testMethod void  postcalloutTest(){
        Account ac = new Account();
        ac.Name= 'Test';
        insert ac;
        
        Contact con= new Contact();
        con.AccountId= ac.Id;
        con.FirstName ='First Name';
        con.LastName = 'Test Contact';
        con.Phone= '7896541233';
        con.Email= 'Test@123.com';
        con.RUSH_Email__c= 'Test@123.com';
        insert con;
         		
        Patient_Satisfaction__c Pr = new Patient_Satisfaction__c();
        Pr.Primary_Campus__c = 'a1pP0000001lfaKIAQ';
        Pr.Primary_Facility__c= 'a1pP00000022FLRIA2';
        Pr.Primary_Location__c= 'a1pP00000022FLcIAM';
        Pr.Reporter__c=con.Id;
        Pr.Reporter_Phone__c=con.Id;
        Pr.Reporter_Email__c= 'Test@123.com';
        Pr.Description_of_Feedback__c= 'Testing Privacy office';
        Pr.Patient_Relation__c = 'Referred to Privacy Office';
        
     update Pr;
  	 RadarUpdate reqst=new RadarUpdate();
   	 String JsonMsg=JSON.serialize(reqst);
     Test.startTest();

    RestRequest req = new RestRequest(); 
    RestResponse res = new RestResponse();

    req.requestURI = '/services/apexrest/DemoUrl';  //Request URL
    req.httpMethod = 'POST';//HTTP Request Type
    req.requestBody = Blob.valueof(JsonMsg);
    RestContext.request = req;
    RestContext.response= res;
    RadarUpdate.postcallout(Pr.Id);
  
    update Pr;
    Test.stopTest();

   }
}

 

 

I am trying to put the id from database.saveresult return values and then the matching value from the citylist list into this map below, but I get an error "Method does not exist or incorrect signature: void put(sumchans__City_Master__c, Id) from the type Map<String,String>"
 
Database.SaveResult[] saveCityMaster = Database.Insert(cityList, false);
        Map<String,String> findCityId = new Map<String,String>();
        for (Database.SaveResult sr : saveCityMaster) {
            if (!sr.isSuccess()) {
                findCityId.put(cityList.get(0),sr.getId());
            }
        }