• Rory Hibbert
  • NEWBIE
  • -1 Points
  • Member since 2015
  • Salesforce System Technician
  • Allianz Insurance


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
Hi! I have class:
public class DisplayOpportunity{ 
    public PageReference save() {
        return null;
    }


    public List<Opportunity> Elements {get; set;}
	public String oppId {get; set;}
 

public void init() {
		Elements = [SELECT Name, CreatedDate, StageName FROM Opportunity WHERE StageName='Prospecting' or StageName='Closed Won'];   
        
}    
    public void changeStage() {
     Opportunity getElements=[SELECT StageName FROM Opportunity WHERE Id = :oppId]; 
	 
       getElements.StageName;
      if (getElements.StageName == 'Closed Won')
      {
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Closed Won is set already')); 
}   
        Else {
		update getElements;
        }
 		
		init();
        
 

    } 
}

and test class:
@isTest 
public class TestOpportunity {
	public static testMethod void insertNewOpportunity() {
        
  
        //create new opportunity
 Opportunity opp = new Opportunity();
	   opp.Name = 'test Oppo';
       opp.CloseDate = System.today();
       opp.StageName = 'Prospecting';
    insert opp;         
        
        
                //inilizate controller
DisplayOpportunity myOpp = new DisplayOpportunity ();  
ApexPages.currentPage().getParameters().put('oppId',opp.Id);        
                       
      //call method for StageChange
myOpp.changeStage();       
    
    }
    
}

Can you help me to understand part when I should call method and verify it in test class?
  • May 13, 2016
  • Like
  • 0
I am replacing a formula that has grown too large with a Visualforce page and an extension to do the work.  When passing the fully composed  apex:outputLink back as a string  is displays as just that a string. How should I be passing this back? I have stripped out all the logic so it is just building the first of about 20 different links that i need to build, once one is working the others will be easy 

VF page:
<apex:page standardController="SFDC_520_Quote__c" showHeader="false" sidebar="false" extensions="makelink">

 
 {!mylink}  
 


</apex:page>
Extention
 
public class makelink {

 private final SFDC_520_Quote__c q;

    public makelink(ApexPages.StandardController stdController) {
        this.q = (SFDC_520_Quote__c)stdController.getRecord();
    }

public string getmylink(){
string l;

l = '<apex:outputLink target="_blank" value="https://inside.legrandna.com/mainpage/Sales/tws_quote_program/find_quote.cfm?quote=' + q.Quote_ID__c + '&oppid=' + q.Opportunity__c + '&quoteid=' + q.id + '">WS Quote</apex:outputLink>';

return l ;
}
 

}

 
Profile userProfile = [SELECT Id FROM Profile WHERE Name='System Administrator'];
            user userRole = [SELECT id, name, UserRole.name FROM User WHERE UserRole.name like '% FAWS Technical Onboarding Manager%'];
       if((userProfile.Id != UserInfo.getProfileId())||(userRole.Id != userInfo.getUserRoleId())){  
           
           if((Trigger.isBefore)||(Trigger.isUndelete))
           { 
            List<Specialist_Lead__c > slist = new List<Specialist_Lead__c >();
            set<Id> leadId = new set<Id>();    
            List<string> adteamtype = new List<string>();    
            
            for(Specialist_Lead__c  s: trigger.new){
                leadId.add(s.Lead__c);
                adteamtype.add(s.Additional_Team_Type__c);
            }    
            slist = [select id, Lead__c, Additional_Team_Type__c 
                     from Specialist_Lead__c 
                     where Lead__c IN :leadId
                     and Additional_Team_Type__c IN :adteamtype];
            
            Map< String, Id > duplicateSpecialistMap = new Map< String, Id >();    
            
            for(Specialist_Lead__c s : slist){
                duplicateSpecialistMap.put(s.Additional_Team_Type__c, s.Id);        
            }
            
            for(Specialist_Lead__c s: trigger.new){
                Id duplicateSpecialistId = duplicateSpecialistMap.get(s.Additional_Team_Type__c);
                if(duplicateSpecialistId != null)
                {            
                   s.addError('This AdditionalTeamType is already existed with this Lead');            
                }
            }    
        }
    }