• Vishwas S
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies

Hi all,

I am writing a Test Class for Apex REST Callout which is throwing an error as "Illegal assignment from void to System.HttpResponse" .

In the test class error is in this line

 HttpResponse response = Account6Class.postmethod(aId); 
 
Please help to reslove this error. Thanks in advance.

This is code of Trigger:
trigger Account6 on Account (after insert) {
        if (Trigger.isInsert) {
        Set<Id> accountIdSet = new Set<Id>();
        for(Account accObj: trigger.new){
            accountIdSet.add(accObj.id);
         }
        if(!accountIdSet.isEmpty()){
            Account6Class.postmethod(accountIdSet);
        }
    }

This is code of Class:
public class Account6Class {
@future(callout=true)
    public static void postmethod(Set<Id> accountIdset) {       
        string resultBodyGet = '';
        list<Account> accts = [SELECT  Name, Id, Description, Phone FROM Account WHERE Id IN:accountIdset];
       for(Account c : accts){         
            MAp<String, String> tags = new Map<String, String>();
            tags.put('id', c.Id);
            tags.put('Name', c.Name);
            tags.put('Description',c.Description);
            tags.put('Phone',c.Phone);               
            try{
                string endpoint = 'https://abc.com/xyz';
                HttpRequest req = new HttpRequest();
                req.setEndpoint(endpoint);
                req.setMethod('POST');
                req.setHeader('Content-type', 'application/json');
                req.setbody(JSON.serialize(tags));
                Http http = new Http();
                HTTPResponse response = http.send(req); 
                resultBodyGet = response.getBody();
                system.debug('Output response:' + resultBodyGet);
                accResponse myAccResponse = new accResponse();
                myAccResponse = (accResponse) JSON.deserialize(resultBodyGet, accResponse.class);
                system.debug('#### myAccResponse: ' + myAccResponse);
            }
            catch (exception e) {                              
            }   
        }
    }    
public class accResponse {
        public string message {get;set;}
    }
}

This is code of  HttpCallouMock Class:
@isTest
global class Account6Test implements HttpCalloutMock{
    global HTTPResponse respond(HTTPRequest request) {
         HttpResponse response = new HttpResponse();
        response.setHeader('Content-Type', 'application/json');
        response.setBody('{"Account": ["Test6"]}');
        response.setStatusCode(200);
        return response; 
    }
}

This is code of  Test Class:
@isTest
private class Account6Test1 {
    @isTest static void testPostCallout() {
        Test.setMock(HttpCalloutMock.class, new Account6Test() );
        Set<Id> aId = new Set<id>();
         Account test = new Account();
            test.Name = 'Test6';
            test.Description = 'FooDes';
            test.Phone = '1231231232';
            insert test;
            aId.add(test.Id);
          System.debug('Accounts are ' + aId);
        HttpResponse response = Account6Class.postmethod(aId);
        String contentType = response.getHeader('Content-Type');
        System.assert(contentType == 'application/json');
        String actualValue = response.getBody();
        System.debug(response.getBody());
        String expectedValue = '{"Account": ["Test6"]}';
        System.assertEquals(actualValue, expectedValue);
        System.assertEquals(200, response.getStatusCode());
        
    }
 }

I am writing a trigger that has to fire when a predecessor task Status field (Picklist field) is marked "completed" then the successor task Status field (Picklist field) should populate "Started"  I have tried to build something but still have very limited knowledge.

Hi all,

I am writing a Test Class for Apex REST Callout which is throwing an error as "Illegal assignment from void to System.HttpResponse" .

In the test class error is in this line

 HttpResponse response = Account6Class.postmethod(aId); 
 
Please help to reslove this error. Thanks in advance.

This is code of Trigger:
trigger Account6 on Account (after insert) {
        if (Trigger.isInsert) {
        Set<Id> accountIdSet = new Set<Id>();
        for(Account accObj: trigger.new){
            accountIdSet.add(accObj.id);
         }
        if(!accountIdSet.isEmpty()){
            Account6Class.postmethod(accountIdSet);
        }
    }

This is code of Class:
public class Account6Class {
@future(callout=true)
    public static void postmethod(Set<Id> accountIdset) {       
        string resultBodyGet = '';
        list<Account> accts = [SELECT  Name, Id, Description, Phone FROM Account WHERE Id IN:accountIdset];
       for(Account c : accts){         
            MAp<String, String> tags = new Map<String, String>();
            tags.put('id', c.Id);
            tags.put('Name', c.Name);
            tags.put('Description',c.Description);
            tags.put('Phone',c.Phone);               
            try{
                string endpoint = 'https://abc.com/xyz';
                HttpRequest req = new HttpRequest();
                req.setEndpoint(endpoint);
                req.setMethod('POST');
                req.setHeader('Content-type', 'application/json');
                req.setbody(JSON.serialize(tags));
                Http http = new Http();
                HTTPResponse response = http.send(req); 
                resultBodyGet = response.getBody();
                system.debug('Output response:' + resultBodyGet);
                accResponse myAccResponse = new accResponse();
                myAccResponse = (accResponse) JSON.deserialize(resultBodyGet, accResponse.class);
                system.debug('#### myAccResponse: ' + myAccResponse);
            }
            catch (exception e) {                              
            }   
        }
    }    
public class accResponse {
        public string message {get;set;}
    }
}

This is code of  HttpCallouMock Class:
@isTest
global class Account6Test implements HttpCalloutMock{
    global HTTPResponse respond(HTTPRequest request) {
         HttpResponse response = new HttpResponse();
        response.setHeader('Content-Type', 'application/json');
        response.setBody('{"Account": ["Test6"]}');
        response.setStatusCode(200);
        return response; 
    }
}

This is code of  Test Class:
@isTest
private class Account6Test1 {
    @isTest static void testPostCallout() {
        Test.setMock(HttpCalloutMock.class, new Account6Test() );
        Set<Id> aId = new Set<id>();
         Account test = new Account();
            test.Name = 'Test6';
            test.Description = 'FooDes';
            test.Phone = '1231231232';
            insert test;
            aId.add(test.Id);
          System.debug('Accounts are ' + aId);
        HttpResponse response = Account6Class.postmethod(aId);
        String contentType = response.getHeader('Content-Type');
        System.assert(contentType == 'application/json');
        String actualValue = response.getBody();
        System.debug(response.getBody());
        String expectedValue = '{"Account": ["Test6"]}';
        System.assertEquals(actualValue, expectedValue);
        System.assertEquals(200, response.getStatusCode());
        
    }
 }

Can anyone tell me how I can delete a managed packaged that was uploaded to appexchange ?
  • January 25, 2008
  • Like
  • 0