• NZ_Xue
  • NEWBIE
  • 25 Points
  • Member since 2010

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 13
    Replies

I can't for the life of me grasp the concept of test methods. 

 

I have a very basic class that deactivates specific users but i don't know how to write a test method for it.

 

 

global class deactivateAccount {

webservice static String deactivateUserAccount(){

String myResult; // define the result that will be returned

Integer countUsers = 0; // count the updated users

List<User> myUsers = [

SELECT u.Profile.Name, u.isActive

FROM User u

WHERE u.Profile.Name = 'test' and u.IsActive = TRUE

];

for (User aUser: myUsers){

aUser.IsActive = FALSE;

countUsers++;

}

update myUsers;

return 'done: ' + countUsers;

}

}

 

 How do I test this? Can someone EXPLAIN what i'd be testing.

 

Thank you!

 

 

 

Message Edited by Sergiu on 03-04-2010 10:32 PM
  • March 05, 2010
  • Like
  • 0

Hi All

 

I would like to email to a person other than Account Owner when the account owner changes. Unfortunately it is not possible unless using Apex code.

 

I would be glad if you could help me write code to do the job for me. Here is pseudo code of what I am tying to achieve:

 

Trigger SendEmailToRegionalManager on Site_Defects__C after update

       if owner of Site_Defect__C record changed then

              get the name of Regional Manager of that record

              match the name to user and get the email address

              (I am not sure which one of the following is easier)

              get the email from email template change the recipient to Regional Manger send the email 

             OR

             use Mail. Function to crate email body here and then send it

      end if

end trigger

 

 

Many thanks in advance

I have a parent object which has a period field, and a child object that also has a period field. And I want to get all rows that either parent.period = 'Jan' or child.period = 'Jan' (with just one query).

 

I cannot do something like

select ..., (select ..., from child where period = 'Jan') from parent where period = 'Jan'

because it will only return records for which parent.period = 'Jan'.

 

Anyone has any thoughts, suggestions?

So I am trying to assign a value to a property in my controller and it just is not working, the value always ends up as null... am I doing somethign wrong?

 

In My Controller

public Boolean blnDoAttachment{get; set;}

 

 <<Some Code>>

 

 if (blnDoAttachment == True){

return new PageReference('p/attach/NoteAttach?pid=/' + c.id + 'retURL=' + c.id); 

 

}

if (blnDoAttachment == False){

return new PageReference('/'+ c.id);

}

return null;

 

On My VisualForce Page

<apex:commandButton action="{!save}" value="Submit"><apex:param value="False" assignto="{!blnDoAttachment}"/></apex:commandButton> <apex:commandButton action="{!save}" value="Submit and Attach"><apex:param value="True" assignto="{!blnDoAttachment}"/></apex:commandButton>

Any assistance would be greatly appreciated.  I am pretty sure its just something totally stupid on my part

 

Thanks!

 

Message Edited by RickoT1031 on 03-09-2010 04:27 PM

I checked my customer portal's profile and my new VF tab

is included in the profile and is set to "Default On".

 

When I log in to the portal as the user, I cannot see the tab.

 

Can somebody please tell me what steps I may have missed?

 

Thanks

Hi ,

i am new to apex programming.

my requirement is like below

opportunity can have Tradin plan

 

Each opportunity can have n number of trading plan but

all trading pan amount can not  greater than the opportunity amount .

  

to check the sum of trading plan amount whether it is greater or less

in validation rules it is not possible so i thought  i  can write  apex trigger

 

but i don't know how to stop data insertion  if codition fails in apex trigger .

below i written apes trigger before insert

please help me on this

 

trigger TradingPlanInsert on Opportunity_Trading_Plan__c (before insert)
{
          
           Id opptID;
           double oppAmount = 0;
           double oppTplanAmount= 0;
           for(Opportunity_Trading_Plan__c newTradinPlanObj: Trigger.new)
           {
          
                opptID = newTradinPlanObj.Opportunity_trading__c;
                oppTplanAmount = oppTplanAmount +  newTradinPlanObj.Plan_Amount__c;
           }
          
         Opportunity_Trading_Plan__c[] oppTradingobj = [Select Id, Name, CurrencyIsoCode, Opportunity_trading__c,
         Plan_Amount__c, Trading_Received_Date__c, Milestone__c, Description__c, GM__c
         FROM Opportunity_Trading_Plan__c  where Opportunity_trading__c = :opptID];
        
         for(Opportunity_Trading_Plan__c oppTexistinObj  : oppTradingobj )
         {
            oppTplanAmount = oppTplanAmount +  oppTexistinObj.Plan_Amount__c;
         }
        
         Opportunity[]  oppobj = [Select Id, StageName, Amount, CloseDate, Type, CurrencyIsoCode   FROM Opportunity where ID =:opptID];
         for(Opportunity oppdetailsObj  : oppobj )
         {
            oppAmount =   oppdetailsObj.Amount;
         }
         if (oppAmount < oppTplanAmount )
         {
           System.Debug('Trading plan  amount more than opportunity amount ');   
         }
          
          

 

 

Message Edited by sridharbarla on 03-08-2010 11:59 PM

Hi,

 

I'm creating a visualforce page for searching the Contact Names from contact records. I can able to search the records and display it in visualforce page. But when i added the pagination functionality its not working in these page. Am i missing anything or my approach is wrong. Please help me to solve this problem.

 

 

Visualforce Page code...

 

 

<apex:page standardController="Contact" extensions="ContactSearch" showHeader="false" sidebar="false"> <apex:form > <apex:sectionHeader title="Search Contacts"/> <apex:pageBlock > <apex:pageBlockSection title="Contacts"> </apex:pageBlockSection> <!--Panel grid to get the input from users --> <apex:panelGrid columns="2"> <apex:outputLabel style="font-weight:bold;" value="Contact Name"></apex:outputLabel> <apex:inputtext value="{!inp}"/> <apex:outputLabel style="font-weight:bold;" value="Contact Email"></apex:outputLabel> <apex:inputText value="{!emailinp}"/> <apex:OutputLabel value="Select Lead Source" style="font-weight:bold;"/> <apex:selectList value="{!lsource}" size="1"> <apex:selectOptions value="{!Source}"></apex:selectOptions> </apex:selectList> </apex:panelGrid> <apex:commandButton value="Search" action="{!search}"/> <apex:pageBlockSection title="Search results" columns="1"> <apex:outputPanel id="contacts"></apex:outputPanel> <apex:pageBlockTable value="{!results}" var="contactsList"> <!--<apex:column> <apex:facet name="header"></apex:facet> </apex:Column>--> <apex:column headerValue="Contact First Name"> <apex:outputText value="{!contactsList.cont.Name}"/> </apex:column> <apex:column headerValue="Contact Email"> <apex:outputText value="{!contactsList.cont.Email}"/> </apex:column> <apex:column headerValue="Level"> <apex:outputText value="{!contactsList.cont.Level__c}"/> </apex:column> <apex:column headerValue="Lead Source"> <apex:outputText value="{!contactsList.cont.LeadSource}"/> </apex:column> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlock> <apex:panelGrid columns="4"> <apex:commandLink action="{!first}">First</apex:commandlink> <apex:commandLink action="{!previous}" rendered="{!hasPrevious}">Previous</apex:commandlink> <apex:commandLink action="{!next}" rendered="{!hasNext}">Next</apex:commandlink> <apex:commandLink action="{!last}">Last</apex:commandlink> </apex:panelGrid> </apex:form> </apex:page>

 

 Apex Class code.....

 

 In these apex class i'm not able to modify the Controllers Database.getQuerylocator. Now, when i click the search button in visuaforce page it will displays the record, but i want to give the pagination for that records.

public class ContactSearch { //List<categoryWrapper> categories {get; set;} public ContactSearch(ApexPages.StandardController controller) { cid = System.currentPageReference().getParameters().get('id'); } Public ApexPages.StandardSetController con { get { if(con == null) { con = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Id, Name FROM Contact ORDER BY Name LIMIT 50])); con.setPageSize(5); } return con; } set; } /*Public List<categoryWrapper> getCategories() { categories = new List<categoryWrapper>(); return categories; } */ Public String cid; String inp; String emailinp; String leadsource; String lsource; String Source; public List<Contact> results = new List<Contact>(); public List<sContact> contacts { get; set; } Public Boolean hasNext { get { return con.gethasNext(); } set; } Public Boolean hasPrevious { get { return con.gethasPrevious(); } set; } Public integer pageNumber { get { return con.getpageNumber(); } } public void first() { con.first(); } public void last() { con.last(); } public void previous() { con.previous(); } public void next() { con.next(); } /* Getting the input from the user in the contact name text box and the values are assigned here */ public String getinp() { return inp; } public void setinp(String i) { this.inp = i; } /* -------------------------------------------------- */ /* Getting and Setting the input from the user in the contact email and the values are assigned here */ public String getemailinp() { return emailinp; } public void setemailinp(String email) { this.emailinp = email; } /* ------------------------------------------------------------------------ */ /* Getting and setting the values from the user in the lead source */ public string getleadsource() { return leadsource; } public void setleadsource(String ls) { this.leadsource = ls; } /* ------------------------------------------------------------------------ */ /* Getter and Setter value for Select List */ public string getlsource() { return lsource; } public void setlsource(String lsource) { this.lsource = lsource; } /* ------------------------------------------------------------------------------ */ /* */ public List<selectOption> getSource() { List<selectOption> val = new List<selectOption>(); val.add(new selectOption('','--None--')); val.add(new selectOption('Partner','Partner')); val.add(new selectOption('Web','Web')); val.add(new selectOption('Phone Inquiry','Phone Inquiry')); val.add(new selectOption('Partner Referral','Partner Referral')); val.add(new selectOption('Purchased List','Purchased List')); return val; } public void setSource(String source) { this.Source = source; } public List<contact> search() { contacts = new List<sContact>(); if(lsource!=null) { for(Contact c : [SELECT Name, FirstName, LastName, Email, Level__c, LeadSource, Id FROM Contact WHERE Name LIKE :inp+'%' AND Email LIKE :emailinp+'%' AND LeadSource LIKE:lsource+'%' ORDER BY Level__c DESC ]) { contacts.add(new sContact(c)); } } else { for(Contact c:[SELECT Name, FirstName, LastName, Email, Level__c, LeadSource, Id FROM Contact WHERE Name LIKE :inp+'%' AND Email LIKE :emailinp+'%' ORDER BY Level__c DESC ]) { contacts.add(new sContact(c)); } } return null; } public List<sContact> getresults() { return contacts; } public class sContact { public contact cont { get; set; } public Boolean selected { get; set; } public sContact (Contact c) { cont = c; selected = false; } } }

 

Please help me to solve this.

 

 

Thank You.

 

 

  • March 06, 2010
  • Like
  • 0

I can't for the life of me grasp the concept of test methods. 

 

I have a very basic class that deactivates specific users but i don't know how to write a test method for it.

 

 

global class deactivateAccount {

webservice static String deactivateUserAccount(){

String myResult; // define the result that will be returned

Integer countUsers = 0; // count the updated users

List<User> myUsers = [

SELECT u.Profile.Name, u.isActive

FROM User u

WHERE u.Profile.Name = 'test' and u.IsActive = TRUE

];

for (User aUser: myUsers){

aUser.IsActive = FALSE;

countUsers++;

}

update myUsers;

return 'done: ' + countUsers;

}

}

 

 How do I test this? Can someone EXPLAIN what i'd be testing.

 

Thank you!

 

 

 

Message Edited by Sergiu on 03-04-2010 10:32 PM
  • March 05, 2010
  • Like
  • 0