• vickim1.396005552708281E12
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 10
    Replies
Hi Guys,

I am currently creating a custom form on our personal website, the form mimics the opportunity form, and we create new opportunities from the form submission. 

I need to be able to retrive the Picklist field options from saleforce into our forms dropdown (some of the Picklist fields are custom fields), is there a way to do this, please keep in mind I cant just copy the choices from salesforce to our platform as the admin are always adding new choices to the Picklist in salesforce.


Thank you.
Hi Guys,

I have created 1 trigger and one class in sandbox, I have written 2 test classes for this, one test for the trigger and one test for the class.

When I run the 'test run' in Sandbox it say Class have 100% coverage, however when trying to deploy the code in prod I get errors saying coverage is only 50%

Code Below

Trigger :
trigger myTrigger on Opportunity (after update) {
    string prams;
	
    // partner portal auth details
    prams = 'userkey=salesforce';
    prams = prams + '&passkey=password';
    
    // action occured in saledforce
    prams = prams + '&action=OpportunityUpdated';
    
    for (Opportunity op: trigger.new) {
        Opportunity oldOpportunity = Trigger.oldMap.get(op.Id);
        
        prams = prams + '&id[]=' + op.Id; // Opportunity ID
        prams = prams + '&name[]=' + op.Name;
        prams = prams + '&oldName[]=' + oldOpportunity.Name; // previous Name
        prams = prams + '&stageName[]=' + op.StageName;
        prams = prams + '&oldStageName[]=' + oldOpportunity.StageName; // previous stage
        prams = prams + '&closeDate[]=' + op.CloseDate;
        prams = prams + '&oldCloseDate[]=' + oldOpportunity.CloseDate; // previous close date
        prams = prams + '&closeLostReason[]=' + op.Closed_Lost_Reason__c;
        prams = prams + '&ownerId[]=' + op.OwnerId;
       	
    }
    
    Sync.invokeUrlWithPost('http://myurl.com', prams); 
}

My class 
public class Sync{
    
    //Future annotation to mark the method as async.
    @Future(callout=true)
    public static void invokeUrlWithPost(string url, string prams){ 
        if(url.length() > 0 && prams.length() > 0){
            HttpRequest req = new HttpRequest();
            req.setMethod('POST');
            req.setEndpoint(url);
            req.setHeader('Content-Type', 'application/x-www-form-urlencoded'); 
            req.setBody(prams);
        
            Http http = new Http();
        
            try {
                HttpResponse res = http.send(req);
                system.debug('B:STATUS:'+res.getStatus());
            } catch(system.Exception e) {
                system.debug('B:Callout error:'+e);
            }
        }
        
    }
}

TEST CLASSES

testSync()
@isTest
public class testSync{

    static testMethod void testInvokeUrlWithPost(){
		String url = 'http://myurl.com';
        String prams;
            
        // partner portal auth details
        prams = 'userkey=salesforce';
        prams = prams + '&passkey=password';
        
        // action occured in saledforce
        prams = prams + '&action=testInvokeUrlWithPost&Name=test';
        
        test.startTest();
        System.assertEquals(url, 'http://myurl.com');
        
        Sync.invokeUrlWithPost(url, prams); 
        test.stopTest();
    }
    
    static testMethod void testInvokeUrlWithPost_noPrams(){
		String url = 'http://myurl.com';
        String prams = '';
                 
        test.startTest();
        Sync.invokeUrlWithPost(url, prams); 
        test.stopTest();
    }
    
    static testMethod void testInvokeUrlWithPost_invalidUrl(){
		String url = '';
        String prams;
        
        // partner portal auth details
        prams = 'userkey=salesforce';
        prams = prams + '&passkey=password';
        
        // action occured in saledforce
        prams = prams + '&action=testInvokeUrlWithPost&Name=test';
        
        test.startTest();
        Sync.invokeUrlWithPost(url, prams); 
        test.stopTest();
    }
    
}

test for my trigger
@isTest
public class testMyTrigger{

    static testMethod void testPurplePortalUpdate(){
		// create a new Opportunity
        Opportunity testOpp = new Opportunity( Name = 'My Test Opp', StageName = 'Qualification', CloseDate = System.today().addDays(4));
      	// insert it to the db
        insert  testOpp;
        
        // get the inserted Opportunity to edit it
        Opportunity oldOpp = [SELECT Name, StageName, CloseDate FROM Opportunity WHERE id = :testOpp.Id];
		
        // error if the Opportunity did not add
        System.assert(testOpp.Id != null, 'The Test opportunities did not insert properly, please check validation rules and other mechanisms');
        
        // change its name
        oldOpp.Name = 'Updated';
        System.assertEquals(oldOpp.Name, 'Updated');
        System.assertEquals(oldOpp.StageName, 'Qualification');

        // Start the test, this changes governor limit context to
    	// that of trigger rather than test.
        test.startTest();
        
        // update the Opportunity
        update oldOpp;

        // Stop the test, this changes limit context back to test from trigger
        test.stopTest();

    }   
    
    
}




Hi Guys,

I am currently creating a custom form on our personal website, the form mimics the opportunity form, and we create new opportunities from the form submission. 

I need to be able to retrive the Picklist field options from saleforce into our forms dropdown (some of the Picklist fields are custom fields), is there a way to do this, please keep in mind I cant just copy the choices from salesforce to our platform as the admin are always adding new choices to the Picklist in salesforce.


Thank you.
Hi Guys,

I have created 1 trigger and one class in sandbox, I have written 2 test classes for this, one test for the trigger and one test for the class.

When I run the 'test run' in Sandbox it say Class have 100% coverage, however when trying to deploy the code in prod I get errors saying coverage is only 50%

Code Below

Trigger :
trigger myTrigger on Opportunity (after update) {
    string prams;
	
    // partner portal auth details
    prams = 'userkey=salesforce';
    prams = prams + '&passkey=password';
    
    // action occured in saledforce
    prams = prams + '&action=OpportunityUpdated';
    
    for (Opportunity op: trigger.new) {
        Opportunity oldOpportunity = Trigger.oldMap.get(op.Id);
        
        prams = prams + '&id[]=' + op.Id; // Opportunity ID
        prams = prams + '&name[]=' + op.Name;
        prams = prams + '&oldName[]=' + oldOpportunity.Name; // previous Name
        prams = prams + '&stageName[]=' + op.StageName;
        prams = prams + '&oldStageName[]=' + oldOpportunity.StageName; // previous stage
        prams = prams + '&closeDate[]=' + op.CloseDate;
        prams = prams + '&oldCloseDate[]=' + oldOpportunity.CloseDate; // previous close date
        prams = prams + '&closeLostReason[]=' + op.Closed_Lost_Reason__c;
        prams = prams + '&ownerId[]=' + op.OwnerId;
       	
    }
    
    Sync.invokeUrlWithPost('http://myurl.com', prams); 
}

My class 
public class Sync{
    
    //Future annotation to mark the method as async.
    @Future(callout=true)
    public static void invokeUrlWithPost(string url, string prams){ 
        if(url.length() > 0 && prams.length() > 0){
            HttpRequest req = new HttpRequest();
            req.setMethod('POST');
            req.setEndpoint(url);
            req.setHeader('Content-Type', 'application/x-www-form-urlencoded'); 
            req.setBody(prams);
        
            Http http = new Http();
        
            try {
                HttpResponse res = http.send(req);
                system.debug('B:STATUS:'+res.getStatus());
            } catch(system.Exception e) {
                system.debug('B:Callout error:'+e);
            }
        }
        
    }
}

TEST CLASSES

testSync()
@isTest
public class testSync{

    static testMethod void testInvokeUrlWithPost(){
		String url = 'http://myurl.com';
        String prams;
            
        // partner portal auth details
        prams = 'userkey=salesforce';
        prams = prams + '&passkey=password';
        
        // action occured in saledforce
        prams = prams + '&action=testInvokeUrlWithPost&Name=test';
        
        test.startTest();
        System.assertEquals(url, 'http://myurl.com');
        
        Sync.invokeUrlWithPost(url, prams); 
        test.stopTest();
    }
    
    static testMethod void testInvokeUrlWithPost_noPrams(){
		String url = 'http://myurl.com';
        String prams = '';
                 
        test.startTest();
        Sync.invokeUrlWithPost(url, prams); 
        test.stopTest();
    }
    
    static testMethod void testInvokeUrlWithPost_invalidUrl(){
		String url = '';
        String prams;
        
        // partner portal auth details
        prams = 'userkey=salesforce';
        prams = prams + '&passkey=password';
        
        // action occured in saledforce
        prams = prams + '&action=testInvokeUrlWithPost&Name=test';
        
        test.startTest();
        Sync.invokeUrlWithPost(url, prams); 
        test.stopTest();
    }
    
}

test for my trigger
@isTest
public class testMyTrigger{

    static testMethod void testPurplePortalUpdate(){
		// create a new Opportunity
        Opportunity testOpp = new Opportunity( Name = 'My Test Opp', StageName = 'Qualification', CloseDate = System.today().addDays(4));
      	// insert it to the db
        insert  testOpp;
        
        // get the inserted Opportunity to edit it
        Opportunity oldOpp = [SELECT Name, StageName, CloseDate FROM Opportunity WHERE id = :testOpp.Id];
		
        // error if the Opportunity did not add
        System.assert(testOpp.Id != null, 'The Test opportunities did not insert properly, please check validation rules and other mechanisms');
        
        // change its name
        oldOpp.Name = 'Updated';
        System.assertEquals(oldOpp.Name, 'Updated');
        System.assertEquals(oldOpp.StageName, 'Qualification');

        // Start the test, this changes governor limit context to
    	// that of trigger rather than test.
        test.startTest();
        
        // update the Opportunity
        update oldOpp;

        // Stop the test, this changes limit context back to test from trigger
        test.stopTest();

    }   
    
    
}