• Neel88
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 2
    Replies
Hi Experts,
I have this class to query records and display the results in a VF page. I need help to write a test class for this. Will be my first. Please advice

public with sharing class scbilling { string sID = ApexPages.currentPage().getParameters().get('id'); //
public Date T1 {get;set;}
public Date T2 {get;set;}
integer monthly =0;
integer totalpayment=0;
integer mCount=0;
Date Tx; //Date Tx = Date.newInstance(2015,1,1);       

  public Pagereference doIt() {          
totalpayment=0;         displayResults.Clear();         mcount=0;         return null;}//For action button    

public scontract__c sc = [select System__r.name, System_Live_Date__c, First_Month_End_of_Service__c  from scontract__c where id=:sID];  public scontract__c getSc(){ return sc; }             

             public LIST<AggregateResult> mp = new LIST<AggregateResult>();//get results from SOQL                 Map<Date, Integer> displayResults = new Map<Date, Integer>(); //To store Date and Monthly                             

 Public integer getcalc(){                    

        IF(T1==null) Tx= sc.First_Month_End_of_Service__c; else Tx=T1; //date.newInstance(2017,1,1);//when page loads     

        Tx = Tx.addMonths(1); //Move to next month of T1         Tx = Tx.toStartOfMonth(); //Get to 1st date of the month of T1 + 1 month         Tx = Tx.addDays(-1);//Get last date of the month of T1                

  
IF(T2==null) T2= Date.TODAY();         IF(T2 > Tx.addMonths(60)) T2=T2.addmonths(60);//to limit the loops to 60             While (Tx <= T2){//loop for x months between T1 & T2     

                                  mp =  [select sum(monthly_fee__c) cmp from scontract_item__c where s_contract__c=:sID                                            AND First_Month_End_of_Service_Period__c <=:Tx                                            AND last_month_end_of_service__c >= :Tx];              

   monthly = integer.valueOf(mp[0].get('cmp'));   //convert aggregate value to integer              

                      IF(monthly==null) monthly=0;   // else monthly=monthly;                    
                       totalPayment = totalPayment + monthly;                
   displayResults.put(Tx, monthly); //insert values into map             
      Tx = Tx.addMonths(1);             
      mCount = mCount+1;            
       IF(mCount >=60) break;              
                  }          
                   return totalPayment ;  }    
        Public Map<date, integer> getdisplayResults(){return displayResults;}  //sends map values to VF page      

   public Void clear(){displayResults.clear();
}      

   public integer getmCount(){return mcount;}                             
                           }
  • December 26, 2017
  • Like
  • 0
I am trying to do this

Date1 = 2017-12-31;
Select sum(monthlyfees__c) from customobject__c where id='12345678' and first_month__c <= date1 and last_month__c <=date1;

I get no results

But i get results for 
Select sum(monthlyfees__c) from customobject__c where id='12345678' and first_month__c <= date1;

Idea is to loop and change date1 with differnt values and get the final total for multiple soql queries in a VF page. 
Please advice.
Thanks
 
  • December 12, 2017
  • Like
  • 0
I am trying to find all leads within a certain radius of another lead say LEAD_A. The latitude, longitude of the postalcode/zip of LEAD_A is to be extracted from an object called zip_code__c (object) unrelated to Leads
with FIELDS
location__c (type GEOLOCATION) has lat,long
zipcode__c (text field)
city__c, State__c

I can get that with soql similar to
*select name, company, postalcode from LEAD where postalcode in('zip1','zip2')*

to get to that I am building a query as below

select name, company, postalcode from lead where postalcode in (select zipcode from zip_code__c where DISTANCE(location__c, GEOLOCATION(LEAD-A.latitude, LEAD-A.longitude)) < 20 )

Please help with this interesting challenge

I want to display this on the Lead layout via a VF page or button !
  • October 11, 2017
  • Like
  • 0
I have a team of 300 salespersons who are contacts in my org who provide leads. I want to create a form page where they can provide leads without giving them salesforce accounts.
I dont want to use web2lead as that leaves me to control over who leaves the lead and spam.

If a person leaves the company and I mark them inactive(custom field) in contact. I would like to be able to reject their lead and also if possible restrict them with another users name(fake/spam leads). WOuld appreciate ideas. I am not much of a programmer :)
  • September 07, 2015
  • Like
  • 0
My Opportunities have related contacts via lookup. The opp is owned by neither of them or could be owned by one of them. I want to be able to share the records with both contacts as users  in partner community. I found https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_bulk_sharing_creating_with_apex.htm for Creating User Managed Sharing Using Apex. I tried to use it however not being conversant with apex programming I am not able to resolve the test fail. I am wondering how to share the records using apex or otherwise. Please advice
My Opportunities have related contacts via lookup. The opp is owned by neither of them or could be owned by one of them. I want to be able to share the records with both contacts as users  in partner community. I found https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_bulk_sharing_creating_with_apex.htm for Creating User Managed Sharing Using Apex. I tried to use it however not being conversant with apex programming I am not able to resolve the test fail. I am wondering how to share the records using apex or otherwise. Please advice

hi friends,

i am using visualforce page and apex class to create standard user and to view user record as well as for edit functionality...

 

i haven't used <apex:detail/> to view record of any particular user...because by using this i am going to standard look and feel...

insted of using detail i have used simple vf  and in that used outputfield to dislay users record

 

here is my code..

 

 

i want to use a command button for reset password ,i haven't written any code in method(reset) of extension ...

how method will be written in extension (say method in extesnion  is reset)

<apex:page standardController="User" tabStyle="MyAdmin__tab" extensions="StaffandUserDetailPageExtension" >  <!--  <apex:detail title="false" relatedList="false"/> -->
    <apex:form >
        <apex:pageBlock mode="edit">
        <apex:pageMessages />
            <apex:pageBlockButtons >
                   
                    <apex:commandButton action="/apex/EditStaffAndUser?id={!id}" value="Edit"/>
                    <apex:commandButton action="/apex/AdminListView?intFocus=5" value="List View"></apex:commandButton>
                <!--    <apex:commandButton action="{!resetpassword}" value="Reset Password"/> -->
                    
                 </apex:pageBlockButtons>
              
              <apex:pageBlockSection title="User Information" columns="2" collapsible="false"> 
             
           
                 <apex:outputField value="{!User.User_Types__c}"/> 
                  <apex:pageBlockSectionItem >
                         <apex:outputLabel value="Active"/>
                         <apex:outputfield value="{!User.IsActive}"/>
                  </apex:pageBlockSectionItem> 
                
                  <apex:outputField value="{!User.ProfileId}"/>
                  <apex:outputField value="{!User.FirstName}"/>
                  <apex:outputField value="{!User.Username}"/>
                  <apex:outputField value="{!User.LastName}"/>
                  <apex:outputField value="{!User.Email}"/>
                  <apex:outputField value="{!User.alias}"/>
                  <apex:outputField value="{!User.CommunityNickName}"/>
     
                  
                 
                  </apex:pageBlockSection>
        
            
           
            

          
                    
                    
            <apex:pageBlockSection >

                  
                   
                   <apex:outputField value="{!User.Phone}"/>
                   <apex:outputField value="{!User.Extension}"/>
                   <apex:outputField value="{!User.Fax}"/>
           
                   <apex:outputField value="{!User.Title}"/>
                   <apex:outputField value="{!User.CompanyName}"/>
          
                   <apex:outputField value="{!User.Department}"/>
                   

         
                   
          
                   </apex:pageBlocksection>
              
              
            
      
      
          
            <!-- 
               <apex:pageBlockSection title="Other Information" columns="1" collapsible="false">
                   <apex:outputField value="{!User.EmailEncodingKey}"/>
                   <apex:outputField value="{!User.TimeZoneSidKey}"/> 
                   <apex:outputField value="{!User.LocaleSidKey}"/>
                   <apex:outputField value="{!User.LanguageLocaleKey}"/>
               </apex:pageBlockSection>
             --> 
               
        
            
              </apex:pageBlock>
              </apex:form>
   
  
 
 
 


   
</apex:page>

 Thanks in advance