• SFDC Admin & Analyst
  • NEWBIE
  • 125 Points
  • Member since 2011

  • Chatter
    Feed
  • 5
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 8
    Replies

Hi,

 

I have a VF page and Controller class. I have two page blocks. First page block loads all the data and second pageblock must be rendered if any record in first page block is selected. The rendered attribute is not working based on the list size.

 

Here is the code

 

<apex:page standardController="Contact" extensions="ContactCodeExtension" id="pg">

<apex:form id="frm">
<apex:outputPanel id="errorPnl">
<apex:pageMessages />
</apex:outputPanel>
<!------------------------------------------------------------- ACTION FUNCTIONS ---------------------------------------------------------------------------->

<apex:actionFunction action="{!populateContactCode}" name="populateContactCodeAF" reRender="pbResult,errorPnl" status="actionStatus" >
</apex:actionFunction>

<apex:actionFunction action="{!addtoSelectedList}" name="addtoSelectedListAF" reRender="pbResult2,errorPnl" status="actionStatus"/ >
<apex:actionFunction action="{!addtoTEst}" name="addtoTEstAF" reRender="pbResult2" status="actionStatus"/>
<!------------------------------------------------------------- ACTION FUNCTIONS ---------------------------------------------------------------------------->

<apex:pageBlock rendered="{!if(contactId != null,true,false)}" id="pb">

<apex:pageBlockButtons id="pgButtons">

<apex:commandButton value="Cancel" action="{!cancel}" />


<apex:actionStatus id="actionStatus" startText="Please wait....">
<apex:facet name="start">&nbsp;&nbsp;<apex:image value="/img/indicator.gif"/></apex:facet>
<apex:facet name="stop"></apex:facet>
</apex:actionStatus>

</apex:pageBlockButtons>


<h1 style="font-weight:bold;font-size:20px">Adding Contact Codes for {!con.Name}.</h1>

<br/>
<br/>
<apex:pageBlocksection title="Contact Codes" columns="1" id="pbResult">
<apex:outputPanel rendered="{!if(wrapperList.size>0,true,false)}">
<table><tr><td>
<div style="overflow:auto; height:470px;width:870px;">
<apex:pageBlockTable id="resultTable" value="{!wrapperList}" var="wrapper" rendered="{!if(wrapperList.size>0,true,false)}">
<apex:column >
<apex:facet name="header">
<apex:inputCheckbox id="allSelected" onclick="checkAll(this,'checkdone');addtoTEstAF();" />
</apex:facet>
<apex:inputCheckbox value="{!wrapper.isSelected}" id="checkdone" onclick="addtoSelectedListAF();"/>


</apex:column>

<apex:column >
<apex:facet name="header">
<apex:outputPanel >
cade444
</apex:outputPanel>
</apex:facet>
<apex:outputField value="{!wrapper.ccDesc.Description__c}" />
</apex:column>
<apex:column >
<apex:facet name="header">
code
</apex:facet>
<apex:outputField value="{!wrapper.ccDesc.Description__c}" />
</apex:column>
</apex:pageBlockTable>
</div> </td></tr></table>
</apex:outputPanel>
<apex:outputPanel rendered="{!If(wrapperList.size = 0,true,false)}" id="errMsg">
<span style="color:red;">No Records found</span>
</apex:outputPanel>


</apex:pageblocksection>
</apex:pageBlock>
<apex:pageBlock rendered="{!If(backupContactCodes.size>0,true,false)}" id="pbResult2">
<apex:pageblocksection title="Selected Contact Codes" columns="1" >
<apex:outputpanel id="ProductUnitsInformation" >
<table><tr><td>
<div style="overflow:auto; height:470px;width:870px;">
<apex:pageBlockTable id="resultTable2" value="{!backupContactCodes}" var="wrapper2">

<apex:column >
<apex:facet name="header">
<apex:outputPanel >

Code Description

</apex:outputPanel>
</apex:facet>
<apex:outputField value="{!wrapper2.Description__c}" title="Code Description"/>
</apex:column>
</apex:pageBlockTable>
</div> </td></tr></table>
</apex:outputpanel>


</apex:pageBlocksection>
</apex:pageBlock>


<!-- // @Sashi Singh -- 09/19/2013 -- RRM Request Number -- REQ-00002156 -->
<input type="hidden" id="oldCodeType" value="" />

<script type="text/javascript">
function checkAll(cb,cbid){
var allchecked = cb.checked;
var inputElem = document.getElementsByTagName("input");
for(var i=0; i<inputElem.length; i++){
if(inputElem[i].id.indexOf(cbid)!=-1){
inputElem[i].checked = cb.checked;
}
}

document.getElementById("allSelected").checked = allchecked;

addtoSelectedListAF();
}
function closeWindow(){
//window.opener.parent.location.href = '/{!contactId}';
window.self.close();
return false;

}
function testingactionfunction(){

addtoSelectedListAF();
}
function changeUrl(url) {
location.href = url;
window.reload();
}



</script>


</apex:form>

</apex:page>

___________________________________________________________________________________________


public with sharing class ContactCodeExtension {

public List<ContactCodeDescWrapper> wrapperList {set;get;}

public String contactId {set;get;}
public Contact con {set;get;}



private Set<Id> selectedCodeDescs;

Public static List<ContactCodeDescription__c> backupContactCodes { set; get;}
public string selectedCCDesc {get; set;}
Public static Boolean renderSetbackupCC = false;
Public static Boolean isPageLoad {get;set;}
public List<ContactCodeDescWrapper> selectedWrapperList {set;get;}
public set<Id> setId {set;get;}

//****************************************************************************
//Constructor
//***************************************************************************/
public ContactCodeExtension(ApexPages.StandardController stdController){
contactId = Apexpages.currentPage().getParameters().get('contactId');
init();

}




//////////////////////////////// Private Methods ////////////////////////////
//****************************************************************************
// Method for initialization
///***************************************************************************/
private void init(){

//
system.debug('***renderSetbackupCC1'+renderSetbackupCC);
//renderSetbackupCC = false;
system.debug('***renderSetbackupCC2'+renderSetbackupCC);
isPageLoad = true;
System.Debug('***renderSetbackupCC'+renderSetbackupCC);
backupContactCodes = new List<ContactCodeDescription__c>();
////

wrapperList = new List<ContactCodeDescWrapper>();
selectedWrapperList = new List<ContactCodeDescWrapper>();
setId = new set<Id>();


selectedCodeDescs = new Set<Id>();

if(contactId != null){

populateContactCode();
getContact();
system.debug('***renderSetbackupCC3'+renderSetbackupCC);
addtoSelectedList();
addtoTEst();
system.debug('***renderSetbackupCC6'+renderSetbackupCC);
}else{
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,'Please associate Contact Codes directly from the Contact object.'));
}
}
private void getContact(){
for(Contact contact : [select Id,name,Email,Phone,MobilePhone from Contact where Id =:contactId limit 1]){
con = contact;
}
}

public void backupSelection(){
selectedCodeDescs.clear();
for(ContactCodeDescWrapper wrapper : wrapperList){
if(wrapper.isSelected){
selectedCodeDescs.add(wrapper.ccDesc.Id);
}
}

System.Debug('***wrapperList'+wrapperList);
}

//Cancel
Public void cancel(){


}

//****************************************************************************
// Method to populate contact code
///***************************************************************************/
public void populateContactCode(){
String query ='Select Description__c From ContactCodeDescription__c';


backupSelection();

System.Debug('***selectedCodeDescs populateContactCode'+selectedCodeDescs);
System.Debug('***wrapperList populateContactCode'+wrapperList);

for(Id ccDesc : selectedCodeDescs)
setId.add(ccDesc);

//selectedWrapperList.add(new ContactCodeDescWrapper(ccDesc,selectedCodeDescs.contains(ccDesc.Id))) ;

Map<ContactCodeDescription__c,boolean> ccDescStatus = new Map<ContactCodeDescription__c,boolean>();

for(ContactCodeDescWrapper wrapper : wrapperList){
ccDescStatus.put(wrapper.ccDesc,wrapper.isSelected);
//If(selectedWrapperList.contains(wrapper))
//selectedWrapperList.put(wrapper.ccDesc, wrapper.isSelected);

}

for(ContactCodeDescWrapper wrapper : selectedWrapperList ){
If(ccDescStatus.containskey(wrapper.ccDesc) != null){
If(ccDescStatus.containskey(wrapper.ccDesc)){
If(wrapper.isSelected != ccDescStatus.get(wrapper.ccDesc))
wrapper.isSelected= ccDescStatus.get(wrapper.ccDesc);
}
}


}

wrapperList.clear();
for(ContactCodeDescription__c ccDesc : Database.query(query)){
wrapperList.add(new ContactCodeDescWrapper(ccDesc,selectedCodeDescs.contains(ccDesc.Id)));
system.Debug('***isPageLoad'+isPageLoad);
If(isPageLoad != null && isPageLoad ){

selectedWrapperList.add(new ContactCodeDescWrapper(ccDesc,selectedCodeDescs.contains(ccDesc.Id)));
}

}
isPageLoad = false;
for(ContactCodeDescWrapper wrapper : wrapperList){

If(setId.contains(wrapper.ccDesc.Id)){
wrapper.isSelected = true;
}
}

System.debug('wrapperList 1 ***' + wrapperList.size());


}

public void addtoSelectedList(){

//wrapperList = new List<ContactCodeDescWrapper>();
backupContactCodes = new List<ContactCodeDescription__c>();

System.Debug('***wrapperList'+wrapperList);
//searchedWrapperList

System.Debug('***wrapperList.size'+wrapperList.size());

System.Debug('***backupContactCodes'+backupContactCodes);
//

Map<ContactCodeDescription__c,boolean> ccDescStatus = new Map<ContactCodeDescription__c,boolean>();

for(ContactCodeDescWrapper wrapper : wrapperList){
ccDescStatus.put(wrapper.ccDesc,wrapper.isSelected);
//If(selectedWrapperList.contains(wrapper))
//selectedWrapperList.put(wrapper.ccDesc, wrapper.isSelected);

}

for(ContactCodeDescWrapper wrapper : selectedWrapperList ){
If(ccDescStatus.containskey(wrapper.ccDesc)){
If(wrapper.isSelected != ccDescStatus.get(wrapper.ccDesc))
wrapper.isSelected= ccDescStatus.get(wrapper.ccDesc);

}


}

system.Debug('***selectedWrapperList'+selectedWrapperList);
For( ContactCodeDescWrapper wrapper : selectedWrapperList ){

If(wrapper.isSelected){
backupContactCodes.add(wrapper.ccDesc);
//rendered="{!renderSetbackupCC}"
system.debug('***renderSetbackupCC5'+renderSetbackupCC);
renderSetbackupCC = true;
}

}
system.debug('***renderSetbackupCC6'+renderSetbackupCC);
If(backupContactCodes.size() > 0)
renderSetbackupCC = true;

System.Debug('***wrapperList'+wrapperList);
System.Debug('***backupContactCodes'+backupContactCodes);

System.Debug('***renderSetbackupCC '+renderSetbackupCC );

System.Debug('***renderSetbackupCC '+renderSetbackupCC );

System.Debug('***selectedCCDesc'+selectedCCDesc);

}
public void addtoTEst(){

system.Debug('***isPageLoadALLL'+isPageLoad);

If(isPageLoad){
For( ContactCodeDescWrapper wrapper : wrapperList ){

//If(wrapper.isSelected)
backupContactCodes.add(wrapper.ccDesc);
//rendered="{!renderSetbackupCC}"

//renderSetbackupCC = true;

}
}
}

//****************************************************************************
//Wrapper Class for ContactCodeDescription__c
//***************************************************************************/
public class ContactCodeDescWrapper{
public ContactCodeDescription__c ccDesc {set;get;}
public boolean isSelected {set;get;}
//Constructor
public ContactCodeDescWrapper(ContactCodeDescription__c ccDesc,Boolean isSelected){
this.isSelected = isSelected;
this.ccDesc = ccDesc;

}
}
}

 

Please let me know. How to fix this.

 

Thanks

Hi

 

My formula is exceeding 5000 characters while compiling.

 

Here is the formula

 

________________________________________________________________________________________

 

 

IF(US_Account_Manager__c != null,If(EU_Account_Manager__c != null,If(US_Relationship_Manager__c != null,If(EU_Relationship_Manager__c != null,

1234

,

123

),If(EU_Relationship_Manager__c != null,

124

,

12

)),

If(US_Relationship_Manager__c != null,If(EU_Relationship_Manager__c != null,

134

,

13

),If(EU_Relationship_Manager__c != null,

14

,

1

)))

,If(EU_Account_Manager__c != null,If(US_Relationship_Manager__c != null,If(EU_Relationship_Manager__c != null,

234

,

23

),If(EU_Relationship_Manager__c != null,

24

,

2

)),If(US_Relationship_Manager__c != null,If(EU_Relationship_Manager__c != null,

34

,

3

),If(EU_Relationship_Manager__c != null,

4

,

''

))))

 

----------------------------------------------------------------------------

A1 = US_Account_Manager__c != null

A2 = EU_Account_Manager__c != null

A3 = US_Relationship_Manager__c != null

A4 = EU_Relationship_Manager__c != null

-------------------------------------------------------------------------------------

1 = US_Account_Manager__r.FirstName + US_Account_Manager__r.LastName  + ' ' + '(US CSM)'+' '+','+' '+

2 = EU_Account_Manager__r.FirstName + EU_Account_Manager__r.LastName + ' ' + '(EU CSM)'+' '+' ,'+' '+

3 = US_Relationship_Manager__r.FirstName + US_Relationship_Manager__r.LastName + ' ' + '(US RM)'+' '+','+' '+

4 = EU_Relationship_Manager__r.FirstName + EU_Relationship_Manager__r.LastName + ' ' + '(EU RM)'

 

_________________________________________________________________________________________

Hi

 

I have a formula which is exceeding 5000 characters when compiling.

 

I used AccountMAnager__r.Firstname+' '+AccountMAnager__r.Lastname in the formula. I see that there is Name standard field on User object. This field is not accessible in Formula field.

 

Is there any way to reduce my formula characters while compiling. Please help.

 

Thanks

 

 

 

Hi I have an issue in code with Aggregate query.

 

I have an object Deal Summary which sums up fields in Opportunity products and displays as related list in opportunity.

 

This is done by an after update trigger on oppportunity. But here if the currency of an Opportunity product is CAD, It shows up the deal Summary in USD; because the aggregate query is aggregating everything in USD.

 

Here is my trigger

 

Trigger SGSFA_NA_UPDATE_DEAL_SUMMARY on Opportunity (After Update) {
If(!OpptyDS_LoopFollowUp.hasAlreadyRun()){
    OpptyDS_LoopFollowUp.setAlreadyRun();
    
    

    List<ID> O_Id = New List<ID>{};
    System.Debug('Opportuniy Ids List here'+O_Id); 
    
    
    List<Deal_Credit__c> DSummaryUpsertList = New  List<Deal_Credit__c> {};  
    System.Debug('DealSummaryUpsertList'+DSummaryUpsertList);  
    
    Map<String,ID> DSummaryMap = New Map<String,ID>();
    System.Debug('DSummaryMap'+DSummaryMap);
    
    List<OpportunityLineItem> oli_Update = New List<OpportunityLineItem>();
    System.Debug('oli_Update'+oli_Update);
    
    Decimal CRR = 0, GCR = 0, OTF = 0, MRR = 0, MRR_C=0;                           
    
    For(Opportunity O: Trigger.New){  If(O.Record_Type_Name__c.indexOf('NA') != -1) {  O_Id.add(O.ID);}}
    
   

    List<OpportunityLineItem> oli = [SELECT ID, OpportunityID, deal_summary__c, schedule_id__c,CurrencyIsoCode FROM OpportunityLineItem 
                                     WHERE OpportunityID in :O_Id];
                                    
                                    
    System.Debug('oli'+oli);                                         
                   
                                     
    If(!oli.isEmpty()){ //Needed for opportunity with no products created yet but when it's updated
        //Delete existing records
        For(Deal_Credit__c DS: [select ID, Name from Deal_Credit__c WHERE Opportunity__c in :O_Id]){DSummaryMap.put(DS.Name,DS.Id);}
    

        For(AggregateResult ar : [SELECT SUM(Current_Run_Rate__c) CRR, SUM(UnitPrice) MRR, SUM(Incremental_GCR__c) GCR, 
                                        SUM(OTF__c) OTF, SUM(Gross_MRR__c) MRR_Credit, Schedule_ID__c, OpportunityID
                                        FROM OpportunityLineItem WHERE OpportunityID in :O_Id GROUP BY OpportunityID, Schedule_ID__c]){
                                        
                                        System.Debug('Agg Results'+ar);
            CRR = 0; GCR = 0; OTF = 0; MRR = 0; MRR_C = 0; 
            If(ar.get('MRR')+ '' != '' && ar.get('MRR')!=null) MRR =  (Decimal.valueOf(ar.get('MRR')+''));
            If(ar.get('GCR')+ '' != '' && ar.get('GCR') != null) GCR=  Decimal.valueOf(ar.get('GCR')+'');
            If(ar.get('CRR')+ '' != '' && ar.get('CRR')!= null ) CRR=  Decimal.valueOf(ar.get('CRR')+'');
            If(ar.get('OTF')+ '' != '' &&  ar.get('OTF')!= null ) OTF=  Decimal.valueOf(ar.get('OTF')+'');
            If(ar.get('MRR_Credit')+ '' != ''&&  ar.get('MRR_Credit')!= null ) MRR_C=  Decimal.valueOf(ar.get('MRR_Credit')+'');
            If(ar.get('Schedule_ID__c')!= null){
                If(!DSummaryMap.containsKey(ar.get('Schedule_ID__c')+ '')){
                
                
                    DSummaryUpsertList.add(new Deal_Credit__c(Name = ar.get('Schedule_ID__c')+ '', Opportunity__c = ar.get('OpportunityID')+ '',
                                        Incremental_MRR__c = MRR, Current_Run_Rate__c = CRR, Incremental_GCR__c = GCR, 
                                        One_Time_Fee__c = OTF,MRR_Credit__c = MRR_C)); // Needs revision
                                        System.Debug('In If loop'+DSummaryUpsertList);
                } Else {
                    DSummaryUpsertList.add(new Deal_Credit__c(Name = ar.get('Schedule_ID__c')+ '', Opportunity__c = ar.get('OpportunityID')+ '',
                                        Incremental_MRR__c = MRR, Current_Run_Rate__c = CRR, Incremental_GCR__c = GCR, //CurrencyIsoCode = String.valueof(ar.get('CurrencyIsoCode')),
                                        One_Time_Fee__c = OTF,MRR_Credit__c = MRR_C, Id = DSummaryMap.get(ar.get('Schedule_ID__c')+ ''))); // Updates old record
                                        System.Debug('In Else loop'+DSummaryUpsertList);
                }
            }
        }
        If(!DSummaryUpsertList.isEmpty()){Upsert DSummaryUpsertList;}// If Schedule Ids are null from above
        // Upsert will updates old ones and inserts new records
        System.Debug('DSummaryUpsertList'+DSummaryUpsertList);
        For(Deal_Credit__c dc: DSummaryUpsertList){
            For(OpportunityLineItem ol: oli){
                If((dc.name == ol.schedule_id__c && dc.Opportunity__c == ol.OpportunityID) 
                    && (ol.deal_summary__c == Null || ol.deal_summary__c != dc.id)){  
                    ol.deal_summary__c = dc.id;  
                    oli_Update.add(ol); // To update only for product with new deal summary value
                }
                
                
            }
        }
        If(!oli_Update.isEmpty()){ Update oli_Update;} // When all products have deal summary field set
    }
    
  
}  

    
       
    
   
}

 

Please help. I am stuck here. How do aggregate in Canadian Dollars.

Hi

Test Methods in our org failed suddenly with the following error:

 

Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, SGSFA_OPPTY_UK_UPDATE_CNTRCT: execution of AfterUpdate caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact ...

 

It seems the test methods failed because of a trigger on oppportunity after update

 Here is the trigger:

 trigger SGSFA_OPPTY_UK_UPDATE_CNTRCT on Opportunity (after update) {
    //Trigger to uncheck Related Opportunity checkbox from contract object
     
     //Select UK Record Type
     RecordType rType =    [Select Id From RecordType 
                            where sObjectType='Opportunity'
                            and DeveloperName = 'UK_All_opportunity_rec_type' 
                            and isActive=true
                            limit 1];
                            
     List<Id> lstOppID = new List<Id>();
     
     for(Opportunity o : Trigger.New){
        if(o.recordTypeID == rType.Id){
            lstOppID.add(o.Id);
        }
     }
     
     List<Id> lstCloseDateChanged =  new List<id>();
     
     for(Opportunity o : Trigger.New){
           if(o.CloseDate != Trigger.oldMap.get(o.id).CloseDate)
              lstCloseDateChanged.add(o.id);      
     }
     
     //find the list of contracts to update
     List<Contract> lstCntrct = new List<Contract> ();
     lstCntrct = [select id, Related_Opportunity__c from contract c
                                 where c.id in (select o.Contract_ID__c From OpportunityLineItem o 
                                                where o.OpportunityID in :lstOppID)
                                 and c.id not in (select o1.Contract_ID__c From OpportunityLineItem o1
                                                  where o1.Opportunity.IsClosed = False)
                                ];
     //set related opportunity field to false and update the contract list                          
     if(!lstCntrct.isEmpty()) {
        for(Integer i = 0; i < lstCntrct.size(); i++){
            lstCntrct[i].Related_Opportunity__c = false;
        }
        
        update lstCntrct;   
     } 
     
     //update all opportunity products if the close date changed. This will trigged the WF rules
     if(!lstCloseDateChanged.isEmpty()){
         List<OpportunityLineItem> lstLine = [select id From OpportunityLineItem o 
                                                 where o.OpportunityID in :lstCloseDateChanged];
         if(!lstLine.isEmpty())
             update lstLine;
     }
}

 

I don't understand what is making test method fail. Any help will be greatly appreciated. Thanks

 

Below is the test method which is failing at Insert oppli

 

 static testmethod void test_batchoppty()
    {
          
        List<Opportunity> oppna = new List<Opportunity>();        
        List<Contact> cont = new List<Contact>();        
        List<OpportunityContactRole> controle = new List<OpportunityContactRole>();    
        
        System.runAs(SalesRep){
            Opportunity oppna1 = new Opportunity();
            Opportunity oppna2 = new Opportunity();
            Opportunity oppna3 = new Opportunity();
            Account acc = new Account();
            acc.Name='Test Acc';
            insert acc;
            RecordType rec = [Select id from RecordType where SObjectType='Opportunity' AND Name like 'NA%' limit 1];
            oppna1.recordtypeId = rec.Id;
            oppna1.AccountId=acc.Id;
            oppna1.Name='Test';
            oppna1.CloseDate=system.today();
            oppna1.StageName='1-In Legal';
            oppna1.Oracle_Quote_ID__c = 'Test001';
            oppna.add(oppna1);
            insert oppna;
            
            Contact ct1 = new Contact(FirstName='TestContact1', LastName = 'Test',AccountId=acc.Id);
        cont.add(ct1);
        //Contact ct2 = new Contact(FirstName='TestContact2', LastName = 'Test',AccountId=acc.Id);
        //cont.add(ct2);
        //Contact ct3 = new Contact(FirstName='TestContact3', LastName = 'Test',AccountId=acc.Id);
       // cont.add(ct3);
            insert cont;
            
            OpportunityContactRole cr1 = new OpportunityContactRole(ContactId = ct1.id , OpportunityId= oppna1.Id);
            controle.add(cr1);
            //OpportunityContactRole cr2 = new OpportunityContactRole(ContactId = ct2.id , OpportunityId= oppna2.Id);
            // controle.add(cr2);
            //OpportunityContactRole cr3 = new OpportunityContactRole(ContactId = ct3.id , OpportunityId= oppna3.Id);
           //controle.add(cr3);
           
           insert controle;
            
            Product2 prd1 = new Product2(Name='TestProduct1',Family='Recovery Services'); 
            Product2 prd2 = new Product2(Name='TestProduct2',Family='Managed Services');
            Product2 prd3 = new Product2(Name='TestProduct3',Family='Recovery Services');
            Product2 prd4 = new Product2(Name='TestProduct4',Family='Consulting Services');
            Product2 prd5 = new Product2(Name='TestProduct5',Family='Software Services');
            Product2[] prd = new Product2[]{prd1,prd2,prd3,prd4,prd5};
            insert prd;
            
            Pricebook2 pb = [select Id from Pricebook2 where IsStandard=true]; 
            
            PricebookEntry pbe1 = new PricebookEntry(Product2Id=prd[0].Id, Pricebook2Id=pb.Id,UnitPrice=12,IsActive=true);
            PricebookEntry pbe2 = new PricebookEntry(Product2Id=prd[1].Id, Pricebook2Id=pb.Id,UnitPrice=14,IsActive=true);
            PricebookEntry pbe3 = new PricebookEntry(Product2Id=prd[2].Id, Pricebook2Id=pb.Id,UnitPrice=13,IsActive=true);
            PricebookEntry pbe4 = new PricebookEntry(Product2Id=prd[3].Id, Pricebook2Id=pb.Id,UnitPrice=12,IsActive=true);
            PricebookEntry pbe5 = new PricebookEntry(Product2Id=prd[4].Id, Pricebook2Id=pb.Id,UnitPrice=14,IsActive=true);
            PricebookEntry[] pbe = new PricebookEntry[]{pbe1,pbe2,pbe3,pbe4,pbe5};
            insert pbe; 
            
            OpportunityLineItem oli1 = new OpportunityLineItem(OpportunityId=oppna[0].Id,PricebookEntryId=pbe[0].Id,Quantity=2,TotalPrice=20,Incremental_GCR__c=12,Gross_GCR__c=22,Gross_MRR__c=21,Stretch_MRR__c=11);
            OpportunityLineItem oli2 = new OpportunityLineItem(OpportunityId=oppna[0].Id,PricebookEntryId=pbe[1].Id,Quantity=1,TotalPrice=24,Incremental_GCR__c=12,Gross_GCR__c=22,Gross_MRR__c=21,Stretch_MRR__c=11);
            OpportunityLineItem oli3 = new OpportunityLineItem(OpportunityId=oppna[0].Id,PricebookEntryId=pbe[2].Id,UnitPrice=null,Quantity=2,TotalPrice=20,Incremental_GCR__c=12,Gross_GCR__c=22,Gross_MRR__c=21,Stretch_MRR__c=11);
            OpportunityLineItem oli4 = new OpportunityLineItem(OpportunityId=oppna[0].Id,PricebookEntryId=pbe[3].Id,Quantity=2,TotalPrice=20,Incremental_GCR__c=12,Gross_GCR__c=22,Gross_MRR__c=21,Stretch_MRR__c=11);
            OpportunityLineItem oli5 = new OpportunityLineItem(OpportunityId=oppna[0].Id,PricebookEntryId=pbe[4].Id,Quantity=2,TotalPrice=20,Incremental_GCR__c=12,Gross_GCR__c=22,Gross_MRR__c=21,Stretch_MRR__c=11);
            OpportunityLineItem[] oppli = new OpportunityLineItem[]{oli1,oli2,oli3,oli4,oli5};
            insert oppli;
     

Test Classes in Production have failed suddenly with the following DML Exception. Please help.

 

Here is the error:

 

System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_USERNAME, Duplicate Username.<br>Another user has already selected this username.<br>Please select another.: [Username]

 

Class.SGPRM_TestingClass.testSGPRM_OwnerChange_Before_Update: line 14, column 1

 

Here is the test class

 

@isTest
private class SGPRM_TestingClass
{

   //*#*Test Method for SGPRM_OwnerChange_Before_Update Trigger
    static testMethod void testSGPRM_OwnerChange_Before_Update() {
        
        Profile Profile1 = [select id from profile where name='System Administrator'];
        Profile Profile2 = [select id from profile where name='Standard User'];
        User CEO = new User(alias = 'ceo', email='admin@testorg.com',
        emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
        localesidkey='en_US', profileid = Profile1.Id,
        timezonesidkey='America/Los_Angeles', username='admin@testorg.com');
        insert CEO;
        User SalesManager = new User(alias = 'smngr', email='sManager@testorg.com',
        emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
        localesidkey='en_US', profileid = Profile2.Id, managerId = CEO.id,
        timezonesidkey='America/Los_Angeles', username='sManager@testorg.com');
        insert SalesManager;
        
        User SalesRep = [Select Id,Name,Email,managerId ,timezonesidkey from User where Name = 'Deborah BUELL' ];
        System.runAs(SalesRep)
        {
        Id RT = [select id from RecordType where SObjectType = 'Lead' AND developerName = 'DealRegistration'][0].Id;
        Lead lead = new Lead();
        lead.RecordTypeId = RT;
        lead.firstname = 'Test';
        lead.lastname = 'User';
        lead.Company = 'Test Group';
        lead.city = 'Test';
        lead.state = 'NJ';
        lead.country = 'United States';
        //lead.OwnerId = '005A0000000iviM';
        insert lead;

        Test.startTest();
        // Lead Submitted for Approval
        lead.Status = 'Submitted for Approval';
        lead.OwnerId = SalesManager.Id;
        update lead;
        Test.stopTest();
        }
    }}

I am trying to create a new custom object Candidates with Auto number.

 

But when I give starting number: C-{00001}; It gives error Invalid number.

Also give some permissions warning. Please help.

 

 

 



Hi,

 

I have a VF page and Controller class. I have two page blocks. First page block loads all the data and second pageblock must be rendered if any record in first page block is selected. The rendered attribute is not working based on the list size.

 

Here is the code

 

<apex:page standardController="Contact" extensions="ContactCodeExtension" id="pg">

<apex:form id="frm">
<apex:outputPanel id="errorPnl">
<apex:pageMessages />
</apex:outputPanel>
<!------------------------------------------------------------- ACTION FUNCTIONS ---------------------------------------------------------------------------->

<apex:actionFunction action="{!populateContactCode}" name="populateContactCodeAF" reRender="pbResult,errorPnl" status="actionStatus" >
</apex:actionFunction>

<apex:actionFunction action="{!addtoSelectedList}" name="addtoSelectedListAF" reRender="pbResult2,errorPnl" status="actionStatus"/ >
<apex:actionFunction action="{!addtoTEst}" name="addtoTEstAF" reRender="pbResult2" status="actionStatus"/>
<!------------------------------------------------------------- ACTION FUNCTIONS ---------------------------------------------------------------------------->

<apex:pageBlock rendered="{!if(contactId != null,true,false)}" id="pb">

<apex:pageBlockButtons id="pgButtons">

<apex:commandButton value="Cancel" action="{!cancel}" />


<apex:actionStatus id="actionStatus" startText="Please wait....">
<apex:facet name="start">&nbsp;&nbsp;<apex:image value="/img/indicator.gif"/></apex:facet>
<apex:facet name="stop"></apex:facet>
</apex:actionStatus>

</apex:pageBlockButtons>


<h1 style="font-weight:bold;font-size:20px">Adding Contact Codes for {!con.Name}.</h1>

<br/>
<br/>
<apex:pageBlocksection title="Contact Codes" columns="1" id="pbResult">
<apex:outputPanel rendered="{!if(wrapperList.size>0,true,false)}">
<table><tr><td>
<div style="overflow:auto; height:470px;width:870px;">
<apex:pageBlockTable id="resultTable" value="{!wrapperList}" var="wrapper" rendered="{!if(wrapperList.size>0,true,false)}">
<apex:column >
<apex:facet name="header">
<apex:inputCheckbox id="allSelected" onclick="checkAll(this,'checkdone');addtoTEstAF();" />
</apex:facet>
<apex:inputCheckbox value="{!wrapper.isSelected}" id="checkdone" onclick="addtoSelectedListAF();"/>


</apex:column>

<apex:column >
<apex:facet name="header">
<apex:outputPanel >
cade444
</apex:outputPanel>
</apex:facet>
<apex:outputField value="{!wrapper.ccDesc.Description__c}" />
</apex:column>
<apex:column >
<apex:facet name="header">
code
</apex:facet>
<apex:outputField value="{!wrapper.ccDesc.Description__c}" />
</apex:column>
</apex:pageBlockTable>
</div> </td></tr></table>
</apex:outputPanel>
<apex:outputPanel rendered="{!If(wrapperList.size = 0,true,false)}" id="errMsg">
<span style="color:red;">No Records found</span>
</apex:outputPanel>


</apex:pageblocksection>
</apex:pageBlock>
<apex:pageBlock rendered="{!If(backupContactCodes.size>0,true,false)}" id="pbResult2">
<apex:pageblocksection title="Selected Contact Codes" columns="1" >
<apex:outputpanel id="ProductUnitsInformation" >
<table><tr><td>
<div style="overflow:auto; height:470px;width:870px;">
<apex:pageBlockTable id="resultTable2" value="{!backupContactCodes}" var="wrapper2">

<apex:column >
<apex:facet name="header">
<apex:outputPanel >

Code Description

</apex:outputPanel>
</apex:facet>
<apex:outputField value="{!wrapper2.Description__c}" title="Code Description"/>
</apex:column>
</apex:pageBlockTable>
</div> </td></tr></table>
</apex:outputpanel>


</apex:pageBlocksection>
</apex:pageBlock>


<!-- // @Sashi Singh -- 09/19/2013 -- RRM Request Number -- REQ-00002156 -->
<input type="hidden" id="oldCodeType" value="" />

<script type="text/javascript">
function checkAll(cb,cbid){
var allchecked = cb.checked;
var inputElem = document.getElementsByTagName("input");
for(var i=0; i<inputElem.length; i++){
if(inputElem[i].id.indexOf(cbid)!=-1){
inputElem[i].checked = cb.checked;
}
}

document.getElementById("allSelected").checked = allchecked;

addtoSelectedListAF();
}
function closeWindow(){
//window.opener.parent.location.href = '/{!contactId}';
window.self.close();
return false;

}
function testingactionfunction(){

addtoSelectedListAF();
}
function changeUrl(url) {
location.href = url;
window.reload();
}



</script>


</apex:form>

</apex:page>

___________________________________________________________________________________________


public with sharing class ContactCodeExtension {

public List<ContactCodeDescWrapper> wrapperList {set;get;}

public String contactId {set;get;}
public Contact con {set;get;}



private Set<Id> selectedCodeDescs;

Public static List<ContactCodeDescription__c> backupContactCodes { set; get;}
public string selectedCCDesc {get; set;}
Public static Boolean renderSetbackupCC = false;
Public static Boolean isPageLoad {get;set;}
public List<ContactCodeDescWrapper> selectedWrapperList {set;get;}
public set<Id> setId {set;get;}

//****************************************************************************
//Constructor
//***************************************************************************/
public ContactCodeExtension(ApexPages.StandardController stdController){
contactId = Apexpages.currentPage().getParameters().get('contactId');
init();

}




//////////////////////////////// Private Methods ////////////////////////////
//****************************************************************************
// Method for initialization
///***************************************************************************/
private void init(){

//
system.debug('***renderSetbackupCC1'+renderSetbackupCC);
//renderSetbackupCC = false;
system.debug('***renderSetbackupCC2'+renderSetbackupCC);
isPageLoad = true;
System.Debug('***renderSetbackupCC'+renderSetbackupCC);
backupContactCodes = new List<ContactCodeDescription__c>();
////

wrapperList = new List<ContactCodeDescWrapper>();
selectedWrapperList = new List<ContactCodeDescWrapper>();
setId = new set<Id>();


selectedCodeDescs = new Set<Id>();

if(contactId != null){

populateContactCode();
getContact();
system.debug('***renderSetbackupCC3'+renderSetbackupCC);
addtoSelectedList();
addtoTEst();
system.debug('***renderSetbackupCC6'+renderSetbackupCC);
}else{
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,'Please associate Contact Codes directly from the Contact object.'));
}
}
private void getContact(){
for(Contact contact : [select Id,name,Email,Phone,MobilePhone from Contact where Id =:contactId limit 1]){
con = contact;
}
}

public void backupSelection(){
selectedCodeDescs.clear();
for(ContactCodeDescWrapper wrapper : wrapperList){
if(wrapper.isSelected){
selectedCodeDescs.add(wrapper.ccDesc.Id);
}
}

System.Debug('***wrapperList'+wrapperList);
}

//Cancel
Public void cancel(){


}

//****************************************************************************
// Method to populate contact code
///***************************************************************************/
public void populateContactCode(){
String query ='Select Description__c From ContactCodeDescription__c';


backupSelection();

System.Debug('***selectedCodeDescs populateContactCode'+selectedCodeDescs);
System.Debug('***wrapperList populateContactCode'+wrapperList);

for(Id ccDesc : selectedCodeDescs)
setId.add(ccDesc);

//selectedWrapperList.add(new ContactCodeDescWrapper(ccDesc,selectedCodeDescs.contains(ccDesc.Id))) ;

Map<ContactCodeDescription__c,boolean> ccDescStatus = new Map<ContactCodeDescription__c,boolean>();

for(ContactCodeDescWrapper wrapper : wrapperList){
ccDescStatus.put(wrapper.ccDesc,wrapper.isSelected);
//If(selectedWrapperList.contains(wrapper))
//selectedWrapperList.put(wrapper.ccDesc, wrapper.isSelected);

}

for(ContactCodeDescWrapper wrapper : selectedWrapperList ){
If(ccDescStatus.containskey(wrapper.ccDesc) != null){
If(ccDescStatus.containskey(wrapper.ccDesc)){
If(wrapper.isSelected != ccDescStatus.get(wrapper.ccDesc))
wrapper.isSelected= ccDescStatus.get(wrapper.ccDesc);
}
}


}

wrapperList.clear();
for(ContactCodeDescription__c ccDesc : Database.query(query)){
wrapperList.add(new ContactCodeDescWrapper(ccDesc,selectedCodeDescs.contains(ccDesc.Id)));
system.Debug('***isPageLoad'+isPageLoad);
If(isPageLoad != null && isPageLoad ){

selectedWrapperList.add(new ContactCodeDescWrapper(ccDesc,selectedCodeDescs.contains(ccDesc.Id)));
}

}
isPageLoad = false;
for(ContactCodeDescWrapper wrapper : wrapperList){

If(setId.contains(wrapper.ccDesc.Id)){
wrapper.isSelected = true;
}
}

System.debug('wrapperList 1 ***' + wrapperList.size());


}

public void addtoSelectedList(){

//wrapperList = new List<ContactCodeDescWrapper>();
backupContactCodes = new List<ContactCodeDescription__c>();

System.Debug('***wrapperList'+wrapperList);
//searchedWrapperList

System.Debug('***wrapperList.size'+wrapperList.size());

System.Debug('***backupContactCodes'+backupContactCodes);
//

Map<ContactCodeDescription__c,boolean> ccDescStatus = new Map<ContactCodeDescription__c,boolean>();

for(ContactCodeDescWrapper wrapper : wrapperList){
ccDescStatus.put(wrapper.ccDesc,wrapper.isSelected);
//If(selectedWrapperList.contains(wrapper))
//selectedWrapperList.put(wrapper.ccDesc, wrapper.isSelected);

}

for(ContactCodeDescWrapper wrapper : selectedWrapperList ){
If(ccDescStatus.containskey(wrapper.ccDesc)){
If(wrapper.isSelected != ccDescStatus.get(wrapper.ccDesc))
wrapper.isSelected= ccDescStatus.get(wrapper.ccDesc);

}


}

system.Debug('***selectedWrapperList'+selectedWrapperList);
For( ContactCodeDescWrapper wrapper : selectedWrapperList ){

If(wrapper.isSelected){
backupContactCodes.add(wrapper.ccDesc);
//rendered="{!renderSetbackupCC}"
system.debug('***renderSetbackupCC5'+renderSetbackupCC);
renderSetbackupCC = true;
}

}
system.debug('***renderSetbackupCC6'+renderSetbackupCC);
If(backupContactCodes.size() > 0)
renderSetbackupCC = true;

System.Debug('***wrapperList'+wrapperList);
System.Debug('***backupContactCodes'+backupContactCodes);

System.Debug('***renderSetbackupCC '+renderSetbackupCC );

System.Debug('***renderSetbackupCC '+renderSetbackupCC );

System.Debug('***selectedCCDesc'+selectedCCDesc);

}
public void addtoTEst(){

system.Debug('***isPageLoadALLL'+isPageLoad);

If(isPageLoad){
For( ContactCodeDescWrapper wrapper : wrapperList ){

//If(wrapper.isSelected)
backupContactCodes.add(wrapper.ccDesc);
//rendered="{!renderSetbackupCC}"

//renderSetbackupCC = true;

}
}
}

//****************************************************************************
//Wrapper Class for ContactCodeDescription__c
//***************************************************************************/
public class ContactCodeDescWrapper{
public ContactCodeDescription__c ccDesc {set;get;}
public boolean isSelected {set;get;}
//Constructor
public ContactCodeDescWrapper(ContactCodeDescription__c ccDesc,Boolean isSelected){
this.isSelected = isSelected;
this.ccDesc = ccDesc;

}
}
}

 

Please let me know. How to fix this.

 

Thanks

Hi

 

My formula is exceeding 5000 characters while compiling.

 

Here is the formula

 

________________________________________________________________________________________

 

 

IF(US_Account_Manager__c != null,If(EU_Account_Manager__c != null,If(US_Relationship_Manager__c != null,If(EU_Relationship_Manager__c != null,

1234

,

123

),If(EU_Relationship_Manager__c != null,

124

,

12

)),

If(US_Relationship_Manager__c != null,If(EU_Relationship_Manager__c != null,

134

,

13

),If(EU_Relationship_Manager__c != null,

14

,

1

)))

,If(EU_Account_Manager__c != null,If(US_Relationship_Manager__c != null,If(EU_Relationship_Manager__c != null,

234

,

23

),If(EU_Relationship_Manager__c != null,

24

,

2

)),If(US_Relationship_Manager__c != null,If(EU_Relationship_Manager__c != null,

34

,

3

),If(EU_Relationship_Manager__c != null,

4

,

''

))))

 

----------------------------------------------------------------------------

A1 = US_Account_Manager__c != null

A2 = EU_Account_Manager__c != null

A3 = US_Relationship_Manager__c != null

A4 = EU_Relationship_Manager__c != null

-------------------------------------------------------------------------------------

1 = US_Account_Manager__r.FirstName + US_Account_Manager__r.LastName  + ' ' + '(US CSM)'+' '+','+' '+

2 = EU_Account_Manager__r.FirstName + EU_Account_Manager__r.LastName + ' ' + '(EU CSM)'+' '+' ,'+' '+

3 = US_Relationship_Manager__r.FirstName + US_Relationship_Manager__r.LastName + ' ' + '(US RM)'+' '+','+' '+

4 = EU_Relationship_Manager__r.FirstName + EU_Relationship_Manager__r.LastName + ' ' + '(EU RM)'

 

_________________________________________________________________________________________

Hi

 

I have a formula which is exceeding 5000 characters when compiling.

 

I used AccountMAnager__r.Firstname+' '+AccountMAnager__r.Lastname in the formula. I see that there is Name standard field on User object. This field is not accessible in Formula field.

 

Is there any way to reduce my formula characters while compiling. Please help.

 

Thanks

 

 

 

Hello,

         I want to create a apex class and visualforce page which include all the functionallity of chatter like Post, Link, File and Poll.

 

Now i created all the features except poll functionallity. Can Anybody help me on how to create Chatter Poll by using our own visualforce page and controller?

 

thank in advance!!!

Hi

Test Methods in our org failed suddenly with the following error:

 

Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, SGSFA_OPPTY_UK_UPDATE_CNTRCT: execution of AfterUpdate caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact ...

 

It seems the test methods failed because of a trigger on oppportunity after update

 Here is the trigger:

 trigger SGSFA_OPPTY_UK_UPDATE_CNTRCT on Opportunity (after update) {
    //Trigger to uncheck Related Opportunity checkbox from contract object
     
     //Select UK Record Type
     RecordType rType =    [Select Id From RecordType 
                            where sObjectType='Opportunity'
                            and DeveloperName = 'UK_All_opportunity_rec_type' 
                            and isActive=true
                            limit 1];
                            
     List<Id> lstOppID = new List<Id>();
     
     for(Opportunity o : Trigger.New){
        if(o.recordTypeID == rType.Id){
            lstOppID.add(o.Id);
        }
     }
     
     List<Id> lstCloseDateChanged =  new List<id>();
     
     for(Opportunity o : Trigger.New){
           if(o.CloseDate != Trigger.oldMap.get(o.id).CloseDate)
              lstCloseDateChanged.add(o.id);      
     }
     
     //find the list of contracts to update
     List<Contract> lstCntrct = new List<Contract> ();
     lstCntrct = [select id, Related_Opportunity__c from contract c
                                 where c.id in (select o.Contract_ID__c From OpportunityLineItem o 
                                                where o.OpportunityID in :lstOppID)
                                 and c.id not in (select o1.Contract_ID__c From OpportunityLineItem o1
                                                  where o1.Opportunity.IsClosed = False)
                                ];
     //set related opportunity field to false and update the contract list                          
     if(!lstCntrct.isEmpty()) {
        for(Integer i = 0; i < lstCntrct.size(); i++){
            lstCntrct[i].Related_Opportunity__c = false;
        }
        
        update lstCntrct;   
     } 
     
     //update all opportunity products if the close date changed. This will trigged the WF rules
     if(!lstCloseDateChanged.isEmpty()){
         List<OpportunityLineItem> lstLine = [select id From OpportunityLineItem o 
                                                 where o.OpportunityID in :lstCloseDateChanged];
         if(!lstLine.isEmpty())
             update lstLine;
     }
}

 

I don't understand what is making test method fail. Any help will be greatly appreciated. Thanks

 

Below is the test method which is failing at Insert oppli

 

 static testmethod void test_batchoppty()
    {
          
        List<Opportunity> oppna = new List<Opportunity>();        
        List<Contact> cont = new List<Contact>();        
        List<OpportunityContactRole> controle = new List<OpportunityContactRole>();    
        
        System.runAs(SalesRep){
            Opportunity oppna1 = new Opportunity();
            Opportunity oppna2 = new Opportunity();
            Opportunity oppna3 = new Opportunity();
            Account acc = new Account();
            acc.Name='Test Acc';
            insert acc;
            RecordType rec = [Select id from RecordType where SObjectType='Opportunity' AND Name like 'NA%' limit 1];
            oppna1.recordtypeId = rec.Id;
            oppna1.AccountId=acc.Id;
            oppna1.Name='Test';
            oppna1.CloseDate=system.today();
            oppna1.StageName='1-In Legal';
            oppna1.Oracle_Quote_ID__c = 'Test001';
            oppna.add(oppna1);
            insert oppna;
            
            Contact ct1 = new Contact(FirstName='TestContact1', LastName = 'Test',AccountId=acc.Id);
        cont.add(ct1);
        //Contact ct2 = new Contact(FirstName='TestContact2', LastName = 'Test',AccountId=acc.Id);
        //cont.add(ct2);
        //Contact ct3 = new Contact(FirstName='TestContact3', LastName = 'Test',AccountId=acc.Id);
       // cont.add(ct3);
            insert cont;
            
            OpportunityContactRole cr1 = new OpportunityContactRole(ContactId = ct1.id , OpportunityId= oppna1.Id);
            controle.add(cr1);
            //OpportunityContactRole cr2 = new OpportunityContactRole(ContactId = ct2.id , OpportunityId= oppna2.Id);
            // controle.add(cr2);
            //OpportunityContactRole cr3 = new OpportunityContactRole(ContactId = ct3.id , OpportunityId= oppna3.Id);
           //controle.add(cr3);
           
           insert controle;
            
            Product2 prd1 = new Product2(Name='TestProduct1',Family='Recovery Services'); 
            Product2 prd2 = new Product2(Name='TestProduct2',Family='Managed Services');
            Product2 prd3 = new Product2(Name='TestProduct3',Family='Recovery Services');
            Product2 prd4 = new Product2(Name='TestProduct4',Family='Consulting Services');
            Product2 prd5 = new Product2(Name='TestProduct5',Family='Software Services');
            Product2[] prd = new Product2[]{prd1,prd2,prd3,prd4,prd5};
            insert prd;
            
            Pricebook2 pb = [select Id from Pricebook2 where IsStandard=true]; 
            
            PricebookEntry pbe1 = new PricebookEntry(Product2Id=prd[0].Id, Pricebook2Id=pb.Id,UnitPrice=12,IsActive=true);
            PricebookEntry pbe2 = new PricebookEntry(Product2Id=prd[1].Id, Pricebook2Id=pb.Id,UnitPrice=14,IsActive=true);
            PricebookEntry pbe3 = new PricebookEntry(Product2Id=prd[2].Id, Pricebook2Id=pb.Id,UnitPrice=13,IsActive=true);
            PricebookEntry pbe4 = new PricebookEntry(Product2Id=prd[3].Id, Pricebook2Id=pb.Id,UnitPrice=12,IsActive=true);
            PricebookEntry pbe5 = new PricebookEntry(Product2Id=prd[4].Id, Pricebook2Id=pb.Id,UnitPrice=14,IsActive=true);
            PricebookEntry[] pbe = new PricebookEntry[]{pbe1,pbe2,pbe3,pbe4,pbe5};
            insert pbe; 
            
            OpportunityLineItem oli1 = new OpportunityLineItem(OpportunityId=oppna[0].Id,PricebookEntryId=pbe[0].Id,Quantity=2,TotalPrice=20,Incremental_GCR__c=12,Gross_GCR__c=22,Gross_MRR__c=21,Stretch_MRR__c=11);
            OpportunityLineItem oli2 = new OpportunityLineItem(OpportunityId=oppna[0].Id,PricebookEntryId=pbe[1].Id,Quantity=1,TotalPrice=24,Incremental_GCR__c=12,Gross_GCR__c=22,Gross_MRR__c=21,Stretch_MRR__c=11);
            OpportunityLineItem oli3 = new OpportunityLineItem(OpportunityId=oppna[0].Id,PricebookEntryId=pbe[2].Id,UnitPrice=null,Quantity=2,TotalPrice=20,Incremental_GCR__c=12,Gross_GCR__c=22,Gross_MRR__c=21,Stretch_MRR__c=11);
            OpportunityLineItem oli4 = new OpportunityLineItem(OpportunityId=oppna[0].Id,PricebookEntryId=pbe[3].Id,Quantity=2,TotalPrice=20,Incremental_GCR__c=12,Gross_GCR__c=22,Gross_MRR__c=21,Stretch_MRR__c=11);
            OpportunityLineItem oli5 = new OpportunityLineItem(OpportunityId=oppna[0].Id,PricebookEntryId=pbe[4].Id,Quantity=2,TotalPrice=20,Incremental_GCR__c=12,Gross_GCR__c=22,Gross_MRR__c=21,Stretch_MRR__c=11);
            OpportunityLineItem[] oppli = new OpportunityLineItem[]{oli1,oli2,oli3,oli4,oli5};
            insert oppli;
     

Hi All,

 

  Here is my trigger, and I have got an error while writing the test class.

  

trigger UpdateRating on Lead (before update) {
    for(Lead l:Trigger.new)
    {
        if(l.Pardot_Rating__c !=null && l.Pardot_Rating__c =='A')
        {
         l.Rating = 'A';
        }
       else if(l.Pardot_Rating__c !=null && l.Pardot_Rating__c =='B')
        {
         l.Rating ='B';
        }
       else if(l.Pardot_Rating__c !=null && l.Pardot_Rating__c =='C')
        {
         l.Rating = 'C';
        }
     }
}

    Here is the Test Class.

   

@isTest(seeAllData = true)
Private Class TestUpdateRatingTrigger{
 @isTest
 Private Static Void testUpdateRatingTrigger(){
     Test.StartTest();
     Lead testLead = new Lead(
       FirstName = 'TestFirstName',
       LastName = 'TestLastName',
       Email = 'Srinu.mandalapu@stratus.com',
       Phone = '4055090045',
       Prospect_Type__c = 'Direct End User',       
       Title = 'Test Title',
       Company = 'ABC',      
       Status = 'Open',
       Rating = 'A'     
     );
     insert testLead;
     testLead.Rating  = 'B';
     update testLead;
     //verifying updation
     Lead updatedLead = [SELECT Rating FROM Lead WHERE Id = :testLead.Id];
     System.assertEquals('B', updatedLead.Rating);     
     Test.StopTest();
    
 }
}

   Error:

   

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, jigsaw_clean.crmLastModifiedLead: execution of BeforeInsert caused by: line -1, column -1: Previous load of class failed: knowledgecontroller: []

Class.TestUpdateRatingTrigger.testUpdateRatingTrigger: line 17, column 1

   Here "KnowledgeController" is the controller in my org.

 

  Is "knowledgeController" managed package in my org? I saw the packages in my ORG, I did not find any package under that name...

 

  Any help would be greatly aprreciated...

  • March 18, 2012
  • Like
  • 0

Test Classes in Production have failed suddenly with the following DML Exception. Please help.

 

Here is the error:

 

System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_USERNAME, Duplicate Username.<br>Another user has already selected this username.<br>Please select another.: [Username]

 

Class.SGPRM_TestingClass.testSGPRM_OwnerChange_Before_Update: line 14, column 1

 

Here is the test class

 

@isTest
private class SGPRM_TestingClass
{

   //*#*Test Method for SGPRM_OwnerChange_Before_Update Trigger
    static testMethod void testSGPRM_OwnerChange_Before_Update() {
        
        Profile Profile1 = [select id from profile where name='System Administrator'];
        Profile Profile2 = [select id from profile where name='Standard User'];
        User CEO = new User(alias = 'ceo', email='admin@testorg.com',
        emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
        localesidkey='en_US', profileid = Profile1.Id,
        timezonesidkey='America/Los_Angeles', username='admin@testorg.com');
        insert CEO;
        User SalesManager = new User(alias = 'smngr', email='sManager@testorg.com',
        emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
        localesidkey='en_US', profileid = Profile2.Id, managerId = CEO.id,
        timezonesidkey='America/Los_Angeles', username='sManager@testorg.com');
        insert SalesManager;
        
        User SalesRep = [Select Id,Name,Email,managerId ,timezonesidkey from User where Name = 'Deborah BUELL' ];
        System.runAs(SalesRep)
        {
        Id RT = [select id from RecordType where SObjectType = 'Lead' AND developerName = 'DealRegistration'][0].Id;
        Lead lead = new Lead();
        lead.RecordTypeId = RT;
        lead.firstname = 'Test';
        lead.lastname = 'User';
        lead.Company = 'Test Group';
        lead.city = 'Test';
        lead.state = 'NJ';
        lead.country = 'United States';
        //lead.OwnerId = '005A0000000iviM';
        insert lead;

        Test.startTest();
        // Lead Submitted for Approval
        lead.Status = 'Submitted for Approval';
        lead.OwnerId = SalesManager.Id;
        update lead;
        Test.stopTest();
        }
    }}