• Salah Odeh 10
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 11
    Replies
Hello Everyone,

We have an integration with box that brings back URL share links. We have developed an Apex class that is working fine, but our test class is not having the coverage we need. Below are the Apex Class & the Test Class. It looks like the test class is not covering Try & Catch method. Please let us know if you can direct us to the right direction.
Apex Class:
 
Hello Developers,

I'm trying to set up our company social sign in with facebook and google, one of the steps is to update the autocreated handler for facebook, I need help with writing a test class for this handler and would appreciate any help. Here is the facebook handler I'm trying to write a test class for:

​​​​​​/** FaceBook Registration Handler example **/ global class SimpleFacebookRegistrationHandler implements Auth.RegistrationHandler{ private static final String ORG_SUFFIX = '.sso.badge.org'; private static final String DEFAULT_ACCOUNTNAME = 'Customers'; private static final String EXTERNAL_USER_PROFILE = 'Customers'; private static final String INTERNAL_USER_PROFILE = 'Standard User'; /** * Let anyone register as long as the required fields are supplied * * We require email, lastName, firstName * * @data - the user's info from the Auth Provider **/ global boolean canCreateUser(Auth.UserData data) { System.debug('canCreateUser was called for ' + (data != null ? data.email : 'null')); Boolean retVal = (data != null && data.email != null && data.lastName != null && data.firstName != null); System.debug('data.username='+data.username); System.debug('data.email='+data.email); System.debug('data.lastName='+data.lastName); System.debug('data.firstName='+data.firstName); return retVal; } /** * Create the User - A required method to implement the Handler Interface * * @param portalId - Id of the Community * @param data - Auth Provider user data describing the User to create * * @return User that has been initialized **/ global User createUser(Id portalId, Auth.UserData data){ if(!canCreateUser(data)) { // Returning null signals the auth framework we can't create the user return null; } // Is this a Community Context? if(data.attributeMap.containsKey('sfdc_networkid')) { System.debug('Registering Community user: ' + data.email); Id contactId; // To keep things modular, we're creating the Contact in a separate method contactId = createContact(data); System.debug('Created contact: '+ contactId); // You'd likely use other logic to assign the Profile Profile p = [SELECT Id FROM profile WHERE name=:EXTERNAL_USER_PROFILE]; System.debug('Found profile: '+ p); // Keeping it modular, we initialize the user in another method User u = createUser(data,p); u.contactId = contactId; return u; } else { //This is not a community, so we Assign an internal profile Profile p = [SELECT Id FROM profile WHERE name=:INTERNAL_USER_PROFILE]; System.debug('Found profile: '+ p); // Keeping it modular, we initialize the user in another method User u = createUser(data,p); return u; } } /** * Update the user * @param portalId - Id of the Community * @param data - Auth Provider user data describing the User to create **/ global void updateUser(Id userId, Id portalId, Auth.UserData data){ System.debug('Update User called for: ' + data.email); User u = new User(id=userId); u.email = data.email; u.lastName = data.lastName; u.firstName = data.firstName; update(u); } /** * Create a Contact * * @param data - Facebook provided context for the User **/ private Id createContact(Auth.UserData data){ Contact contact = new Contact(); contact.LastName = data.lastName; contact.FirstName = data.firstName; contact.Email = data.email; // set Account Id if (data.attributemap.get('accountId') != null){ contact.accountId = data.attributemap.get('accountId'); } else { List<Account> accounts = [select Id from Account where Name =:DEFAULT_ACCOUNTNAME]; System.debug('Found account: ' + accounts); contact.accountId = accounts[0].Id; } insert contact; System.debug('Contact created for ' + data.email + ' id=' + contact.id); return contact.id; } /** * Create and initialize the User but don't save it yet * * @param data - the provided User context from FaceBook * @param p - the Profile we are going to assign to this user * * @return User that has been initialized but not Saved **/ private User createUser(Auth.UserData data, Profile p) { User u = new User(); u.username = data.email + ORG_SUFFIX; u.email = data.email; u.lastName = data.lastName; u.firstName = data.firstName; String alias = data.firstName + data.lastName; //Alias must be 8 characters or less if(alias.length() > 8) { alias = alias.substring(0, 8); } u.alias = alias; u.languagelocalekey = UserInfo.getLocale(); u.localesidkey = UserInfo.getLocale(); u.emailEncodingKey = 'UTF-8'; u.timeZoneSidKey = 'America/Los_Angeles'; u.profileId = p.Id; return u; } }
Hello,

I have the following Visualforce page along wiht Apex Controller and Test Class. When I run the test class the coverage for Apex Controller is 0%, any idea on how to solve this issue:

Visualforce Page:

<apex:page standardController="Bid_Summaries__c" recordSetVar="Bid_Summaries__c" extensions="BidSummariesController"> <apex:pageBlock title="Bid Summary"> <apex:slds /> <style type="text/css"> body {background-color: white;} p { font-weight: bold; } p { font-style: italic;} h1 { color: #f00; } p { background-color: #eec; } newLink { color: #f60; font-weight: bold; } </style> <apex:page lightningStylesheets="true"/> <apex:form > <apex:pageBlockTable value="{! Bid_Summaries__c }" var="b"> <apex:column value="{! b.Name }"/> <apex:column value="{! b.Original_Budget__c }"/> <apex:column value="{! b.Upgrade_Amount__c }"/> <apex:column value="{! b.Budget_incl_Upgrades__c }"/> <apex:column value="{! b.TJH_Service_Fee__c }"/> <apex:column value="{! b.Concession__c }"/> <apex:column value="{! b.Upgrade_Total__c}"/> </apex:pageBlockTable> </apex:form> </apex:pageBlock> </apex:page>

Apex Controller:

​​​​​​public class BidSummariesController {

    public BidSummariesController(ApexPages.StandardController controller) {

    }

        public List<Bid_Summaries__c> Bid {get; set;}
        public BidSummariesController(){
        List<Bid_Summaries__c> Bid= [Select Id, Selected_Option__c,Concession__c, Status__c,TJH_Service_Fee__c,
                                    Upgrade_Amount__c,Upgrade_Total__c, Original_Budget__c From Bid_Summaries__c] ;
    }
                       PageReference pageRef = Page.BidSummary1;                    
                       public list <Bid_Summaries__c> getBid(){
                                              
                       return Bid;
                       
        }
    
    }


Test Class:

@isTest 

    public class BidSummariesControllertest {
        
        private static testMethod void BidSummariesController() {
            
         test.StartTest();
            
         Bid_Summaries__c b = new Bid_Summaries__c();
         
         b.Upgrade_Amount__c     = 1000;
         b.Concession__c         = 1000;         
         b.Original_Budget__c = 100;
         b.Status__c  = 'New';
            
            Insert b;
            
         
          
           test.stopTest(); 
        PageReference pageRef = Page.BidSummary1;
        Test.setCurrentPage(pageRef);
        ApexPages.StandardController sc = new ApexPages.StandardController(b);
        
      
             
           
             
            List<Bid_Summaries__c> Bids = [Select Id, Selected_Option__c,Concession__c, Status__c,TJH_Service_Fee__c,
                                    Upgrade_Amount__c,Upgrade_Total__c, Original_Budget__c From Bid_Summaries__c ];
                    
                    Update Bids;
            
            
            
        } 
        
        List<Bid_Summaries__c> Bids = New List<Bid_Summaries__c>();
             
               
                                    
          
        }
Here is my visualforce page:
​​​​​​<apex:page standardController="Bid_Summaries__c">
    <apex:pageBlock title="Bid Summary">
    <apex:slds />
    <style type="text/css">
        body {background-color: white;}
        p { font-weight: bold; }
        p { font-style: italic;}
        h1 { color: #f00; }
        p { background-color: #eec; }
        newLink { color: #f60; font-weight: bold; }   
    </style>
            <apex:page lightningStylesheets="true"/>  
            <apex:form >       
            <apex:pageBlockTable value="{! Bid_Summaries__c }" var="Bid_Summaries__c">
            <apex:column value="{! Bid_Summaries__c.Name }"/>                  
            <apex:column value="{! Bid_Summaries__c.Original_Budget__c }"/>
            <apex:column value="{! Bid_Summaries__c.Upgrade_Amount__c }"/>
            <apex:column value="{! Bid_Summaries__c.Budget_incl_Upgrades__c }"/>
            <apex:column value="{! Bid_Summaries__c.TJH_Service_Fee__c }"/>
            <apex:column value="{! Bid_Summaries__c.Concession__c }"/>
            <apex:column value="{! Bid_Summaries__c.Upgrade_Total__c}"/>
            </apex:pageBlockTable>
            </apex:form>
      </apex:pageBlock>
</apex:page>

What I'm trying to do is dynamically populate the value of the Bid_Summaries__c object fields on a visualforce page where any changes to the fields in that object will reflect in realtime to the visualforce page. The Bid_Summaries__c object is showing on a record list on the community as Kanaban list, users are able to move the field to select options and change prices. The point is once a user change those fields it will reflect on the visualforce page dynamicly without the need to refresh the page. Any ideas on how to write the apex controller and test class, or if there is any other way to accomplish this. Thanks
Hello Everyone,

We have an integration with box that brings back URL share links. We have developed an Apex class that is working fine, but our test class is not having the coverage we need. Below are the Apex Class & the Test Class. It looks like the test class is not covering Try & Catch method. Please let us know if you can direct us to the right direction.
Apex Class:
 
Hello,

I have the following Visualforce page along wiht Apex Controller and Test Class. When I run the test class the coverage for Apex Controller is 0%, any idea on how to solve this issue:

Visualforce Page:

<apex:page standardController="Bid_Summaries__c" recordSetVar="Bid_Summaries__c" extensions="BidSummariesController"> <apex:pageBlock title="Bid Summary"> <apex:slds /> <style type="text/css"> body {background-color: white;} p { font-weight: bold; } p { font-style: italic;} h1 { color: #f00; } p { background-color: #eec; } newLink { color: #f60; font-weight: bold; } </style> <apex:page lightningStylesheets="true"/> <apex:form > <apex:pageBlockTable value="{! Bid_Summaries__c }" var="b"> <apex:column value="{! b.Name }"/> <apex:column value="{! b.Original_Budget__c }"/> <apex:column value="{! b.Upgrade_Amount__c }"/> <apex:column value="{! b.Budget_incl_Upgrades__c }"/> <apex:column value="{! b.TJH_Service_Fee__c }"/> <apex:column value="{! b.Concession__c }"/> <apex:column value="{! b.Upgrade_Total__c}"/> </apex:pageBlockTable> </apex:form> </apex:pageBlock> </apex:page>

Apex Controller:

​​​​​​public class BidSummariesController {

    public BidSummariesController(ApexPages.StandardController controller) {

    }

        public List<Bid_Summaries__c> Bid {get; set;}
        public BidSummariesController(){
        List<Bid_Summaries__c> Bid= [Select Id, Selected_Option__c,Concession__c, Status__c,TJH_Service_Fee__c,
                                    Upgrade_Amount__c,Upgrade_Total__c, Original_Budget__c From Bid_Summaries__c] ;
    }
                       PageReference pageRef = Page.BidSummary1;                    
                       public list <Bid_Summaries__c> getBid(){
                                              
                       return Bid;
                       
        }
    
    }


Test Class:

@isTest 

    public class BidSummariesControllertest {
        
        private static testMethod void BidSummariesController() {
            
         test.StartTest();
            
         Bid_Summaries__c b = new Bid_Summaries__c();
         
         b.Upgrade_Amount__c     = 1000;
         b.Concession__c         = 1000;         
         b.Original_Budget__c = 100;
         b.Status__c  = 'New';
            
            Insert b;
            
         
          
           test.stopTest(); 
        PageReference pageRef = Page.BidSummary1;
        Test.setCurrentPage(pageRef);
        ApexPages.StandardController sc = new ApexPages.StandardController(b);
        
      
             
           
             
            List<Bid_Summaries__c> Bids = [Select Id, Selected_Option__c,Concession__c, Status__c,TJH_Service_Fee__c,
                                    Upgrade_Amount__c,Upgrade_Total__c, Original_Budget__c From Bid_Summaries__c ];
                    
                    Update Bids;
            
            
            
        } 
        
        List<Bid_Summaries__c> Bids = New List<Bid_Summaries__c>();
             
               
                                    
          
        }
Here is my visualforce page:
​​​​​​<apex:page standardController="Bid_Summaries__c">
    <apex:pageBlock title="Bid Summary">
    <apex:slds />
    <style type="text/css">
        body {background-color: white;}
        p { font-weight: bold; }
        p { font-style: italic;}
        h1 { color: #f00; }
        p { background-color: #eec; }
        newLink { color: #f60; font-weight: bold; }   
    </style>
            <apex:page lightningStylesheets="true"/>  
            <apex:form >       
            <apex:pageBlockTable value="{! Bid_Summaries__c }" var="Bid_Summaries__c">
            <apex:column value="{! Bid_Summaries__c.Name }"/>                  
            <apex:column value="{! Bid_Summaries__c.Original_Budget__c }"/>
            <apex:column value="{! Bid_Summaries__c.Upgrade_Amount__c }"/>
            <apex:column value="{! Bid_Summaries__c.Budget_incl_Upgrades__c }"/>
            <apex:column value="{! Bid_Summaries__c.TJH_Service_Fee__c }"/>
            <apex:column value="{! Bid_Summaries__c.Concession__c }"/>
            <apex:column value="{! Bid_Summaries__c.Upgrade_Total__c}"/>
            </apex:pageBlockTable>
            </apex:form>
      </apex:pageBlock>
</apex:page>

What I'm trying to do is dynamically populate the value of the Bid_Summaries__c object fields on a visualforce page where any changes to the fields in that object will reflect in realtime to the visualforce page. The Bid_Summaries__c object is showing on a record list on the community as Kanaban list, users are able to move the field to select options and change prices. The point is once a user change those fields it will reflect on the visualforce page dynamicly without the need to refresh the page. Any ideas on how to write the apex controller and test class, or if there is any other way to accomplish this. Thanks