• Kamil Mieczakowski
  • NEWBIE
  • 60 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 14
    Replies
I have 5 different triggers calling out to different API services (I am using @future callouts) every time a new lead is added to Salesforce.

My concern is that when I bulk add say 500 leads to Salesforce with DataLoader (haven't tried yet) all those triggers will end up shooting a request out at the same time and I will exceed the rate limits (or at least seriously clog them) for the APIs that I am using ending up in 100s of failed triggers.

Is there a way to ensure that those triggers don't get fired all at once for each lead that is being added but instead respect the rate limits/proceed at a slower pace?
I am working on a project where I need to access values in a Google Sheet, scan them for certain keywords, and if they meet a particular condition, copy the data from a given row into an object in Salesforce. 

I am accessing a body of a Google Sheet using Google Sheets API and Apex. 

The problem that I am having is that each data row that I am getting from the Google Sheets file is a separate JSON file.

As you will see in the example below the keys are only located in the first JSON file, then each file that follows contains only values.

Is there a way to pair each JSON file that contains values (from 2nd one onwards) with the keys in the first file?

Here's how the response body looks like:
"range": "Angels!B2:AD2501",
      "majorDimension": "ROWS",
      "values": [
        [
          "Complete?",
          "Name",
          "ID :",
          "Source",
          "LinkedIn",
          "Twitter",
          "Profile",
          "",
          "AA Profile",
          "Email",
          "Location: City",
          "Location: Country",
          "Twitter Bio",
          "Bio",
          "Known For:",
          "Investments",
          "Preferred Industry",
          "Vertical",
          "Associated Venture Fund",
          "Type",
          "Total Investments",
          "Total Exits",
          "",
          "Priority",
          "Comments",
          "Email",
          "Contact Owner",
          "Account Owner",
          "In CRM"
        ],
        [
          "Yes",
          "John Doe",
          "2305",
          "CrowdSourced",
          "https://www.linkedin.com/in/someone-34738265",
          "",
          "",
          "",
          "https://angel.co/person",
          "",
          "Something",
          "UK",
          "",
          "Executive Manager",
          "Long term investor.",
          "list, of, companies, separated,by, a, comma",
          "IT, Advertising",
          "",
          "",
          "Person (individual)",
          "239",
          "16",
          "TRUE",
          "H"
        ],
        [
          "Yes",
          "A. Nikiforov",
          "766",
          "Pitchbook2",
          "https://www.linkedin.com/pub/dir/alexey/nikiforov",
          "",
          "https://my.pitchbook.com?i=106763-86",
          "",
          "",
          "gfm@polytechnics.spb.ru",
          "Saint Petersburg",
          "Russia",
          "",
          "Mr. A. Nikiforov is the Owner at Izdatelstvo Politekhnika. Mr. A. Nikiforov is the Owner at A. Nikiforov.",
          " ",
          "Izdatelstvo Politekhnika",
          "Media",
          "",
          "",
          "Angel (individual)",
          "1",
          "",
          "FALSE"
        ],
        [
          "Yes",
          "Aarish Patel",
          "1043",
          "Pitchbook2",
          "https://www.linkedin.com/in/aarish-patel-06387983",
          "",
          "https://my.pitchbook.com?i=151254-01",
          "",
          "",
          "",
          "",
          "",
          "",
          "Mr. Patel serves as the Non-Executive Director at Reds True Barbecue. He serves as the Angel Investor at Aarish Patel.",
          " ",
          "Reds True Barbecue",
          "Restaurants, Hotels and Leisure, Retail",
          "",
          "",
          "Angel (individual)",
          "1",
          "",
          "FALSE"
        ]];


As you can see in the example the keys are only located in the first JSON file, then each JSON file that follows contains values. 

Is there a way to pair each JSON file that contains values (from 2nd one onwards) with the keys in the first file? 
 
I am currently attempting to connect to Google Sheets API via OAuth2 with JWT. I am using Service Account Key, so Salesforce can pull the data from Google Sheets without the requirement for manual authorisation every time it sends out a query.
I am at the point where I set up the Service Account Key and I am successfully sending a request to it to obtain the access_code.

Then I am attempting to query the API, using the following class:
 
/****** API CALLOUT *******/
    public static HttpResponse googleSheetsCallout (){

      string accessCode = getAccessToken();
      string endpoint = 'https://sheets.googleapis.com/v4/spreadsheets/[SPREADSHEET_ID]/values/[VALUE_RANGE]&access_token=';
      httpRequest req = new httpRequest();
      req.setEndpoint(endpoint+accessCode);
      req.setMethod('GET');
      req.setTimeout(120000);
      httpResponse res = new http().send(req);
      System.debug ('res is ' +res);
      return res;

    }
When I run the function this is what the log returns:
​|CALLOUT_RESPONSE|[71]|System.HttpResponse[Status=Forbidden, StatusCode=403] 
|USER_DEBUG|[72]|DEBUG|res is System.HttpResponse[Status=Forbidden, StatusCode=403]

 
I am attempting to test the following callout method:
 
/******  CALLOUT  ******/
      public static HttpResponse MMarkAPIcallout(String domain){
        string endpoint = 'https://someapi.com/api/v5/company/dd/det?comp_id=';

        //get companyID using domain (this is a separate callout)
        string companyID = companyIDFetcher.companyIDFetcher(domain);

        //system.debug('companyID is' +companyID);
        httpRequest req = new httpRequest();


        req.setMethod('GET');

//set method as containing the endpoint + companyID
        req.setEndpoint(endpoint+companyID);

//set timeout
        req.setTimeout(120000);

        httpResponse res = new http().send(req);

        return res;
      }

And here's the test:
 
@isTest
private class MMarkAPITest {

    static testMethod void MMarkAPIUnitTest() {
        test.startTest();
        test.setMock(HttpCalloutMock.class, new MMarkAPITestHttpCalloutMock());

        // Call method to test.
        // This causes a fake response to be sent
        // from the class that implements HttpCalloutMock.
        MMarkAPIcallout('company.com');

        test.stopTest();
    }

}

However, when I run this test from the classes menu in 'Setup' I get the following error and no test coverage:
 
system.nullpointerexception attempt to dereference a null object salesforce



 
This is probably really easy but I am completely new to Salesforce and struggling to find any tutorials on this.
I have managed to deserialise a JSON object into the following wrapper:
 
public class MMark {

public class Funding {
    public String amount {get; set;}
    public String deal_currency {get; set;}
}

public class Data {
    public String name {get; set;}
    public String description {get; set;}
}

My plan now is to write a trigger class so that whenever a new lead is created and it contains a website, to grab the website variable and query an API containing additional information with it to then return a JSON file and deserialise it using the above class.
I want to use the deserialised data to populate custom fields in the Lead Object.
That's what I've got so far:
 
trigger MMarkBasicFields on Lead (after insert) {
                for (Lead l : Trigger.new){
        //if lead has a website            
        if (l.Website != ''){
        //create a variable containing the website
                        string domain = l.website;
        //invoke parser class
                        MMarkParser mmarkparser = new MMarkParser();
        //use it with the relevant domain
                        mmarkparser.parse(domain);
        //subsequently I want to access the individual values that have been 
//deserialised and update the custom 
 //   fields in the lead object with them but 
 //   I am not sure how to reference them...

                    }
                }   
            }

If anyone wonders here's my deserialise class:
 
public class MMarkParser {
    public MMarkMetadata.Company wrapper {
        get;
        set;
    }

    public void parse(string domain) {

        string companyID = companyIDFetcher.companyIDFetcher(domain);
        system.debug('company ID is'+companyID);

        HTTPRequest request = new HTTPRequest();
        request.setEndpoint('https://api.companies.com'+companyID);  
        request.setMethod('GET');

        HTTP h = new HTTP();
        HTTPResponse response = h.send(request);
        string strresponse = response.getBody();
        system.debug(strresponse);

        this.wrapper = (MMarkMetadata.Company) JSON.deserialize(response.getBody(), MMarkMetadata.Company.class);
        System.debug('wrapper data says----->'+wrapper);
    }
}

 
I am attempting to parse MatterMark's API, but I am planning to do so selectively, picking only the value pairs that are relevant. The example JSON response is available to be viewed in MatterMark's documentation (here).

Here's my Wrapper:
 
public class MMarkWrapper {
    public class mmark_company_profile {
        public string name {get;set;}
        public string description {get;set;}
        public string employees {get;set;}
        public string employees_6_months_ago {get;set;}
        public string last_funding_amount {get;set;}
        public string last_funding_date {get;set;}
        public string country {get;set;}
        public string total_funding {get;set;}
        public string acquired_by {get;set;}
        public List<mmark_funding_round> mmark_funding_rounds {get;set;}
        
    }
    public class mmark_funding_round {
        public string amount {get;set;}
        public string transaction_currency {get;set;}
        public string series {get;set;}
        public string funding_date {get;set;}
        public string investors {get;set;}
        
    }
    
    public List<mmark_company_profile> mmark_company_profile_list {get; set;}

}

And the Parser:
 
public class MMarkParser {
    public MMarkWrapper wrapper {
        get;
        set;
    }
    
    public void parse() {
        
        //request class
        HTTPRequest request = new HTTPRequest();
        request.setEndpoint(Label.MatterMarkAPI+'/domains/'+ 'marketinvoice.com' +'/companies?key=' +'c878f447941828d91d53ffbebae068cdb7624fb257cca98e2672e8148e039c1c');  
        request.setMethod('GET');
        
        //response class
        HTTP h = new HTTP();
        HTTPResponse response = h.send(request); 
        
        
        wrapper = (MMarkWrapper) JSON.deserialize(response.getBody(), MMarkWrapper.class);
        System.debug(wrapper);
        
    }
    
}

I am trying to get it displayed on this page, but all I am getting is a blank page...
 
<apex:page controller="MMarkParser">
    <apex:form >
        <apex:pageBlock title="MMarkParserResponse">
            <apex:pageBlockButtons >
                <apex:commandButton value="submit" action="{!parse}" reRender="mmark_company_profile"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection id="mmark_company_profile" columns="1">
                <apex:repeat value="{!wrapper.mmark_company_profile_list}" var="mmark_company_profile">
                    <apex:pageBlockSection columns="2">
                        <apex:facet name="header">Company {!mmark_company_profile.name}</apex:facet>
                        <apex:pageBlockSectionItem >
                            <apex:outputLabel value="Description" for="description" />
                            <apex:outputText value="{!mmark_company_profile.description}" id="description" />
                        </apex:pageBlockSectionItem>
                        <apex:pageBlockSectionItem >
                            <apex:outputLabel value="Employees" for="employees" />
                            <apex:outputText value="{!mmark_company_profile.employees}" id="employees" />
                        </apex:pageBlockSectionItem>
                    </apex:pageBlockSection>
                    <apex:pageBlockSection columns="1">
                        <apex:facet name="header">Funding {!mmark_company_profile.name} Series</apex:facet>
                        <apex:pageBlockTable value="{!mmark_company_profile.mmark_funding_rounds}" var="item" id="mmark_funding_rounds">
                            <apex:column value="{!item.amount}" headerValue="Amount" />
                            <apex:column value="{!item.transaction_currency}" headerValue="Transaction Currency" />
                            <apex:column value="{!item.series}" headerValue="Series" />
                            <apex:column value="{!item.funding_date}" headerValue="Funding Date" />
                        </apex:pageBlockTable>
                    </apex:pageBlockSection>
                </apex:repeat>
            </apex:pageBlockSection>
        </apex:pageBlock> 
    </apex:form>
</apex:page>

I've been trying to debug it with no success, any ideas why this may be not working?
I created the following class that updates the Websites field after a new website is added. It basically normalises it by removing 'http://', 'https://', and 'www'.

Here's the class:
 
trigger standardiseWebsitesTrigger on Account (after insert, after update ) {
    if(checkRecursive.runOnce()){
        
        Set<Id> AccIds = new Set<Id>();
        
        List<Account> acctsToUpdate = new List<Account>{};
            
            
            for (Account acc : Trigger.new){
                AccIds.add(acc.Id);
            }
        
        List<Account> accounts = [SELECT Id, Website FROM Account WHERE Id IN :AccIds];
        
        for (Account acc : accounts){
            string website = acc.Website;
            string hostDomain1 = 'http://';
            string hostDomain2 = 'https://';
            string justWWWAddress = 'www';       
            
            if (acc.Website.startsWith(hostDomain1) || acc.Website.startsWith(hostDomain2) && acctsToUpdate.isEmpty()){
                Url u = new Url(acc.Website);
                website = u.GetHost();
                acc.Website = u.getHost().replaceFirst('^(https?://www\\.|https?://|www\\.)','');
                acctsToUpdate.add(acc);
                
            }
            
            if(acc.Website.startsWith(justWWWAddress) && acctsToUpdate.isEmpty()){
                acc.website = website.substring(4);
                acctsToUpdate.add(acc);
                
            }
            
            update acctsToUpdate; 
            
        }
    }
    
    }

However when using the following test the assertion relating to removing the 'www.' component fails:
   
@isTest
    public class standardiseWebsitesTriggerTest {

    static testmethod void standardiseWebsiteTriggerHTTP() {
        testSetup('HTTP', 'http://I_AM_HTTP', true);
    }

    static testmethod void standardiseWebsitesTriggerWWW() {
        testSetup('WWW', 'WWW.I_AM_WWW', false);
    }

    public static void testSetup(String accName, String accWebsite, Boolean webProtocol) {
        Account acc = new Account(
            Name = accName,
            Website = accWebsite
        );
        insert acc;

        Account updatedAccount = [select Website from Account where id = :acc.Id];
        
        if(webProtocol) {
            Url u = new Url(acc.Website);
            System.assert(u.getHost() == updatedAccount.Website);
        } else {
            System.assert(updatedAccount.Website == acc.Website.substring(4));
        }
    }
    }

The error is:
 
>    Assertion failed
Class.standardiseWebsitesTriggerTest.testSetup: line 25, column 1
Class.standardiseWebsitesTriggerTest.standardiseWebsitesTriggerWWW: line 9, column 1

Any idea as to why this test may be failing?




 
Hi Guys, I wrote the below code and test method for it, but for some reason my test method is not providing sufficient coverage for deployment. I run out of ideas on how to increase the coverage of this test method. Any advice on how to do it?

Actual code:
public class  standardiseWebsites {
 
    public static void standardiseWebsites(){
    //extracting the host from the address for websites that have web-protocol (http:// and https://)
    list<Account> accts = [SELECT Website FROM Account WHERE Website LIKE 'http://%' OR Website LIKE 'https://%'];
        for (Account acct : accts){            
            string website = acct.Website;
            Url u = new Url(acct.Website);
            acct.Website = u.getHost();
            update acct;
        }
        
      //removing first 4 digits of the address if it starts with 'www.' (non-web-protocol values)
      list<Account> accts2 = [SELECT Website FROM Account WHERE Website LIKE 'www.%'];
        for (Account acct2 : accts2){
            string website = acct2.website;
            website = website.substring(4);
            acct2.website = website;
            update acct2;
        }
    }
}
Test:
@isTest
public class standardiseWebsitesTest {
 
        static void standardiseWebsitesTest() {
        standardiseWebsites.standardiseWebsites();
    }
}

 
Hi All, I am really baffled by this. When I run the below code as a simple method with no type it runs fine and websites in the database are being updated (code executes as desired). However, when I add the type of 'void' to the method, it seemingly runs fine without any errors but nothing happens in consequence (websites aren't updated/stripped of the desired components such as 'http', 'www', etc.

What is the reason behind this?

I believe this should be a void method type and I need it to be of void type for testing. If I change it to non-void it runs fine in Sandbox but then I cannot refer to it in the test.

​I am sorry if I am asking about something obvious, I am new to this game.

Here's the code (with 'void' type added to the method):
 
public class standardiseWebsites {
 
    public void standardiseWebsites(){
    //extracting the host from the address for websites that have web-protocol (http:// and https://)
    list<Account> accts = [SELECT Website FROM Account WHERE Website LIKE 'http://%' OR Website LIKE 'https://%'];
        for (Account acct : accts){            
            string website = acct.Website;
            Url u = new Url(acct.Website);
            acct.Website = u.getHost();
            update acct;
        }
        
      //removing first 4 digits of the address if it starts with 'www.' (non-web-protocol values)
      list<Account> accts2 = [SELECT Website FROM Account WHERE Website LIKE 'www.%'];
        for (Account acct2 : accts2){
            string website = acct2.website;
            website = website.substring(4);
            acct2.website = website;
            update acct2;
        }
    }
}



And the test for it:
 
@isTest
public class standardiseWebsitesTest {
    static testMethod void standardiseWebsitesTest(){
		
        //Run the test
		standardiseWebsites ca = new standardiseWebsites();
        ca.standardiseWebsites();
        
    }
}


 
Hi, I am attempting to write a simple test for a for loop that cleans the websites fields of unwanted elements such as 'http', 'www' etc. The script works for me but the test class that I wrote gets me 0% of coverage. Could anyone advise on what I am doing wrong? Thank you in advance.

Here's the actual script:
 
public class standardiseWebsites {
    list<Account> accts = [SELECT Website FROM Account];
    public standardiseWebsites(){
   
        for (Account acct : accts){
            string website = acct.website; 
        	website = website.replace('http://www.','');
            website = website.replace('https://www.','');
            website = website.replace('https://','');
            website = website.replace('http://','');
            website = website.replace('www.','');
            acct.website = website;
            update acct;
            
        }
    }
}

And here's the test script:
 
@isTest
public class standardiseWebsitesTest {
    static testMethod void standardiseWebsitesTest(){
        //Create test Accounts with various types of websites
        
        Account account1 = new Account(Name = 'Test Account1', Website='https://www.test.com');
        insert account1;
		Account account2 = new Account(Name = 'Test Account1', Website='http://www.test.com');
		insert account2;
		Account account3 = new Account(Name = 'Test Account1', Website='https://test.com');
		insert account3;                                      
		Account account4 = new Account(Name = 'Test Account1', Website='http://test.com');
		insert account4;
		Account account5 = new Account(Name = 'Test Account1', Website='www.test.com');                                                           
        insert account5;
		Account account6 = new Account(Name = 'Test Account1', Website='test.com');                                                           
        insert account6;

        Test.startTest();
        
        System.debug(accts);
		StandardiseWebsitesTest obj = new standardiseWebsitesTest();
		
        Test.stopTest();
        
        //Check the desired results
        system.assertEquals(Account1.Website,'test.com');
        system.assertEquals(Account2.Website,'test.com');            
        system.assertEquals(Account3.Website,'test.com');            
        system.assertEquals(Account4.Website,'test.com');
        system.assertEquals(Account5.Website,'test.com');            
        system.assertEquals(Account6.Website,'test.com');        
        
        
        
    }

}

 
Hi All,

I am currently putting together an Apex script that would normalise all of the website addresses in our database by extracting the host addres and eliminating 'http', 'www' etc from the domain address. For this I am using a for loop. The problem that I am experiencing is that once the code runs (and it runs without errors and the debug produces the desired outcome) the website addresses don't get updated.

Here's the script so far:
public class Standardise_Websites {
    public Standardise_Websites(){
        list<Account> accts = [SELECT Website FROM Account];
               
        for (Account acct : accts){
            string website = acct.website;
            System.debug('Website is ---------->' +website);  
            website = website.replace('http://www.','');
            website = website.replace('https://www.','');
            website = website.replace('https://','');
            website = website.replace('http://','');
            website = website.replace('www.','');
            System.debug('Final website is ---------->' +website); 
            update acct;
            
        }
    update accts;
    }
}

               
    
I am working on creating a workflow that updates a tickbox field (to TRUE) whenever the Account Owner changes from a specific one to a new one (any owner).

Here's the formula I came up with:

Record Type: Account
Evaluation: Evaluate the rule when a record is created, or edited

Formula evaluates to TRUE:

AND(
ISCHANGED(OwnerId),
PRIORVALUE( OwnerId)= "XXXXXXXXXXXXXXXX"
)

When checking its syntax Salesforce doesn't report any errors. However, when checking the workflow in action (it's been activated) the tick box  doesn't get ticked.

Any ideas as to why the workflow may not be working?
I am working on a project where I need to access values in a Google Sheet, scan them for certain keywords, and if they meet a particular condition, copy the data from a given row into an object in Salesforce. 

I am accessing a body of a Google Sheet using Google Sheets API and Apex. 

The problem that I am having is that each data row that I am getting from the Google Sheets file is a separate JSON file.

As you will see in the example below the keys are only located in the first JSON file, then each file that follows contains only values.

Is there a way to pair each JSON file that contains values (from 2nd one onwards) with the keys in the first file?

Here's how the response body looks like:
"range": "Angels!B2:AD2501",
      "majorDimension": "ROWS",
      "values": [
        [
          "Complete?",
          "Name",
          "ID :",
          "Source",
          "LinkedIn",
          "Twitter",
          "Profile",
          "",
          "AA Profile",
          "Email",
          "Location: City",
          "Location: Country",
          "Twitter Bio",
          "Bio",
          "Known For:",
          "Investments",
          "Preferred Industry",
          "Vertical",
          "Associated Venture Fund",
          "Type",
          "Total Investments",
          "Total Exits",
          "",
          "Priority",
          "Comments",
          "Email",
          "Contact Owner",
          "Account Owner",
          "In CRM"
        ],
        [
          "Yes",
          "John Doe",
          "2305",
          "CrowdSourced",
          "https://www.linkedin.com/in/someone-34738265",
          "",
          "",
          "",
          "https://angel.co/person",
          "",
          "Something",
          "UK",
          "",
          "Executive Manager",
          "Long term investor.",
          "list, of, companies, separated,by, a, comma",
          "IT, Advertising",
          "",
          "",
          "Person (individual)",
          "239",
          "16",
          "TRUE",
          "H"
        ],
        [
          "Yes",
          "A. Nikiforov",
          "766",
          "Pitchbook2",
          "https://www.linkedin.com/pub/dir/alexey/nikiforov",
          "",
          "https://my.pitchbook.com?i=106763-86",
          "",
          "",
          "gfm@polytechnics.spb.ru",
          "Saint Petersburg",
          "Russia",
          "",
          "Mr. A. Nikiforov is the Owner at Izdatelstvo Politekhnika. Mr. A. Nikiforov is the Owner at A. Nikiforov.",
          " ",
          "Izdatelstvo Politekhnika",
          "Media",
          "",
          "",
          "Angel (individual)",
          "1",
          "",
          "FALSE"
        ],
        [
          "Yes",
          "Aarish Patel",
          "1043",
          "Pitchbook2",
          "https://www.linkedin.com/in/aarish-patel-06387983",
          "",
          "https://my.pitchbook.com?i=151254-01",
          "",
          "",
          "",
          "",
          "",
          "",
          "Mr. Patel serves as the Non-Executive Director at Reds True Barbecue. He serves as the Angel Investor at Aarish Patel.",
          " ",
          "Reds True Barbecue",
          "Restaurants, Hotels and Leisure, Retail",
          "",
          "",
          "Angel (individual)",
          "1",
          "",
          "FALSE"
        ]];


As you can see in the example the keys are only located in the first JSON file, then each JSON file that follows contains values. 

Is there a way to pair each JSON file that contains values (from 2nd one onwards) with the keys in the first file? 
 
I am currently attempting to connect to Google Sheets API via OAuth2 with JWT. I am using Service Account Key, so Salesforce can pull the data from Google Sheets without the requirement for manual authorisation every time it sends out a query.
I am at the point where I set up the Service Account Key and I am successfully sending a request to it to obtain the access_code.

Then I am attempting to query the API, using the following class:
 
/****** API CALLOUT *******/
    public static HttpResponse googleSheetsCallout (){

      string accessCode = getAccessToken();
      string endpoint = 'https://sheets.googleapis.com/v4/spreadsheets/[SPREADSHEET_ID]/values/[VALUE_RANGE]&access_token=';
      httpRequest req = new httpRequest();
      req.setEndpoint(endpoint+accessCode);
      req.setMethod('GET');
      req.setTimeout(120000);
      httpResponse res = new http().send(req);
      System.debug ('res is ' +res);
      return res;

    }
When I run the function this is what the log returns:
​|CALLOUT_RESPONSE|[71]|System.HttpResponse[Status=Forbidden, StatusCode=403] 
|USER_DEBUG|[72]|DEBUG|res is System.HttpResponse[Status=Forbidden, StatusCode=403]

 
I am attempting to test the following callout method:
 
/******  CALLOUT  ******/
      public static HttpResponse MMarkAPIcallout(String domain){
        string endpoint = 'https://someapi.com/api/v5/company/dd/det?comp_id=';

        //get companyID using domain (this is a separate callout)
        string companyID = companyIDFetcher.companyIDFetcher(domain);

        //system.debug('companyID is' +companyID);
        httpRequest req = new httpRequest();


        req.setMethod('GET');

//set method as containing the endpoint + companyID
        req.setEndpoint(endpoint+companyID);

//set timeout
        req.setTimeout(120000);

        httpResponse res = new http().send(req);

        return res;
      }

And here's the test:
 
@isTest
private class MMarkAPITest {

    static testMethod void MMarkAPIUnitTest() {
        test.startTest();
        test.setMock(HttpCalloutMock.class, new MMarkAPITestHttpCalloutMock());

        // Call method to test.
        // This causes a fake response to be sent
        // from the class that implements HttpCalloutMock.
        MMarkAPIcallout('company.com');

        test.stopTest();
    }

}

However, when I run this test from the classes menu in 'Setup' I get the following error and no test coverage:
 
system.nullpointerexception attempt to dereference a null object salesforce



 
I am attempting to parse MatterMark's API, but I am planning to do so selectively, picking only the value pairs that are relevant. The example JSON response is available to be viewed in MatterMark's documentation (here).

Here's my Wrapper:
 
public class MMarkWrapper {
    public class mmark_company_profile {
        public string name {get;set;}
        public string description {get;set;}
        public string employees {get;set;}
        public string employees_6_months_ago {get;set;}
        public string last_funding_amount {get;set;}
        public string last_funding_date {get;set;}
        public string country {get;set;}
        public string total_funding {get;set;}
        public string acquired_by {get;set;}
        public List<mmark_funding_round> mmark_funding_rounds {get;set;}
        
    }
    public class mmark_funding_round {
        public string amount {get;set;}
        public string transaction_currency {get;set;}
        public string series {get;set;}
        public string funding_date {get;set;}
        public string investors {get;set;}
        
    }
    
    public List<mmark_company_profile> mmark_company_profile_list {get; set;}

}

And the Parser:
 
public class MMarkParser {
    public MMarkWrapper wrapper {
        get;
        set;
    }
    
    public void parse() {
        
        //request class
        HTTPRequest request = new HTTPRequest();
        request.setEndpoint(Label.MatterMarkAPI+'/domains/'+ 'marketinvoice.com' +'/companies?key=' +'c878f447941828d91d53ffbebae068cdb7624fb257cca98e2672e8148e039c1c');  
        request.setMethod('GET');
        
        //response class
        HTTP h = new HTTP();
        HTTPResponse response = h.send(request); 
        
        
        wrapper = (MMarkWrapper) JSON.deserialize(response.getBody(), MMarkWrapper.class);
        System.debug(wrapper);
        
    }
    
}

I am trying to get it displayed on this page, but all I am getting is a blank page...
 
<apex:page controller="MMarkParser">
    <apex:form >
        <apex:pageBlock title="MMarkParserResponse">
            <apex:pageBlockButtons >
                <apex:commandButton value="submit" action="{!parse}" reRender="mmark_company_profile"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection id="mmark_company_profile" columns="1">
                <apex:repeat value="{!wrapper.mmark_company_profile_list}" var="mmark_company_profile">
                    <apex:pageBlockSection columns="2">
                        <apex:facet name="header">Company {!mmark_company_profile.name}</apex:facet>
                        <apex:pageBlockSectionItem >
                            <apex:outputLabel value="Description" for="description" />
                            <apex:outputText value="{!mmark_company_profile.description}" id="description" />
                        </apex:pageBlockSectionItem>
                        <apex:pageBlockSectionItem >
                            <apex:outputLabel value="Employees" for="employees" />
                            <apex:outputText value="{!mmark_company_profile.employees}" id="employees" />
                        </apex:pageBlockSectionItem>
                    </apex:pageBlockSection>
                    <apex:pageBlockSection columns="1">
                        <apex:facet name="header">Funding {!mmark_company_profile.name} Series</apex:facet>
                        <apex:pageBlockTable value="{!mmark_company_profile.mmark_funding_rounds}" var="item" id="mmark_funding_rounds">
                            <apex:column value="{!item.amount}" headerValue="Amount" />
                            <apex:column value="{!item.transaction_currency}" headerValue="Transaction Currency" />
                            <apex:column value="{!item.series}" headerValue="Series" />
                            <apex:column value="{!item.funding_date}" headerValue="Funding Date" />
                        </apex:pageBlockTable>
                    </apex:pageBlockSection>
                </apex:repeat>
            </apex:pageBlockSection>
        </apex:pageBlock> 
    </apex:form>
</apex:page>

I've been trying to debug it with no success, any ideas why this may be not working?
Hi Guys, I wrote the below code and test method for it, but for some reason my test method is not providing sufficient coverage for deployment. I run out of ideas on how to increase the coverage of this test method. Any advice on how to do it?

Actual code:
public class  standardiseWebsites {
 
    public static void standardiseWebsites(){
    //extracting the host from the address for websites that have web-protocol (http:// and https://)
    list<Account> accts = [SELECT Website FROM Account WHERE Website LIKE 'http://%' OR Website LIKE 'https://%'];
        for (Account acct : accts){            
            string website = acct.Website;
            Url u = new Url(acct.Website);
            acct.Website = u.getHost();
            update acct;
        }
        
      //removing first 4 digits of the address if it starts with 'www.' (non-web-protocol values)
      list<Account> accts2 = [SELECT Website FROM Account WHERE Website LIKE 'www.%'];
        for (Account acct2 : accts2){
            string website = acct2.website;
            website = website.substring(4);
            acct2.website = website;
            update acct2;
        }
    }
}
Test:
@isTest
public class standardiseWebsitesTest {
 
        static void standardiseWebsitesTest() {
        standardiseWebsites.standardiseWebsites();
    }
}

 
Hi All, I am really baffled by this. When I run the below code as a simple method with no type it runs fine and websites in the database are being updated (code executes as desired). However, when I add the type of 'void' to the method, it seemingly runs fine without any errors but nothing happens in consequence (websites aren't updated/stripped of the desired components such as 'http', 'www', etc.

What is the reason behind this?

I believe this should be a void method type and I need it to be of void type for testing. If I change it to non-void it runs fine in Sandbox but then I cannot refer to it in the test.

​I am sorry if I am asking about something obvious, I am new to this game.

Here's the code (with 'void' type added to the method):
 
public class standardiseWebsites {
 
    public void standardiseWebsites(){
    //extracting the host from the address for websites that have web-protocol (http:// and https://)
    list<Account> accts = [SELECT Website FROM Account WHERE Website LIKE 'http://%' OR Website LIKE 'https://%'];
        for (Account acct : accts){            
            string website = acct.Website;
            Url u = new Url(acct.Website);
            acct.Website = u.getHost();
            update acct;
        }
        
      //removing first 4 digits of the address if it starts with 'www.' (non-web-protocol values)
      list<Account> accts2 = [SELECT Website FROM Account WHERE Website LIKE 'www.%'];
        for (Account acct2 : accts2){
            string website = acct2.website;
            website = website.substring(4);
            acct2.website = website;
            update acct2;
        }
    }
}



And the test for it:
 
@isTest
public class standardiseWebsitesTest {
    static testMethod void standardiseWebsitesTest(){
		
        //Run the test
		standardiseWebsites ca = new standardiseWebsites();
        ca.standardiseWebsites();
        
    }
}


 
Hi, I am attempting to write a simple test for a for loop that cleans the websites fields of unwanted elements such as 'http', 'www' etc. The script works for me but the test class that I wrote gets me 0% of coverage. Could anyone advise on what I am doing wrong? Thank you in advance.

Here's the actual script:
 
public class standardiseWebsites {
    list<Account> accts = [SELECT Website FROM Account];
    public standardiseWebsites(){
   
        for (Account acct : accts){
            string website = acct.website; 
        	website = website.replace('http://www.','');
            website = website.replace('https://www.','');
            website = website.replace('https://','');
            website = website.replace('http://','');
            website = website.replace('www.','');
            acct.website = website;
            update acct;
            
        }
    }
}

And here's the test script:
 
@isTest
public class standardiseWebsitesTest {
    static testMethod void standardiseWebsitesTest(){
        //Create test Accounts with various types of websites
        
        Account account1 = new Account(Name = 'Test Account1', Website='https://www.test.com');
        insert account1;
		Account account2 = new Account(Name = 'Test Account1', Website='http://www.test.com');
		insert account2;
		Account account3 = new Account(Name = 'Test Account1', Website='https://test.com');
		insert account3;                                      
		Account account4 = new Account(Name = 'Test Account1', Website='http://test.com');
		insert account4;
		Account account5 = new Account(Name = 'Test Account1', Website='www.test.com');                                                           
        insert account5;
		Account account6 = new Account(Name = 'Test Account1', Website='test.com');                                                           
        insert account6;

        Test.startTest();
        
        System.debug(accts);
		StandardiseWebsitesTest obj = new standardiseWebsitesTest();
		
        Test.stopTest();
        
        //Check the desired results
        system.assertEquals(Account1.Website,'test.com');
        system.assertEquals(Account2.Website,'test.com');            
        system.assertEquals(Account3.Website,'test.com');            
        system.assertEquals(Account4.Website,'test.com');
        system.assertEquals(Account5.Website,'test.com');            
        system.assertEquals(Account6.Website,'test.com');        
        
        
        
    }

}

 
I am working on creating a workflow that updates a tickbox field (to TRUE) whenever the Account Owner changes from a specific one to a new one (any owner).

Here's the formula I came up with:

Record Type: Account
Evaluation: Evaluate the rule when a record is created, or edited

Formula evaluates to TRUE:

AND(
ISCHANGED(OwnerId),
PRIORVALUE( OwnerId)= "XXXXXXXXXXXXXXXX"
)

When checking its syntax Salesforce doesn't report any errors. However, when checking the workflow in action (it's been activated) the tick box  doesn't get ticked.

Any ideas as to why the workflow may not be working?