• Spencer Widman
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
I am trying to finish a test class for an APEX class for use with FormAssembly and PayPal.  The original example I have is for the Opportunity Object.  My use case uses the Campaign Member.  Here is the original examples from FormAssembly :

https://help.formassembly.com/help/make-salesforce-and-paypal-work-together
 
public class IPNHandlerController {

    public PageReference myIPNupdate() {
     try{
        PageReference pageRef = ApexPages.currentPage();
        //Get the value of the 'custom' parameter from current page
        String paramCustom = pageRef.getParameters().get('custom');
        opportunity = [select Id,paid__c from Opportunity where FormAssemblyID__c = :paramCustom ];

        String content = '';
        for(String key : pageRef.getParameters().keySet()){
            //Note that there is no guarantee of order in the parameter key map.
            content += key + ' : ' + pageRef.getParameters().get(key) + '\n';
        }
        opportunity.PayPalInfo__c = content;
        opportunity.paid__c = True;
        update opportunity;

        PageReference newPage = new ApexPages.StandardController(opportunity).view();
        newPage.setRedirect(true);        

        return newPage;
     } catch (System.Exception e){
         //A failure occurred
         system.debug(e);
         return null;
     }
    }

    public Opportunity opportunity {get; set;}

    public IPNHandlerController() {
    }
}


 
@istest
private class IPNHandlerTestClass {
    public static testMethod void testMyIPNupdateSuccess(){
        IPNHandlerController ipn = new IPNHandlerController();

        Opportunity c = new Opportunity(Name='Test01',CloseDate=date.parse('1/1/2010'),StageName='Qualification',
FormAssemblyId__c='111111101111110z');
        insert c;
        ApexPages.currentPage().getParameters().put('custom', '111111101111110z');

        PageReference p = ipn.myIPNupdate();
        System.assertNotEquals(null,p);
    }

    public static testMethod void testMyIPNupdateFailure(){
        IPNHandlerController ipn = new IPNHandlerController();
        ApexPages.currentPage().getParameters().put('custom', '111111101111111z');
        PageReference p = ipn.myIPNupdate();
        System.assertEquals(null,p);
    }

    public static testMethod void testIPNHandlerController(){
        //You should customize this to fit your needs.
        System.assertEquals(true,true);
    }

}
and here is what I attempted to mimic for the CampaignMember Object.  Everything works fine in my Sandbox but when I attempt to deploy to Production I am getting a failure in my Test Class. 
 
public class IPNHandlerController {

    public PageReference myIPNupdate() {
     try{
        PageReference pageRef = ApexPages.currentPage();
        //Get the value of the 'custom' parameter from current page
        String paramCustom = pageRef.getParameters().get('custom');
        CampaignMember = [select Id,paid__c from CampaignMember where FormAssemblyID__c = :paramCustom ];

        String content = '';
        for(String key : pageRef.getParameters().keySet()){
            //Note that there is no guarantee of order in the parameter key map.
            content += key + ' : ' + pageRef.getParameters().get(key) + '\n';
        }
        CampaignMember.PayPalInfo__c = content;
        CampaignMember.paid__c = True;
        update CampaignMember;

        PageReference newPage = new ApexPages.StandardController(CampaignMember).view();
        newPage.setRedirect(true);

        return newPage;
     } catch (System.Exception e){
         //A failure occurred
         system.debug(e);
         return null;
     }
    }

    public CampaignMember CampaignMember {get; set;}

    public IPNHandlerController() {
    }
}

@istest
private class IPNHandlerTestClass {
    public static testMethod void testMyIPNupdateSuccess(){
        IPNHandlerController ipn = new IPNHandlerController();

        CampaignMember m1 = new CampaignMember (ContactId='1', CampaignId='1', Status='Sent');

        ApexPages.currentPage().getParameters().put('custom', '111111101111110z');

        PageReference p = ipn.myIPNupdate();
        System.assertNotEquals(null,p);
    }

    public static testMethod void testMyIPNupdateFailure(){
        IPNHandlerController ipn = new IPNHandlerController();
        ApexPages.currentPage().getParameters().put('custom', '111111101111111z');
        PageReference p = ipn.myIPNupdate();
        System.assertEquals(null,p);
    }

    public static testMethod void testIPNHandlerController(){
        //You should customize this to fit your needs.
        System.assertEquals(true,true);
    }

}
I am assuming it is a very simple mistake on my part due to the fact that this is new ground for me.  Can anyone help me out with a test class for a PayPal IPN Handler?

 
I have posted a similar question in the past.  I have since made progress and can get the example apex belwo to work perfectly.  I borrowed some knowledge from: 

https://www.salesforcezone.co.nz/2015/05/email-service-to-parse-csv.html?m=1 (https://www.salesforcezone.co.nz/2015/05/email-service-to-parse-csv.html?m=1)

It works exactly as advertised.  The difference in my use case is I have a list of contacts in a .csv file that I receive weekly.  The list has various contact fields as well as the salesforce contact ID's.  In addtion to the named salesforce fields it contains additional fields that will not be imported (I would like to ignore fields that I designate and only update the fields I specify).  I would like to utilize the salesforce ID to map or match the contacts and then perform an "update" on those contacts.  The example works great for "inserting" records but I have not found a good example or sample to backwards engineer and apply the update function to a list of contacts matched by the Contact ID.  Any details to accomplish this or a good example would be greatly appreciated.  Thanks in advance for the help!
 
I get sent emails with data in both the bodies and as a csv attachment with contact information that I need to update.  Currently I use the dataloader or the data import wizard and manually upload the information into our Org.  From the research I have done on the forums it appears that I can write an Apex class to parse the information from both the body of the email or an attachment and update the contact records with the appropriate information.  Looking for some examples or resources to write this in Apex so that my external partners can email an address and have the data update in my organzation.  Hopefully this makes sense on this post like it does in my head.  Any information or references would be greatly appreciated.  
I get sent emails with data in both the bodies and as a csv attachment with contact information that I need to update.  Currently I use the dataloader or the data import wizard and manually upload the information into our Org.  From the research I have done on the forums it appears that I can write an Apex class to parse the information from both the body of the email or an attachment and update the contact records with the appropriate information.  Looking for some examples or resources to write this in Apex so that my external partners can email an address and have the data update in my organzation.  Hopefully this makes sense on this post like it does in my head.  Any information or references would be greatly appreciated.