• Satmetrix
  • NEWBIE
  • 0 Points
  • Member since 2011

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

Hi All,

 

We want to DO a HTTPpost with Certain data related to cases only when a case is closed.

Is it Possible and is there any example for the same?

 

Regards

Pradeep

Hi All,

 

I have a new apex class which can search for contacts from a page based on  the selected chack box.

but I am not able to write test methods.

 

Please help on this.

 

public class MassEmailFromContact{
public String aMessage {        get; set;       }

 
/* Constructor Function. The campaign id is captured in this function */
public MassEmailFromContact(ApexPages.StandardController controller)
{
/*cid=System.currentPageReference().getParameters().get('id');*/
}
/* Variable declarations */
Public String cid;    
           
            public list<cContact> contactList {get; set;}   
                             // Wrapper class which stores contact data and a boolean flag.public
                             public Boolean selectAllCheckbox {get; set;}                      
           // Stores checkbox data.public
           public Boolean errormsg=false;       
          String userinput;                            
               String userinp;                                                                                                                        // Contact EmailString userinp;                                                               // Contact NamePublic boolean displayboxes;
Public List<Contact> results = new List<Contact>();
                                     // Contact search results.
Public List<Contact> selectedContactsstep2 = new List<Contact>();     // Selcted Contacts
 /*End of variable declarations */
/* Getter and setter methods for getting the user input ie. Contact name and email from the UI */
public String getuserinput()
{
return userinput;
}
public void setuserinput(String userinp)
{
this.userinput=userinp;
}
public String getuserinp()
{
return userinp;
}
public void setuserinp(String userinp)
{
this.userinp=userinp;
}
/*End of Getter and Setter methods */
/* Method to Search the contact database to fetch the query results */
public List<Contact> contactsearch()

   errormsg=false; 
   contactList = new List<cContact>();
    for(Contact c : [select Account.Name,Name,FirstName,LastName,Email,Department,NPS__c,title,Id from Contact where Department like :userinput+'%' and Name like :userinp+'%'])
    {     
   contactList.add(new cContact(c)); 
   }
return null;
}
/* End of method */
/* Method for returning the contact search results to the UI */
public List<cContact> getresults()
{
 return contactList;
}
/* End of Method */
/* Wrapper class to contain contact record and a boolean flag */
public class cContact
{
public Contact con {get; set;}
public Boolean selected {get; set;}
 /*This is the contructor method. When we create a new cContact object we pass a Contact that is set to the con property. We also set the selected value to false*/
public cContact(Contact c)
 {  
  con = c;
    selected = false;
}
}
/* end of Wrapper class */
/* Method to fetch the selected records and send email to them */
public Pagereference processSelected()

List<Contact> selectedContacts = new List<Contact>();
 if (contactList!= null)
 {
    for(cContact cCon : getresults())
    {      
     if(cCon.selected == true)
        {       
             selectedContacts.add(cCon.con);
        }       
    }                    

    System.debug('These are the selected Contacts...');
   
 //   Integer numSelectedContacts = selectedContacts.size();
 //       Integer counter = 0;
   System.Debug(selectedContacts);
           String content = '';
  for(Contact con : selectedContacts)
        {
           content =  + con.ID  +'#' +  con.Email  + '#' + con.FirstName  + '#' + con.LastName  + '|' + content;
      }
  
    /*
    for (Integer i = 0, j = 0; i < 1000;i++)
    {
     strEmailIds = strEmailIds + '|' + i + '|' + 'crnvpwitness@gmail.com'
     strIDs  = strIDs + '|' + i + '|' + '1001';
    }
     */
    /*HttpRequest req = new HttpRequest();       
    Http http = new Http();         
    req.setHeader('content-type', 'UTF-8'); 
    req.setEndpoint('http://localhost:8080/Webservice/fetchVariables.jsp');
    req.setEndpoint('http://www.satmetrix.com/');
    req.setMethod('POST');
    req.setBody('emails='+EncodingUtil.urlEncode(strEmailIds, 'UTF-8'));             
    req.setBody('IDs='+EncodingUtil.urlEncode(strIDs , 'UTF-8')); 
     req.setBody('Firstnames='+EncodingUtil.urlEncode(strFirstNames , 'UTF-8')); 
      req.setBody('LastNames='+EncodingUtil.urlEncode(strLastNames , 'UTF-8')); 
    req.setCompressed(true);
    HttpResponse res = http.send(req);
    System.debug(res.toString()); */
    //Pagereference p=new Pagereference ('http://localhost:8080/Webservice/index.jsp?language=en_US&emailID=CRNVPWITNESS@GMAIL.COM');
    Pagereference p=new Pagereference ('http://localhost:8080/Webservice/fetchVariables.jsp');
    p.getParameters().put('content', EncodingUtil.urlEncode(content, 'UTF-8'));          
   // p.getParameters().put('IDs', EncodingUtil.urlEncode(strIDs , 'UTF-8'));
    //p.getParameters().put('FirstNames', EncodingUtil.urlEncode(strFirstNames , 'UTF-8'));
   // p.getParameters().put('LastNames', EncodingUtil.urlEncode(strLastNames , 'UTF-8'));  
            //Pagereference p=new Pagereference ('http://localhost:8080/Webservice/fetchVariables.jsp');
    return p;         
  }            
    else
        return new Pagereference ('/apex/Campaign');
}
public List<SelectOption> getItems()
{
 List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('YES','YES'));
 options.add(new SelectOption('NO','NO'));
 return options;
}
/* return error message if no contact is selected
*/
public boolean geterrormsg()
{
 return errormsg;
}   
       static testMethod void testAccountTrigger(){
       
        //First, prepare 200 contacts for the test data
        Account acct = new Account(name='test account');
        insert acct;
       
        Contact[] contactsToCreate = new Contact[]{};
        for(Integer x=0; x<200;x++){
            Contact ct = new Contact(AccountId=acct.Id,lastname='testing',firstname='apex');
            contactsToCreate.add(ct);
        }
       
        //Now insert data causing an contact trigger to fire.
        Test.startTest();
        insert contactsToCreate;
        Test.stopTest();   
   
}
     public Pagereference Cancel()
{    
  Pagereference p =new Pagereference('/');  
     return p;
}   

 

   }

Hi All Friends,


I wrote a new REST Web service which works well for an update while calling from out side.

But not able to package it,because it required test methods.

The below is the REST web service written in apex class.Please help write test methods.

 

Thanks
Pradeep

 

@RestResource(urlMapping='/Contacts/*')

global with sharing class MyRestResource {

@HttpPost

global static String doPost(RestRequest req, RestResponse res, String NPS)

 {

 String contactId= req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);

 Contact contact= [SELECT AccountID,NPS__c FROM Contact WHERE Id=:contactId];

contact.NPS__c= NPS; update contact; return contact.NPS__c;

}

 }