• Nagaraj SV
  • NEWBIE
  • 20 Points
  • Member since 2015


  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 21
    Questions
  • 14
    Replies
My apex class 
 
@RestResource(urlMapping='/SDUpdateSchoolService/*')
global with sharing class SD_UpdateSchoolService{
    @HttpPut
    global static deserializeResponse updateOrganization(){
        SD_UpdateSchoolService.deserializeResponse results;
        try{
            RestRequest req = RestContext.request;
            RestResponse res = RestContext.response;
            String jsonStr= req.requestBody.toString();    
            JSONParser parser = JSON.createParser(jsonStr);
            jsonParserClass UpdateOrganizationRequest = (jsonParserClass)parser.readValueAs(jsonParserClass.class);
            system.debug('UpdateOrganizationRequest=========>'+UpdateOrganizationRequest);
            if(UpdateOrganizationRequest.OrgId == null || UpdateOrganizationRequest.OrgId == ''){
                results = new SD_UpdateSchoolService.deserializeResponse(False, 'Please Send OrganizationId');
                return results;
            }else if(UpdateOrganizationRequest.OrgId != null){
                //Fetching the Profile/Contact information based on OrgId
                list<Account> lstAcc = [Select id from Account where Id =: UpdateOrganizationRequest.OrgId limit 1];
                if(lstAcc.size() > 0){
                    Account accobj = new Account();
                    accobj.id = UpdateOrganizationRequest.OrgId;
                    if(!String.isBlank(UpdateOrganizationRequest.SchoolName)){
                        accobj.Name = UpdateOrganizationRequest.SchoolName;
                    }
                    if(!String.isBlank(UpdateOrganizationRequest.addressline1)){
                        accobj.ShippingStreet = UpdateOrganizationRequest.addressline1 + UpdateOrganizationRequest.addressline2;
                    }
                    if(!String.isBlank(UpdateOrganizationRequest.City)){
                        accobj.ShippingCity = UpdateOrganizationRequest.City;
                    }
                    if(!String.isBlank(UpdateOrganizationRequest.State)){
                        accobj.ShippingState = UpdateOrganizationRequest.State;
                    }
                    if(!String.isBlank(UpdateOrganizationRequest.PostalCode)){
                        accobj.ShippingPostalCode = UpdateOrganizationRequest.PostalCode;
                    }
                    if(!String.isBlank(UpdateOrganizationRequest.Country)){
                        accobj.ShippingCountry = UpdateOrganizationRequest.Country;
                    }
                    if(!String.isBlank(UpdateOrganizationRequest.Fax)){
                        accobj.Fax = UpdateOrganizationRequest.Fax;
                    }
                    if(!String.isBlank(UpdateOrganizationRequest.Phone)){
                        accobj.Phone = UpdateOrganizationRequest.Phone;
                    }
                    if(!String.isBlank(UpdateOrganizationRequest.District)){
                        accobj.District__c = UpdateOrganizationRequest.District;
                    }
                   
                    update accobj;
                    results = new SD_UpdateSchoolService.deserializeResponse(True, 'Organization information Updated Successfully');
                    return results;
                }else{
                    results = new SD_UpdateSchoolService.deserializeResponse(False, 'Invalid Id was provided');
                    return results;
                } 
         }
            
        }catch (Exception ex) {
            string errorMessage = ex.getMessage(); 
            results=new SD_UpdateSchoolService.deserializeResponse(false, 'Error Message :'+errorMessage);
        }
        return results;
    }
    global class deserializeResponse{
        webservice Boolean Success {get; set;}
        webservice String  Message{get;set;}
        global deserializeResponse(Boolean success, String error){
            this.Success = success;
            this.Message = error;
        }
       
    }
   public class jsonParserClass{
        public String OrgId;
        public String UserId;
        public String SchoolName;
        public String addressline1;
        public String addressline2;
        public String City;
        public String State;
        public String PostalCode;
        public String Country;
        public String Phone;
        public String Fax;
        public String District;
   }
}

And Test Class is below and now coverage is 35% please help me and urgent 
 
@isTest
public class SD_UpdateSchoolServiceTest{
    static testMethod void updateSchoolServiceTest() {
        
        
        Account objAcc = new Account();
        objAcc.Name = 'Amoes';
        objAcc.ShippingStreet = '4 Fletcher St';
        objAcc.ShippingCity = 'Manchester';
        objAcc.ShippingState = 'NH';
        objAcc.ShippingPostalCode = '03086';
        objAcc.ShippingCountry = 'USA';
        objAcc.Website = 'http://www.amoskeagfishways.org';
        objAcc.KSD__TaxExemptId__c= '';
        objAcc.Description = 'Sampledesc';
        objAcc.KSD__Facebook__c= 'http://facebook.com/AmoskeagFishways';
        objAcc.Fax = '(603) 644-4386';
        objAcc.Phone = '9999999999'; 
        insert objAcc;
        
        Account objAccount = new Account();
        objAccount.ID = objAcc.Id;
        objAccount.Name = 'Amoes1123';
        objAccount.ShippingStreet = '4 Fletcher St';
        objAccount.ShippingCity = 'Manchester';
        objAccount.ShippingState = 'NH';
        objAccount.ShippingPostalCode = '03086';
        objAccount.ShippingCountry = 'USA';
        objAccount.Website = 'http://www.amoskeagfishways.org';
        objAccount.KSD__TaxExemptId__c= '';
        objAccount.Description = 'Sampledesc';
        objAccount.KSD__Facebook__c= 'http://facebook.com/AmoskeagFishways';
        objAccount.Fax = '(603) 644-4386';
        objAccount.Phone = '9999999999'; 
        Update objAccount;
        List<String> OrgId = new List<String>();
        OrgId.add(objAccount.ID);
        RestRequest req = new RestRequest(); 
        
        String JSONMsg = JSON.serialize(OrgId);
        req.httpMethod = 'PUT';
        req.requestBody = Blob.valueOf(JSONMsg);
        RestResponse res = new RestResponse();
        
        RestContext.request = req;
        RestContext.response = res;
        
        SD_UpdateSchoolService.deserializeResponse  SDUS = new SD_UpdateSchoolService.deserializeResponse(true,'OrgId');
        SDUS = SD_UpdateSchoolService.UpdateOrganization();
             
        
    }
    
}

 

By using Metadata API i am able to insert and removing values but i need to edit the value .(For Exmple existing value 1 and i need to change that one to 11)

Some one help please 

 

Can some help to write a test class for AutocreatedRegHandler. 
Colud you please  help  me to show records dynamically in dependent piclist 
Can you please help me to find out is there any way we can dump all USPS address in salesforce org and validate the address against salesforce Org , instead of USPS.

Hi,

I have to send image from Salesforce to ONEHUB.

for this i have code snippet in RUBY.Could you please help me to write In Apex.

Code sinnpet from ONEHUB 

Set up your instance of the Oauth2 client for multipart posts. 

In ruby, using the Oauth2 library, it’s something like this:
client = OAuth2::Client.new(client_app_id, client_app_secret, :site => ‘https://ws-api.onehub.com’, :ssl => {:verify => true}) do |b|
b.request :multipart
b.request :url_encoded
b.adapter Faraday.default_adapter
end

< handle all of the authentication here, e.g. token = OAuth2::AccessToken.new… >

Then, make the body from a local file in your directory:
pathname = ‘./logo_onehub_ws.png’

1.local file name ./logo_onehub_ws.png will be stored in folder FOLDER_ID as ‘foo1.png’
upload = Faraday::UploadIO.new(File.new(pathname,‘rb’), 
‘application/octet-stream’, ‘foo1.png’)

payload = { :file => { :name => File.basename(pathname), :‘form-data’ => upload } }

Post to the folder specified by its numeric ID
resp = token.post(“/folders/#{FOLDER_ID}/files.json”, body: payload)
you will get back a json payload with the file information in it.

Can any one help me how to Transfer files to FTP from Salesforce Attachment object.
 

I am trying to push image from salesforce to ONEHUB .But i am getting ERROR .

Can any have idea to how to do integration with One hub.

Please help me 

In the below code i am calling third party API and iam sending request but i am getting error like Bad Request.
This is the URL third party given for reference 
https://lipack.legalintake.com/#outboundHeaders
​Can any one help it's urgent ..
public class LIPOutboundCntr{
    public String apiKey {get;set;}
    public String firstName {get;set;}
    public String lastName { get; set; }
    public String result { get; set; }
    public String email{ get; set; }
    public String phoneNumber{ get; set; }
    public String encryption{ get; set; }
    
    public String RestRequest(String body,String endPoint,String method){
        
        String ReqString = 'YSX28ygFl1UaIqSKx1Sp2w==ApiKey'+apiKey+'FirstName'+firstName+'LastName'+lastName+'Email'+email+'PhoneNumber'+phoneNumber+'Encryption'+encryption;
        System.debug('ReqString============================>'+ReqString);
        Blob Blobedstring = Blob.valueOf(ReqString);
        System.debug('Blobedstring============================>'+Blobedstring);
        String FormHash = EncodingUtil.base64Encode(Blobedstring);
        System.debug('FormHash============================>'+ FormHash);
        String bbody=body.removeEnd('}');
        System.debug('bbody============================>'+bbody);
        
        String hashBody=bbody+',"FormHash"'+':'+'"'+FormHash+'"'+'}';
        System.debug('hashBody============================>'+hashBody);
        
        Http h=new Http();
        HttpRequest req = new HttpRequest();
        req.setMethod(method);
        req.setHeader('content-type','application/json');
         
        req.setEndPoint(endPoint);
        req.setBody(hashBody);
        
        HttpResponse res = h.send(req);
        result = res.getBody();
        System.debug('result================================================>'+result);
        return null;
    }
    public void getTex(){
        String texString = createTexRequestBody();
        RestRequest(texString ,'https://lipack.legalintake.com/qa/api/outbound','POST');
    }        
    public String createTexRequestBody(){
        
        JSONGenerator gen= JSON.createGenerator(true);
        gen.writeStartObject();
        gen.writeStringField('ApiKey',apiKey);
        gen.writeStringField('FirstName',firstName);
        gen.writeStringField('LastName',lastName);
        gen.writeStringField('Email',email);
        gen.writeStringField('Encryption',encryption);
        gen.writeEndObject();
        
        System.debug('gen.getAsString()================================================>'+gen.getAsString());
        return gen.getAsString();  
        
    }
    public class Jsonparsercls{  
        public String totalTax{get;set;}
        
        
    }
}
In the below code i am calling third party API and iam sending request but i am getting error like Bad Request.
This is the URL third party given for reference 
https://lipack.legalintake.com/#outboundHeaders
Can any one help it's urgent ..
public class LIPOutboundCntr{
    public String apiKey {get;set;}
    public String firstName {get;set;}
    public String lastName { get; set; }
    public String result { get; set; }
    public String email{ get; set; }
    public String phoneNumber{ get; set; }
    public String encryption{ get; set; }
    
    public String RestRequest(String body,String endPoint,String method){
        
        String ReqString = 'YSX28ygFl1UaIqSKx1Sp2w==ApiKey'+apiKey+'FirstName'+firstName+'LastName'+lastName+'Email'+email+'PhoneNumber'+phoneNumber+'Encryption'+encryption;
        System.debug('ReqString============================>'+ReqString);
        Blob Blobedstring = Blob.valueOf(ReqString);
        System.debug('Blobedstring============================>'+Blobedstring);
        String FormHash = EncodingUtil.base64Encode(Blobedstring);
        System.debug('FormHash============================>'+ FormHash);
        String bbody=body.removeEnd('}');
        System.debug('bbody============================>'+bbody);
        
        String hashBody=bbody+',"FormHash"'+':'+'"'+FormHash+'"'+'}';
        System.debug('hashBody============================>'+hashBody);
        
        Http h=new Http();
        HttpRequest req = new HttpRequest();
        req.setMethod(method);
        req.setHeader('content-type','application/json');
         
        req.setEndPoint(endPoint);
        req.setBody(hashBody);
        
        HttpResponse res = h.send(req);
        result = res.getBody();
        System.debug('result================================================>'+result);
        return null;
    }
    public void getTex(){
        String texString = createTexRequestBody();
        RestRequest(texString ,'https://lipack.legalintake.com/qa/api/outbound','POST');
    }        
    public String createTexRequestBody(){
        
        JSONGenerator gen= JSON.createGenerator(true);
        gen.writeStartObject();
        gen.writeStringField('ApiKey',apiKey);
        gen.writeStringField('FirstName',firstName);
        gen.writeStringField('LastName',lastName);
        gen.writeStringField('Email',email);
        gen.writeStringField('Encryption',encryption);
        gen.writeEndObject();
        
        System.debug('gen.getAsString()================================================>'+gen.getAsString());
        return gen.getAsString();  
        
    }
    public class Jsonparsercls{  
        public String totalTax{get;set;}
        
        
    }
}
Public class GetCases
{
    Public static void SaveCase(GetCases.Cases cases)
    {                
        HttpRequest req = new HttpRequest(); 
        //req.setEndpoint(System.URL.getSalesforceBaseUrl().toExternalForm()+'/services/apexrest/CaseRestAPI?Priority='+cases.Priority+'&Reason='+cases.Reason+'&Subject='+cases.Subject+'&Description='+cases.Description+'&Status='+cases.Status);
        req.setEndpoint(System.URL.getSalesforceBaseUrl().toExternalForm()+'/services/apexrest/CaseRestAPI');
        req.setMethod('POST');
        req.setHeader('Content-Type', 'application/json');
        string caseNew=System.JSON.serialize(cases);
        req.setHeader('Content-Length',String.valueof(caseNew.length()));
        req.setCompressed(true);
        req.setHeader('Authorization', 'OAuth '+GetSessionId.getSessionId());
        req.setBody(caseNew);
        
        Http http = new Http();
        HTTPResponse res = http.send(req);
        
        // redirection checking
        boolean redirect = false;
        if (res.getStatusCode() >=300 && res.getStatusCode() <= 307 && res.getStatusCode() != 306) 
        {
            do {
                redirect = false; // reset the value each time
                String loc = res.getHeader('Location'); // get location of the redirect
                if(loc == null) {
                    redirect = false;
                    continue;
                }
                req = new HttpRequest();                
                req.setEndpoint(loc);
                req.setMethod('POST');
                req.setHeader('Content-Type', 'application/json');
                caseNew=System.JSON.serialize(cases);
                req.setHeader('Content-Length',String.valueof(caseNew.length()));
                req.setCompressed(true);
                req.setHeader('Authorization', 'OAuth '+GetSessionId.getSessionId());
                req.setBody(caseNew);
                res = http.send(req);
                if(res.getStatusCode() != 500) // 500 = fail
                { 
                    if(res.getStatusCode() >=300 && res.getStatusCode() <= 307 && res.getStatusCode() != 306) 
                    {
                        redirect= true;
                    }
                }
            } while (redirect && Limits.getCallouts() != Limits.getLimitCallouts());

        }
                
        string jsonResponse=res.getBody();
        
        System.debug('POSTBODY: '+jsonResponse);
        System.debug('POSTSTATUS:'+res.getStatus());
        System.debug('POSTSTATUS_CODE:'+res.getStatusCode());
    }
    }

I have requriment 

I am uploading CSV file from visualforce page and the CSV contains two cloumns called name and email .In email I have 10 email ids in those 5 email ids are invalid (Email ids are not existed)but all are in correct formate.

Now how can i find the Bounced email address.

I've created a trigger that calls the metadata api (class created from metadata api wsdl) for updating the picklist value in a sobject. Now with this working fine i need to deploy it for which the code coverage is required.

I wrote the below piece of code to test:
 
static testmethod void UpdateSalesOwnerPicklist_Tr(){
		        user usr =  new user();
		        usr.LastName = 'Phil';
		        usr.Alias = 'Sphil';
		        usr.Email = 'non@none.co.uk';
		        usr.Username = 'spencer.phil@capita.co.uk';
		        usr.CommunityNickname = 'Phil';
		        usr.TimeZoneSidKey = 'Europe/London';
		        usr.LocaleSidKey = 'en_GB';
		        usr.EmailEncodingKey = 'ISO-8859-1';
		        usr.ProfileId = '00e2400000103uxAAA';
		        usr.LanguageLocaleKey = 'en_US';
		        //insert user
		        insert usr;
		    }
but for the error Methods defined as TestMethod do not support Web service callouts

Following this i did refer the link  https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts_wsdl2apex_testing.htm    but quite confused on how to approach the test class? any help on this please?
 
  • November 19, 2015
  • Like
  • 0

Hi,

I have to send image from Salesforce to ONEHUB.

for this i have code snippet in RUBY.Could you please help me to write In Apex.

Code sinnpet from ONEHUB 

Set up your instance of the Oauth2 client for multipart posts. 

In ruby, using the Oauth2 library, it’s something like this:
client = OAuth2::Client.new(client_app_id, client_app_secret, :site => ‘https://ws-api.onehub.com’, :ssl => {:verify => true}) do |b|
b.request :multipart
b.request :url_encoded
b.adapter Faraday.default_adapter
end

< handle all of the authentication here, e.g. token = OAuth2::AccessToken.new… >

Then, make the body from a local file in your directory:
pathname = ‘./logo_onehub_ws.png’

1.local file name ./logo_onehub_ws.png will be stored in folder FOLDER_ID as ‘foo1.png’
upload = Faraday::UploadIO.new(File.new(pathname,‘rb’), 
‘application/octet-stream’, ‘foo1.png’)

payload = { :file => { :name => File.basename(pathname), :‘form-data’ => upload } }

Post to the folder specified by its numeric ID
resp = token.post(“/folders/#{FOLDER_ID}/files.json”, body: payload)
you will get back a json payload with the file information in it.

Can any one help me how to Transfer files to FTP from Salesforce Attachment object.
 

I am trying to push image from salesforce to ONEHUB .But i am getting ERROR .

Can any have idea to how to do integration with One hub.

Please help me