• David Durant 5
  • NEWBIE
  • 15 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 8
    Replies
I have a test class and trigger that I have completed. Currently, it is giving me an error on the web services callout. I tried to do some research to understand why it was giving me this error. I know that the piclist field that I am referencing has a web service callout on the lead object but I am refereing to it on the opportunity.  I also do not know where or how to even set up the mock callout to allow myself to obtain code coverage. Can anybody offer any advice on where to start?

I read both 
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_testing_httpcalloutmock.htm

And 

https://help.salesforce.com/apex/HTViewSolution?id=000138850&language=en_US

I understand that I need to build a mock web service but I have no idea where to start. 


Here is my code:
@isTest
public class TestUtilityUpdate{
    static testMethod void myTest(){
        Account acc= new Account(name='Test - Properties');
        insert acc;
        
        set<String> strNames = new set<String>{'Los Angeles Department of Water and Power',
            'Adams Ranch',
            'Amarillo Mutual',
            'Anaheim, City of',
            'Arcadia, City of'
            };

        List<Opportunity> lstOpp = new List<Opportunity>();

        for(String str : strNames)
        {
           Opportunity opp = new Opportunity(Water_Agency__c=str,name=str,closedate=system.today(),stagename='Consult to be Scheduled',Accountid=acc.id);
            lstOpp.add(opp);
        }

insert lstOpp;
    
    }
}

 
I have a test class and trigger that I have completed. Currently, it is giving me an error on the web services callout. I tried to do some research to understand why it was giving me this error. I know that the piclist field that I am referencing has a web service callout on the lead object but I am refereing to it on the opportunity.  I also do not know where or how to even set up the mock callout to allow myself to obtain code coverage. Here is my code:
@isTest
public class TestUtilityUpdate{
    static testMethod void myTest(){
        Account acc= new Account(name='Test - Properties');
        insert acc;
        
        set<String> strNames = new set<String>{'Los Angeles Department of Water and Power',
            'Adams Ranch',
            'Amarillo Mutual',
            'Anaheim, City of',
            'Arcadia, City of'
            };

        List<Opportunity> lstOpp = new List<Opportunity>();

        for(String str : strNames)
        {
           Opportunity opp = new Opportunity(Water_Agency__c=str,name=str,closedate=system.today(),stagename='Consult to be Scheduled',Accountid=acc.id);
            lstOpp.add(opp);
        }

insert lstOpp;
    
    }
}

 
I am wondering if there is a better way for me to capture all of of the ID's I need instead of in indivudial list statements. Example below: 
list<Utility__c>  LADWPId           = new list<Utility__c>([SELECT Id FROM Utility__c WHERE Name='Los Angeles' Limit 1]);
    list<Utility__c>  ARMWCId           = new list<Utility__c>([SELECT Id FROM Utility__c WHERE Name='Adams Ranch Mutual Water Company' Limit 1]);
    list<Utility__c>  AMWCId            = new list<Utility__c>([SELECT Id FROM Utility__c WHERE Name='Amarillo' Limit 1]);
    list<Utility__c>  ANAHEIMId         = new list<Utility__c>([SELECT Id FROM Utility__c WHERE Name='Anaheim, City of' Limit 1]);
    list<Utility__c>  ARCADIAId         = new list<Utility__c>([SELECT Id FROM Utility__c WHERE Name='Arcadia, City of' Limit 1]);
    list<Utility__c>  AZUSATHREEId      = new list<Utility__c>([SELECT Id FROM Utility__c WHERE Name='Azusa (Three Valleys)' Limit 1]);
    list<Utility__c>  AZUSAUPPERId      = new list<Utility__c>([SELECT Id FROM Utility__c WHERE Name='Azusa' Limit 1]);
    list<Utility__c>  BELLFLOWERHGWCId  = new list<Utility__c>([SELECT Id FROM Utility__c WHERE Name='Bellflower' Limit 1]);
    list<Utility__c>  BELLFLOWERSMWCId  = new list<Utility__c>([SELECT Id FROM Utility__c WHERE Name='Bellflower-Somerset' Limit 1]);
    list<Utility__c>  BELLGARDENSId     = new list<Utility__c>([SELECT Id FROM Utility__c WHERE Name='Bell Gardens, City of' Limit 1]);
    list<Utility__c>  BERLYWOODId       = new list<Utility__c>([SELECT Id FROM Utility__c WHERE Name='Berylwood Heights' Limit 1]);
    list<Utility__c>  BEVERLYHILLSId    = new list<Utility__c>([SELECT Id FROM Utility__c WHERE Name='Beverly Hills, City of' Limit 1]);
Basically, I have a picklist on the opportunity page layout that holds about 240 values and I have a custom object with the same exact 240 values but ovbiously also holds more information about the individual cities.  I am inserting the lookup value into the page layout corresponding with the picklist value. For example, Picklist = Berlywood Heights, Lookup Field = Berlywood Heights.  I am going through in the trigger and capturing all the ID's I need and then inserting them into individual if, else if statements. The trigger is working great so far and I have coded about 60 of the cities in. I am wondering though if there is a way to in esence condense the code. Below is an example of how I am attaching the ID's to the if statment:
 
else if (o.Water_Agency__c == 'Berylwood Heights') {
              o.Organization_Name__c = BERLYWOODId[0].Id;

 
Currenlty, we are using a flow to pull data from the event into an opportunity. In a paricular situation which I cant identify a trend users are getting an error "Workflow failed to execute flow."

There is a lookup field on the event that links it to the opportunity. Basically, I can wash out the error by manually going into the stage and selecting consult scheduled and setting  a consultation date and it will allow me to hit save without an error. However, I still cant find out why there is an error in the first place. 

I have identified the particular flow and it is pictured below:
User-added image

I am sure you can do this a couple other ways one being the process builder but if there are any other suggesstions on how to get this done that would be great. 
I have a test class and trigger that I have completed. Currently, it is giving me an error on the web services callout. I tried to do some research to understand why it was giving me this error. I know that the piclist field that I am referencing has a web service callout on the lead object but I am refereing to it on the opportunity.  I also do not know where or how to even set up the mock callout to allow myself to obtain code coverage. Here is my code:
@isTest
public class TestUtilityUpdate{
    static testMethod void myTest(){
        Account acc= new Account(name='Test - Properties');
        insert acc;
        
        set<String> strNames = new set<String>{'Los Angeles Department of Water and Power',
            'Adams Ranch',
            'Amarillo Mutual',
            'Anaheim, City of',
            'Arcadia, City of'
            };

        List<Opportunity> lstOpp = new List<Opportunity>();

        for(String str : strNames)
        {
           Opportunity opp = new Opportunity(Water_Agency__c=str,name=str,closedate=system.today(),stagename='Consult to be Scheduled',Accountid=acc.id);
            lstOpp.add(opp);
        }

insert lstOpp;
    
    }
}

 
I am wondering if there is a better way for me to capture all of of the ID's I need instead of in indivudial list statements. Example below: 
list<Utility__c>  LADWPId           = new list<Utility__c>([SELECT Id FROM Utility__c WHERE Name='Los Angeles' Limit 1]);
    list<Utility__c>  ARMWCId           = new list<Utility__c>([SELECT Id FROM Utility__c WHERE Name='Adams Ranch Mutual Water Company' Limit 1]);
    list<Utility__c>  AMWCId            = new list<Utility__c>([SELECT Id FROM Utility__c WHERE Name='Amarillo' Limit 1]);
    list<Utility__c>  ANAHEIMId         = new list<Utility__c>([SELECT Id FROM Utility__c WHERE Name='Anaheim, City of' Limit 1]);
    list<Utility__c>  ARCADIAId         = new list<Utility__c>([SELECT Id FROM Utility__c WHERE Name='Arcadia, City of' Limit 1]);
    list<Utility__c>  AZUSATHREEId      = new list<Utility__c>([SELECT Id FROM Utility__c WHERE Name='Azusa (Three Valleys)' Limit 1]);
    list<Utility__c>  AZUSAUPPERId      = new list<Utility__c>([SELECT Id FROM Utility__c WHERE Name='Azusa' Limit 1]);
    list<Utility__c>  BELLFLOWERHGWCId  = new list<Utility__c>([SELECT Id FROM Utility__c WHERE Name='Bellflower' Limit 1]);
    list<Utility__c>  BELLFLOWERSMWCId  = new list<Utility__c>([SELECT Id FROM Utility__c WHERE Name='Bellflower-Somerset' Limit 1]);
    list<Utility__c>  BELLGARDENSId     = new list<Utility__c>([SELECT Id FROM Utility__c WHERE Name='Bell Gardens, City of' Limit 1]);
    list<Utility__c>  BERLYWOODId       = new list<Utility__c>([SELECT Id FROM Utility__c WHERE Name='Berylwood Heights' Limit 1]);
    list<Utility__c>  BEVERLYHILLSId    = new list<Utility__c>([SELECT Id FROM Utility__c WHERE Name='Beverly Hills, City of' Limit 1]);
Basically, I have a picklist on the opportunity page layout that holds about 240 values and I have a custom object with the same exact 240 values but ovbiously also holds more information about the individual cities.  I am inserting the lookup value into the page layout corresponding with the picklist value. For example, Picklist = Berlywood Heights, Lookup Field = Berlywood Heights.  I am going through in the trigger and capturing all the ID's I need and then inserting them into individual if, else if statements. The trigger is working great so far and I have coded about 60 of the cities in. I am wondering though if there is a way to in esence condense the code. Below is an example of how I am attaching the ID's to the if statment:
 
else if (o.Water_Agency__c == 'Berylwood Heights') {
              o.Organization_Name__c = BERLYWOODId[0].Id;