• Tarun_Khandelwal
  • NEWBIE
  • 90 Points
  • Member since 2015

  • Chatter
    Feed
  • 3
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 38
    Replies
Hi All,

I need some help writing a test class for the below (I am fairly new to apex so still learning)

Apex Class:

public class InteractionsForCustomer {
    
    
private List<Interactions__c> allInteractions;
        private Interactions__c currentInteractions;
 
    public InteractionsForCustomer() {
         
     }
 
    public List<Interactions__c> getAllInteractions() {
                allInteractions = [Select Id, Name from Interactions__c where Stage__c = 'Open' AND Cutomer__c = :currentInteractions.Customer__c];
        return allInteractions;
    }
 
     public Interactions__c getcurrentInteractions() {       
             return currentInteractions;
     }
     public void setcurrentInteractions(Interactions__c val) {
            this.currentInteractions = val;     
      }
}

VisualForce Component

<apex:component controller="InteractionsForCustomer" access="global">
    <apex:dataTable value="{!allInteractions}" var="inv">
        <apex:column >
            <apex:facet name="header">Invoice Name</apex:facet>
            {!inv.Customer__c}
        </apex:column>
    </apex:dataTable>
</apex:component>

Thanks
Josh
Hi,

Normally when for my getters I use the short hand.  For example
public Opportunity opp {get; set; }
And this works fine

However, I was trying that with a custom class I built and when I try and do it that way I get the error

"System.NullPointerException: Attempt to de-reference a null object 
Class.Top10OppAt90All_Class.<init>: line 27, column 1"
 
public class Top10OppAt90All_Class {
    
    public List<Opportunity> oppListStart {get; set;}
    OppWrapper newOpp;
    public List<OppWrapper> oppList {get; set;}   // = new List<oppWrapper>();
    public aggregateResult oppTotalClosed {get; set;}
    public decimal variance {get; set;}
    public Goals__c goal { get; set;}
    public Decimal oppTotal {get; set;}
    
    public Top10OppAt90All_Class() {
       // try {
            if (oppTotal == NULL) {oppTotal = 0;}
            if (oppListStart == NULL) { 
                oppListStart = [SELECT Name, StageName, Id, Amount, account.id, account.name, type, closedate FROM Opportunity 
                                                  WHERE StageName = 'A. Pending Sale' AND Amount != 0 AND Amount != NULL
                                                  ORDER BY Amount DESC LIMIT 10]; 
                
                oppTotalClosed = [SELECT Sum(Amount) TotalAmount FROM Opportunity WHERE StageName = 'W. Win' AND CloseDate = THIS_QUARTER];
                
            }
            
            for (Opportunity opp:oppListStart) {
				newopp = new OppWrapper(opp.name, opp.CloseDate, opp.Amount,  opp.id);
                system.debug('opp = ' + opp );
                system.debug('newopp = ' + newOpp);
                oppList.add(new OppWrapper(opp.name, opp.CloseDate, opp.Amount,  opp.id) );
                oppTotal = oppTotal + opp.amount;
            }
        oppList.add(new OppWrapper('Total', NULL, OppTotal, NULL));
      //  } catch (exception e) { system.debug(e); }    
        
        system.debug('oppList = ' + oppList);
    }
    
    /*
    public List<OppWrapper> getOppList() {
        return oppList;
    }  */
    
    public class OppWrapper {
        public String name {get; set; }
        public Date closeDate {get; set; }
        public Decimal amount {get; set; }
        public String Id {get; set; }
        
        public  OppWrapper(String name, Date closedate, Decimal amount, String id) {
            this.name = name;
            this.closeDate = closeDate;
            this.amount = amount;
            this.id = id;
            

            
        }
    }
    

}

The only way I've found to fix that is to do 
public List<OppWrapper> oppList  = new List<oppWrapper>();
combined with
/*
    public List<OppWrapper> getOppList() {
        return oppList;
    }  */

Why isn't the normal way working?





 
Hi,

i am unable to cover this lines in my test class can any one give me some idea how to do this.


        public Integer compareTo(Object compareTo) {
        
            WRNWrapper compareToWr = (WRNWrapper)compareTo;
            
            Integer returnValue = 0;
            
            if (getDate(this.openedDate) > getDate(compareToWr.openedDate)) {
                returnValue = -1;
            } else if (getDate(this.openedDate) < getDate(compareToWr.openedDate)) {
                returnValue = 1;
            }
        
            return returnValue;       
        }
        
        private DateTime getDate(String dt) {
            
            String[] dt2 = dt.split(' ');
            String[] dtFields = dt2[0].split('/');
            String[] tmFields = dt2[1].split(':');
            return system.Datetime.newInstance(Integer.valueOf(dtFields[2]), Integer.valueOf(dtFields[0]), Integer.valueOf(dtFields[1]), 
                                                Integer.valueOf(tmFields[0]), Integer.valueOf(tmFields[1]), Integer.valueOf(tmFields[2]));
        }
    }
}

Thanks.
. When the lead is converted, transfer the following data also to the opportunity:

Open activities
Notes and Attachments
Chat Transcript
As these are the related lists on Lead  and Opportunity.The values of these related list vales on lead need to be transfered to the respective related list on Opportunity.What approach should be taken for trigger. Please answer ASAP
Hi,

I am having an Issue. I want to allign two pageblocks in the Top Part of panel Grid. One a Pageblock contains some Search Parameters, and another is a page block contains Google Map.  Now, Serach Paramerts Page block coming in the Center Position of the Panel Grid .

User-added image

How to make it in the Top side , along the Google Map .
This is my Panel Grid Code
<apex:panelGrid columns="2" id="theGrid" width="100%" columnClasses="colstyle" style="vertical-align:top;" >
</apex: panelGrid>
Thanks in Advance
Reshmi
Hi All,

I need some help writing a test class for the below (I am fairly new to apex so still learning)

Apex Class:

public class InteractionsForCustomer {
    
    
private List<Interactions__c> allInteractions;
        private Interactions__c currentInteractions;
 
    public InteractionsForCustomer() {
         
     }
 
    public List<Interactions__c> getAllInteractions() {
                allInteractions = [Select Id, Name from Interactions__c where Stage__c = 'Open' AND Cutomer__c = :currentInteractions.Customer__c];
        return allInteractions;
    }
 
     public Interactions__c getcurrentInteractions() {       
             return currentInteractions;
     }
     public void setcurrentInteractions(Interactions__c val) {
            this.currentInteractions = val;     
      }
}

VisualForce Component

<apex:component controller="InteractionsForCustomer" access="global">
    <apex:dataTable value="{!allInteractions}" var="inv">
        <apex:column >
            <apex:facet name="header">Invoice Name</apex:facet>
            {!inv.Customer__c}
        </apex:column>
    </apex:dataTable>
</apex:component>

Thanks
Josh
Hi,

I want to download the pdf automatically using render as pdf i tried using contenttype attribute.Its throwing error

Thanks & Regards,
Sindhu Ambarkar.
Hi,
Trigger SetRecordToFixedRecordType on Lead(before insert)

    Id recId=recordTypeId('Lead','Lead - GOVT'); 

    for(Lead led :Trigger.new)

    { 
    if(led.Status__c='Submitted' && led.Web_To_Lead__c='Lead - GOVT')
        { 
            led.RecordTypeId='012280000005fr1'; 
        } 
    }
 Public static Id recordTypeId(string Lead,string GOVT)

    Id recTypeId; 
    if(Lead!= null && Lead - GOVT != null)
    { 
    recTypeId= Schema.getGlobalDescribe().get(Lead).getDescribe().getRecordTypeInfosByName().get(Lead - GOVT).getRecordTypeId();
    }
     return recTypeId; 
    } 

}


This is the trigger written for web to lead .when the webtolead is saved it has to to perticular record type but i am getting error.

Thanks,
swathi.
Hi,


How to put background image image in visualforce page
Hi, guys.

I have a strange problem here, which really pisses me off :(

So it is very simple, just typing in execute anonymous:
Account acc;
acc.getCloneSourceId();

Gives me an error:
"Compile error at line 2 column 1
Method does not exist or incorrect signature: [Account].getCloneSourceId()"

According to this (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_sobject.htm)article, this method should work with any SObject, but it doesn't work with any object...
Please, tell me what am I missing.



Thanks!
  • October 16, 2015
  • Like
  • 0
Hi,

I have records with column header Name, Date and Payment under pageblocktable section. I've another pageblocktable section below the former. Now what I need is when I click the row I can fetch the details of the that row, like values of name,date,etc. In the long run, that another page table will be use ro show records of the related list related to that record. But right now my concern is how to revtrieve values. Please help, it's an urgent case on which I'm working right now.
After Uploading Package i got an error
"No test methods found in the Apex code included in the package. At least 75% test coverage is required."
My Apex Class
@isTest
public class CryptoTest {
        public CryptoTest (ApexPages.StandardController acon) { }
    String MySessionID = UserInfo.getSessionID();
    String conId = ApexPages.currentPage().getParameters().get('Id');
    String EmailCon=[Select email from Contact where Id=:conId ].email;
    String myurl= URL.getSalesforceBaseUrl().toExternalForm() + '/services/Soap/c/10.0/' + UserInfo.getOrganizationId();
    public String getFoo() {
    string c='eU9WzoFgU4n8Apu5PYxcNGRZswRDZJWDEMdbQVU85gw=';
    if(String.IsBlank(EmailCon)){ EmailCon='';}
    Blob cryptoKey= EncodingUtil.base64Decode(c);
    Blob data = Blob.valueOf(MySessionID );
    Blob data1 = Blob.valueOf(myurl);
    Blob data2 = Blob.valueOf(conId);
    Blob data3 = Blob.valueOf(EmailCon);
    
    Blob encryptedData = Crypto.encryptWithManagedIV('AES256', cryptoKey, data);
    Blob encryptedData1 = Crypto.encryptWithManagedIV('AES256', cryptoKey, data1);
    Blob encryptedData2 = Crypto.encryptWithManagedIV('AES256', cryptoKey, data2);
    Blob encryptedData3 = Crypto.encryptWithManagedIV('AES256', cryptoKey, data3 );
     
    String b64Data = EncodingUtil.base64Encode(encryptedData);
    String b64Data1 = EncodingUtil.base64Encode(encryptedData1);
    String b64Data2 = EncodingUtil.base64Encode(encryptedData2);
    String b64Data3 = EncodingUtil.base64Encode(encryptedData3);
    
    String testurl='sessionID='+EncodingUtil.urlEncode(b64Data, 'UTF-8')+'&serverUrl='+EncodingUtil.urlEncode(b64Data1, 'UTF-8')+'&contactID='+EncodingUtil.urlEncode(b64Data2, 'UTF-8')+'&email='+EncodingUtil.urlEncode(b64Data3, 'UTF-8');
        return testurl;
    }
}
------------------------------------------------
Visual force page

<apex:page standardController="Contact" extensions="CryptoTest" > <apex:iframe src="https://www.demomail.net/demomailsfdc/sendvideo/demomailfromcontact.aspx?{!foo}&IsEnc=1" scrolling="true" id="theIframe"/> </apex:page>


 
two different programs, two before triggers are there then which one execute first?
<apex:page controller="SpeakerFeedbackcc" showHeader="false" sidebar="false" >
<apex:outputpanel >
     <apex:actionstatus id="actStatusId1">
       <apex:facet name="start">
      <div class="waitingSearchDiv" id="el_loading" style="background-color: #DCD6D6; height: 100%;opacity:0.65;width:100%;">
      <div class="waitingHolder" style="top: 74.2px; width: 91px;">
        <img class="waitingImage" src="/img/loading.gif"     title="Please Wait..." />
        <span class="waitingDescription">Processing.....</span>
         </div>
          </div>
      </apex:facet>
 </apex:actionstatus>
    </apex:outputpanel>
 
<style>
td
{
background-color:#CCCCFF;
}
</style>
 <apex:form >
      <apex:image url="{!imageURL}">
    </apex:image>     
    <apex:sectionHeader subtitle="please Submit your Feedback"/>

    <h1 style="text-align:center;color:#0000FF;margin-left:375px;">We have created your personalized profile in eMedEvents.com. Please feel free to add more information </h1><br/> <br/>
   <h2 style="text-align:center;margin-left:400px;">We are collecting the following information as part of the professional speaker blog campaign</h2>
   
     
     

    <apex:pageblock >
 
    <table style="auto; margin-left:50px; margin-top:50px;">
     <tr>
                        <td>
                            <b>1. Please elaborate on the topic presented by you in the conference</b>
                        </td>    
                        <td >
                            <apex:inputField id="inp1" value="{!iFR.Please_elaborate_on_the_topic_presented__c}" style="width:360px; height:50px" />
                        </td>
                    </tr>  
                     <tr>
                        <td width="65%">
                            <b>2.Do you have any you-tube links or news links related to your session</b>
                        </td>    
                        <td >
                            <apex:inputField id="inp2" value="{!iFR.Do_you_have_any_you_tube_links_or_news_l__c}" style="width:360px; height:50px"/>
                        </td>
                    </tr>  
                     <tr>
                        <td>
                            <b>3.  Would you like to present in other countries</b>
                        </td>    
                        <td >
                            <apex:inputField id="inp3" value="{!iFR.Would_you_like_to_present_in_other_count__c}" style="width:360px; height:50px"/>
                        </td>
                    </tr>  
                     <tr>
                        <td>
                            <b>4.What are the beneficial aspect/novel innovations pertaining to your topic</b>
                        </td>    
                        <td >
                            <apex:inputField id="inp4" value="{!iFR.What_are_the_beneficial_aspect_novel_inn__c}" style="width:360px; height:50px"/>
                        </td>
                    </tr>  
                     <tr>
                        <td>
                            <b>5.Were there any other speaker(s) involved in the session</b>
                        </td>    
                        <td >
                            <apex:inputField id="inp5" value="{!iFR.Were_there_any_other_speaker_s_involved__c}" style="width:360px; height:50px"/>
                        </td>
                    </tr>  
                     <tr>
                        <td width="30%">
                            <b>&nbsp;&nbsp;  </b>
                        </td>
                        <td width="70%">
   <apex:commandButton value="Submit your Feedback" action="{!submitFeedBack}" status="actStatusId1" />
                       </td>
                    </tr>     
    
   </table>
   
   </apex:pageblock>
    </apex:form>

</apex:page>


public class SpeakerFeedbackcc {
 public String imageURL{get;set;}
     Public string rating{get;set;}
     public Speaker_Feedback__c iFR{get;set;}
public SpeakerFeedbackcc (ApexPages.StandardController controller){
  }
  public SpeakerFeedbackcc ()
   {
   iFR= new Speaker_Feedback__c ();
 
      imageURL='/servlet/servlet.FileDownload?file=';
    List< document > documentList=[select name from document where
                                    Name='eMED events'];
   
    if(documentList.size()>0)
    {
      imageURL=imageURL+documentList[0].id;
    }
  }
   
  public pageReference submitFeedBack(){
      system.debug('total values is ===>'+iFR);
     
 
      insert iFR;
      pageReference pf = new pageReference ('/apex/FeedbackThanksPage');
      pf.setRedirect(true);
     return pf ;
    }
}



 
Hi
    My Scenrio is i m having one picklist field with values are X,Y,Z and W and one dependent text field is there.whenever i was select the W value in the picklist ,text field was populating after that i entered some text and saving the page upto its fine.The problem is whenever i was going to EDIT the page the picklist field value i was changing from W to X,the test field value didint erase. Thetest field value should come blank.
  
 THANKS
RANGA
Hi,

I want to create duplicate copy of an object in Salesforce since we need to archive some data into duplicate object. Is there a better way to do this without using third part app from app exchange. I tried it using Force.com IDE but it is getting errored out while saving to server. 
Can anyone please help me to solve my issue.
I have created apex trigger with test classes. I am not getting any error after test run but unable to getting any code coverage. Please check below is my apex trigger and test class.

                trigger getAllContacts on Scheme__c (after insert,after update)
                {
                    List<ANZSIC_Contact__c> acc = new List<ANZSIC_Contact__c>();
                    for(Scheme__c scheme :trigger.new)
                    {
                        Id devRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Underwriter').getRecordTypeId();
                        if(scheme.Account__c != null && scheme.Account__r.RecordTypeId== devRecordTypeId )
                        {
                            List<Contact> con = new List<Contact>();
                            con = [select Id,Email,Phone from contact where Account.Id =:scheme.Account__c];
                            for(Contact c:con)
                            {
                                acc = [select Id from ANZSIC_Contact__c where Contact__c =:c.Id and Scheme__c =:scheme.Id];
                                if(acc ==Null)
                                {
                                    ANZSIC_Contact__c ac = new ANZSIC_Contact__c();
                                    ac.Contact__c = c.Id;
                                    ac.Scheme__c = scheme.Id;
                                    ac.Email__c = c.Email;
                                    ac.Phone__c = c.Phone;
                                    acc.add(ac);
                                }
                                else
                                {
                                
                                }
                            }
                            insert acc;
                        }
                    }
                }

                @isTest(seeAllData=false)
                private class Test_getAllContacts
                {
                    static testMethod void getAllContacts()
                    {
                        test.startTest();
                        RecordType businessAccountRecordType = [SELECT Id FROM RecordType WHERE SobjectType='Account' AND Name = 'Underwriter'];
                        Account acc = new Account();
                        acc.Name = 'Test Account';
                        acc.RecordTypeId = businessAccountRecordType.Id;
                        insert acc;Contact con = new Contact();
                        con.LastName = 'Test data';
                        con.AccountId = acc.Id;
                        con.Email ='n@yahoo.in';
                        con.Phone = '987654321';
                        insert con; Scheme__c  sh = new Scheme__c();
                        sh.Account__c = acc.Id;
                          test.stopTest();
                    }
                }