• rohan.chopra1.3941833609301624E12
  • NEWBIE
  • 0 Points
  • Member since 2014

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

Hi,

 

Has anyone is having experience on Salesforce integration with PayPal Using PayFlowPro gate way?

I want to do integration using HTTPS request.

I am new to Integartion. Can anyone plz suggest any link or source code?

 

Regards,

Nilesh.

I recently tried to package an app with custom settings. Unfortunately I couldn't write test methods because I wanted to create custom settings instances to test the various areas of my code. The error message I got is well known to me: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa).

 

Since inserting a Custom Settings object is a setup operation I can not create a custom settings and then proceed to create my test data. I tried creating my custom settings inside an @future method and this didn't work either (I did wrap my @future call with Test.startTest() and Test.stopTest() to ensure my @future method completed (i.e. to force synchornous execution). But I still got the same error message.

 

Ultimately what I did was write my code in such a way that the Class which relied on the custom settings had a local variable for the custom settings which I could set. In normal operation my code will query the custom settings using .getInstance() however my testMethods will all override this normal behavior and "force" set the custom settings.

 

My class which uses custom settings is below as is my class which tests my code. I hope you find this useful, and if you spot anything wrong with this please let me know. Thanks,

Caleb

 

------------ Class --------------

 public without sharing class CrossObjectUtil {
 private Map<Id,gii__AccountAdd__c> childrenToUpdateParent;
 private List<Account> parentsToUpdate;
 private Boolean isTest = false;

//This is the key!
 private CrossObjectSettings__c crossObjSettingsInstance = null;
 
 public CrossObjectUtil() {
  childrenToUpdateParent = new Map<Id,gii__AccountAdd__c>();
  parentsToUpdate = new List<Account>();
  setCrossObjectSettings(null);
 }

//Used by the test methods!

 public void setCrossObjectSettings(CrossObjectSettings__c cos) {
  if(cos == null) {
   CrossObjectSettings__c crossObjSettingsInstance = null;
   Map<String,CrossObjectSettings__c> crossObjSettingsInstanceMap = CrossObjectSettings__c.getAll();
   
   for(CrossObjectSettings__c cosInstance : crossObjSettingsInstanceMap.values()) {
    if(cosInstance.Child_Object_Name__c == 'gii__AccountAdd__c'&&
       cosInstance.Parent_Object_Name__c == 'Account') {
        crossObjSettingsInstance = cosInstance;
       }     
   }
  } else {
   crossObjSettingsInstance = cos;
  }
 }
 
 public void addChildToUpdateParent(Id parentId, gii__AccountAdd__c child) {
  childrenToUpdateParent.put(parentId,child);
 }

 public void updateParents() {
  if (childrenToUpdateParent.size() > 0) {
   updateParents(childrenToUpdateParent,false);
  }
 
  update parentsToUpdate;
 }
 
 private void updateParents(Map<Id,gii__AccountAdd__c> children,Boolean isDelete) {
  System.debug('updateParents: isDelete = ' + isDelete);
  for(Id parentId : children.keySet()) {
    SObject parent = new Account(Id=parentId);
    SObject child = children.get(parentId);
        
    if(crossObjSettingsInstance == null) {
     setCrossObjectSettings(null);
     if(crossObjSettingsInstance == null) {
      return;
     }
    }
    
    List<String> fieldMappings = crossObjSettingsInstance.Child_to_Parent_Field_Mapping__c.split(';',0);
    
    if(fieldMappings.size() == 0) return;
    
    for(String mapping : fieldMappings) {
     List<String> fields = mapping.split('=',0);
     if(fields.size() == 2) {
      if(!isDelete) {
       parent.put(fields[1],child.get(fields[0]));
      } else {
       parent.put(fields[1],null);
      }
     }
    }
    parentsToUpdate.add((Account)parent);
   } 
 }
}

 

-----------Test Method -------------

    static testMethod void test_CrossObjectUtil_Self() {
     Account a = insertAccount();
     gii__Warehouse__c w = insertWharehouse();
     gii__AccountAdd__c acctAdd = getAccountAdd(a,w);
    
      CrossObjectUtil coUtil = new CrossObjectUtil();

//Set the custom settings - the object is never saved!
      coUtil.setCrossObjectSettings(createCustomSettings());
        coUtil.addChildToUpdateParent(a.Id,acctAdd);
        coUtil.updateParents();
        Account assertAccount = [SELECT Name, Description FROM Account WHERE Id =:a.Id LIMIT 1];
        System.assertEquals(w.Id,assertAccount.Name);
        System.assertEquals(acctAdd.Name,assertAccount.Description);
    }
      
 //Notice that I do NOT insert the object! it's all in memory!
    static CrossObjectSettings__c createCustomSettings() {
     CrossObjectSettings__c crossObjSettingsInstance = new CrossObjectSettings__c(Name = 'Test Account Add to Account');
     crossObjSettingsInstance.Child_Object_Name__c = 'gii__AccountAdd__c';
     crossObjSettingsInstance.Parent_Object_Name__c = 'Account';
     crossObjSettingsInstance.Child_to_Parent_Field_Mapping__c = 'Name=Description;gii__DefaultWarehouse__c=Name';
     return crossObjSettingsInstance;
    }