• Sakthidasan
  • NEWBIE
  • 110 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 16
    Questions
  • 11
    Replies
I'm learning vf page.I am struggling display a record from vg page.I copy the id of the contact record and past in url like same(https://***Salesforce_instance***/apex/HelloWorld2?id=001D000000IRt53) but I'm not see the record in vf page.my code here:

<apex:page standardController="Contact">
<apex:form >
<apex:pageBlock title="Quick Edit: {!Contact.Name}">
<apex:pageBlockSection title="Contact Details" columns="1">
<apex:inputField value="{!Contact.Phone}"/>
<apex:outputField value="{!Contact.MobilePhone}"
label="Mobile #"/>
<apex:inputText value="{!Contact.Email}"
label="{!Contact.FirstName + '’s Email'}"/>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
 would like to know that where's this Owner coming from? I don't see there's a Owner object and I believe that Owner.Name was getting from User object.when should we use owner field ?
I'm leanring dynamic apex.it can be useful for create flexible application.but when we should we use dynamic apex.please explain real time example
I'm new to salesforce.How to write test class for follwing Apex class.it function is get unique ownerId from the object 
 and find out sum of outcome,howmany event occur in the current month and send the email to the owner.
Apex class:
public class oppOwnerOutcome {
    //Remove debug statements
    public void executeLogic(){
        Map<String,List<Meeting__c>> outCmeMap=new Map<String,List<Meeting__c>>();
        Map<String,Decimal> ownerOutComeMap =new Map<String,Decimal>();
        Map<String,String> ownerNameMap =new Map<String,String>();
        Map<String,String> ownerEmailMap =new Map<String,String>(); 
        Set<Id> ownerIdSet = new Set<Id>();     
        for(Meeting__c mData:[SELECT id, OutCome__c, Expected_Close_Date__c, AccountMaster__r.Ownerid, AccountMaster__r.Owner.Name FROM Meeting__c WHERE OutCome_Flag__c = false AND Expected_Close_Date__c = THIS_MONTH]){         
            if(!outCmeMap.containsKey(mData.AccountMaster__r.Owner.id)){                
                List<Meeting__c> meetingList=new List<Meeting__c>();
                meetingList.add(mData);
                outCmeMap.put(mData.AccountMaster__r.Owner.id,meetingList);
            }
            else{
                List<Meeting__c> meetingList=new List<Meeting__c>();
                //Use OwnerId
                meetingList=outCmeMap.get(mData.AccountMaster__r.Owner.id);
                meetingList.add(mData);
                outCmeMap.put(mData.AccountMaster__r.Owner.id,meetingList);
            }
        }
        for(String owrId:outCmeMap.keySet()){
            Decimal totalOutcomePerOwner = 0;
            for(Meeting__c mtg: outCmeMap.get(owrId)){
                totalOutcomePerOwner = mtg.OutCome__c+totalOutcomePerOwner ;
                //System.debug('summary'+res1.OutCome__c);              
            }
            ownerOutComeMap.put(owrId, totalOutComePerOwner);
        }
        
        List<User> owRecList = new List<User>();
        owRecList = [SELECT Id, Name, Email FROM User WHERE Id IN: outCmeMap.keySet()];
        for(User uRec:owRecList){
            ownerNameMap.put(uRec.Id, uRec.Name);
            ownerEmailMap.put(uRec.Id, uRec.Email); 
        }       
        List<EmailObj__c> emailRecList = new List<EmailObj__c>();
        //Move hardcoded values to custom labels or settings
        for(String owrId:outCmeMap.keySet()){
            EmailObj__c emailRec = new EmailObj__c();
            emailRec.send_Address__c = ownerEmailMap.get(owrId);
            String emailBody = 'Dear '+ownerNameMap.get(owrId)+'<br></br>' +
                                'Total Opportunity Outcome expected for this month is '+ownerOutComeMap.get(owrId)+'<br></br>' +
                                'Regards'+'<br></br>' +
                                'Sales Team';
            emailRec.emailBody__c = emailBody;
            emailRecList.add(emailRec);
        }
        //Use database.insert instead of insert statement
        //database.saveResult[] srList = database.insert(emailRecList, false);
        //for(Database.saveResult sr : srList) {
   
        insert emailRecList;
        
        //System.debug('summary:'+summary);
    }         
}
Apex Test Class:
@isTest
private class oppOwnerOutcomeTest {
    
    static  testMethod void testoutCome(){
        
         Account acc=new Account(Name='TestMethod');
        insert acc;
        
        Opportunity opp=new Opportunity(Name='TestCaseOpp',StageName='Prospecting',CloseDate=system.today());
        insert opp;
        Opportunity opp1=new Opportunity(Name='TestCaseOpp',StageName='Prospecting',CloseDate=system.today());
        insert opp1;
        
        Meeting__c mRec = new Meeting__c( AccountMaster__c = acc.id, OutCome_Flag__c = false );
        insert mRec ;
        Meeting__c mRec1 = new Meeting__c( AccountMaster__c = acc.id, OutCome_Flag__c = false );
        insert mRec1 ;
        oppOwnerOutcome tt=new oppOwnerOutcome();
        tt.executeLogic();
        
    }

}
I'm new to salesforce any one please explani how to write test class for extension controller class.In the vf page I show the account details and custom object details.If the user not staisfied the result .they create case and task based on the scenerio I create one extension controller.
here is my Controlle Code:
public class MeetingOverviewExtension {
    public final Account accRec;
    public String issueRadio {get; set;}
    transient public Integer counts {get; set;}
    //public List<Meeting__c> meetingList=new List<Meeting__c>();
     public List<Meeting__c> meetingList {get; set; }
   
    public MeetingOverviewExtension(ApexPages.StandardController controller){
        accRec = (Account)controller.getRecord();
        meetingList=[select id,StartDate__c,EndDate__c,Expected_Close_Date__c,Location__c,
                    Purpose__c,OutCome__c from Meeting__c where AccountMaster__c=: accRec.id];
        system.debug('check'+meetingList.size());
        
       
             counts = (Integer) [select count() from meeting__c where AccountMaster__c=: accRec.id and Expected_Close_Date__c = THIS_MONTH];
        System.debug('outttt'+counts);
    }
    public PageReference submit(){
         Task T = new Task();
         Case cRec=new Case();
        if(issueRadio == 'Yes'){
            system.debug('yesstruee');
       
        T.Type = 'Email';
                 T.Description = 'Reassign the outcome'; 
                T.Subject='Outcome monitoring';
    T.WhatId = accRec.Id; 
           
            cRec.Status='New';
            cRec.Status='Email';
            cRec.AccountId=accRec.Id;
     
            }
        try{
            insert T;
            insert cRec;
            system.debug('Caseid::'+cRec.id);
        }
        catch(System.DmlException e){
            System.debug(e.getMessage());
            return null;
                
        }

          PageReference page = new PageReference('/'+accRec.Id);
        page.setRedirect(true);
        return page;

            }
  
}
Test Class:
@isTest 
public class MeetingOverviewExtensionTest {
    
    static testMethod void testMethod1(){
        
        Account acc=new Account(Name='TestMethod');
         insert acc;
         Opportunity opp=new Opportunity(Name='TestCaseOpp',StageName='Prospecting',CloseDate=system.today());
             insert opp;
         Meeting__c mRec=new Meeting__c(AccountMaster__c=acc.id,OutCome_Flag__c=false);
         insert mRec;
        ApexPages.StandardController sc = new ApexPages.StandardController(acc);
       // sc.setSelected(acc);
        MeetingOverviewExtension testAccPlan = new MeetingOverviewExtension(sc);
        
         Task T = new Task();
        T.Type = 'Email';
                 T.Description = 'Reassign the outcome'; 
                T.Subject='Outcome monitoring';
                    T.WhatId = acc.Id; 
        insert T;
         PageReference pageRef = Page.MeetingOverviewForm;
       // Test.setCurrentPage(pageRef);
          pageRef.getParameters().put('id', String.valueOf(acc.Id));
        Test.setCurrentPage(pageRef);
    
    }
}
I'm new to salesfore I wrote test class for after update scnerio but I got only 72 code coverage.How do get 100% coverage.here's my trigger
and the test class.
TriggerHandler Class:
public  class OpportunityTriggerHandler {
    
    public static void outComeDealProcess(List<Opportunity> NewOpps,Set<id> Opp){
        
    List<Meeting__c    > meetingRec=new List<Meeting__c    >();
    List<Meeting__c> meetingIdList=new List<Meeting__c>();
    meetingIdList=[select id,OpportunityLookup__c from Meeting__c where OpportunityLookup__c IN :Opp];
    
        for(Opportunity oppRec:NewOpps){
        
            if(oppRec.StageName=='Closed Won'|| oppRec.StageName=='Closed Lost'){
                for(Meeting__c mRec:meetingIdList){
         
                if(oppRec.Id==mRec.OpportunityLookup__c)
                    mRec.OutCome_Flag__c=false;
                    meetingRec.add(mRec);
                }
            }
    }
update meetingRec;
    
    }
    
}
Test class:
@isTest
private class OpportunityTriggerHandlerTest {
    @isTest 
    public static void testocc(){
         Account acc=new Account(Name='TestMethod');
         insert acc;
        Opportunity opp=new Opportunity(Name='TestCaseOpp',StageName='Prospecting',CloseDate=system.today());
         Opportunity opp1=new Opportunity(Name='TestCaseOpp',StageName='Prospecting',CloseDate=system.today());
        insert opp;
         Meeting__c mRec=new Meeting__c(AccountMaster__c=acc.id,OutCome_Flag__c=false);
         insert mRec;
         Meeting__c mRec1=new Meeting__c(AccountMaster__c=acc.id,OutCome_Flag__c=false,OpportunityLookup__c=opp.id);
      
        opp.StageName='Closed Won';
        update opp;
        
       
     }
    
}