• Pallavic14
  • NEWBIE
  • 15 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 10
    Replies
I'm trying to query all knowledge articles. I'm using knowledgearticle and knowledgearticleversion objects.
I see there are lot of articles published but are missing in knowledgearticleversion object.
my understanding is all articles should exist in knowledgearticleversion object.
did anyone encounter this issue?
Hi,

I want to add a message on partner portal. when I addeed html sample file I see logo disappeard. I want to add logo inside the headerr html file, I copy pasted url from logo document i ahve in salesforce. logo does'nt show up.
can any one help me how i can use document logo inside my html or have logo and header both at the same time?

Thank you in advance,
Pallavi
Hi,
PLease help.
I have a custom object and a trigger, I see its working in sandbox , with test case coverage of 100% i migrated to production. This trigger is not working.
is there anything to do special for custom triggers?
 when a field is updated , oan custom object record is created with a trigger, after record is created I want opportunity object to be updated back.

Here is the code
trigger UpdateRefExist on Customer_Ref_Design__c (after insert) {
List <Opportunity> oppupdate = new List <Opportunity>();
    for (Customer_Ref_Design__c ref : Trigger.new){
        Opportunity opp = [select Id,RefDesignExist__c from Opportunity where Id = :ref.Oppid__c]; 
        opp.RefDesignExist__c='Y';  
           oppupdate.add(opp);
        }
     try {
         update oppupdate;
         } catch (system.Dmlexception e) {
             system.debug (e);
         }
}

Thanks
Pallavi
Hi,

On homepage I have dashboard snapshot enabled. And Every year we change the dashboard. And users need to manully go into Customize page and pick that dashboard. 
Is there a way to write a script to update to new dashboard with out doing this manually.

THanks
Pallavi
Hi ,

I created a trigger on Lead object and some custom lookup fields to update after insert.
It works fine. I added test code and the code coverage is not covering all code.
Really appreciate of some one can help with what I missed. Here is my trigger and class.
FYI, my test code also includes convert lead whcih is extra.

***Trigger***
trigger UpdateLeadDistifields on Lead (after insert) {
    Set<ID> LeadId = new Set<Id>();
    for (Lead cLead : Trigger.New){
        
        Lead l = [select Id,OwnerId,PartnerAccountId,RecordTypeId from Lead where  Id = :cLead.Id];
        RecordType rt = [select Name FROM RecordType where Id = :l.RecordTypeId];
        
        
        if (rt.name == 'DealRegistration'){
            User u = [select Id ,AccountId from User where Id = :l.OwnerId and AccountId  != '' and ContactId != '' and IsPortalEnabled = true];
            Account a = [select Id, RecordTypeId from Account where Id = :u.AccountId ];
            RecordType accrt = [select Name FROM RecordType where Id = :a.RecordTypeId];
            l.PortalUser__c = u.Id;
        l.PortalAccount__c = u.AccountId;
        if (accrt.Name == 'Distributor'){
            l.DistiAccount__c = l.PartnerAccountId ;
            
            
        }
        
        }else {
            l.PortalUser__c = l.OwnerId;
            l.PortalAccount__c = l.PartnerAccountId;
        }
        update l;
    }
}


********test**********

@IsTest
private class TestXXCSRLeadConvertClass{
 
        static testMethod void TestXXCSRLeadConvertClass() {
       
       test.startTest();
           Boolean bolCreateOpp;
           String strAccountId;
           String strContactId;
            
            User usr = [select Id,PartnerApprover__c,AccountId from User where  Name='Tim House' and IsPortalEnabled = true];
            RecordType rt = [select Id,Name FROM RecordType where Name='Deal Registration'];
            Lead l = new Lead();
            l.FirstName = 'CRM Testing First';
            l.LastName = 'CRM Testing Last';
            l.Company = 'CRM Testing INCtest';
            l.description = 'Test descr';
            l.city = 'test';
            l.street = 'test';
            l.state = 'CA';
            l.country = 'United States';
            l.status = 'Qualified';
            l.email = 'test@testnetgear.com';
            l.website = 'www.testcrm.com';
            l.ApprovalStatus__c='Approved';
            l.RecordTypeId= rt.Id;
            l.OwnerId = usr.Id; //Timhouse
            
                
              
         
            insert l;
         //update
       
        l = [select Id,OwnerId,PartnerAccountId,RecordTypeId,DistiAccount__c,PortalUser__c ,PortalAccount__c from Lead where  Id = :l.Id];
      
           // system.debug("Owner"+l.OwnerId);
         //    system.debug("AccountId"+usr.AccountId);
            if (rt.Name == 'DealRegistration'){
                 User usr1 = [select Id ,AccountId from User where Id = :l.OwnerId and AccountId  != '' and ContactId != '' and IsPortalEnabled = true];
                Account a = [select Id, RecordTypeId from Account where Id = :usr1.AccountId ];
                RecordType accrt = [select Name FROM RecordType where Id = :a.RecordTypeId];
                // user usr1  = [select Id,AccountId from User where Id = :l.OwnerId];
                // Account a = [select Id, RecordTypeId from Account where Id = :usr1.AccountId and IsPartner = true];
                // RecordType accrt = [select Name FROM RecordType where Id = :a.RecordTypeId];
                 system.assertEquals(l.OwnerId,usr1.Id );
                system.assertEquals(l.PartnerAccountId,usr1.AccountId);
            
                if (accrt.Name == 'Distributor'){
                     system.assertEquals(l.PartnerAccountId ,usr1.AccountId);
                }
            }
            
            Id leadId = l.Id;
        bolCreateOpp = false;
        //Create a reference to the VF page
        PageReference pageRef = Page.XXCSR_LEAD_CONVERT;
        Test.setCurrentPageReference(pageRef);
    
           //Create an instance of the controller extension and call the autoRun method.
        //autoRun must be called explicitly even though it is "autoRun".
        ApexPages.StandardController sc = new ApexPages.standardController(l);
        XXCSRLeadConvertClass leadconvt = new XXCSRLeadConvertClass(sc);
        leadconvt.autoRun();
         //String nextPage = sc.save().getUrl();
        
       
       List<SelectOption> testacct = new List<SelectOption>();
       testacct = leadconvt.getlstCompanyInfo();
        system.debug(testacct);
     
        
     List<SelectOption> testcon = new List<SelectOption>();
       testcon = leadconvt.getlstContactInfo();
        system.debug(testcon);
        
         leadconvt.doNothing();
        
         leadconvt.strAccountId= '1';
         leadconvt.strcontactId= '1';
         leadconvt.convertlead();
        
        
             //Retrieve the converted Lead info and the opps and roles.
            l = [select Id, IsConverted, ConvertedAccountId, ConvertedContactId ,Status, ApprovalStatus__c,
             Company,OwnerId,firstname,lastname,city,country from Lead where Id = :leadId];
          
            
           
        //  system.assert(!l.IsConverted,'Lead Converted' );  
          test.stopTest();
         

        }
   
         

}

Thank you for your help,

Pallavi
 
Here is my VF page for lead conversion. not able to figure out what else needs in my test class to increase the coverage. PLease help.

<apex:page standardController="Lead" extensions="XXCSRLeadConvertClass"   title="Convert Lead" id="pgConvertLead">

<apex:form id="frmConvert">

    <apex:actionFunction name="afOpportunity" action="{!doNothing}" rerender="pbsConvert" immediate="true" />

    <apex:pageBlock title="Convert Lead" mode="edit">
   
        <apex:pageBlockButtons >
            <apex:commandButton id="cmdConvert" action="{!convertLead}" value="Convert" />
            <apex:commandButton id="cmdCancel" action="{!cancel}" value="Cancel" />
        </apex:pageBlockButtons>
       
        <apex:messages ></apex:messages>
       
        <apex:pageBlockSection id="pbsConvert" title="Convert Lead" columns="1">
                       
            <apex:inputField id="ifOwnerId" value="{!ldSource.OwnerId}" />
            <apex:selectList id="soAccount" value="{!strAccountId}" label="Account Name" size="1">
                <apex:selectOptions value="{!lstCompanyInfo}" />
            </apex:selectList>
            <apex:selectList id="soContact" value="{!strContactId}" label="Contact Name" size="1">
                <apex:selectOptions value="{!lstContactInfo}" />
            </apex:selectList>
                      
        </apex:pageBlockSection>
   
    </apex:pageBlock>

</apex:form>

</apex:page>

Here is extension class

public class XXCSRLeadConvertClass {
public Lead ldSource {get;set;}
public Boolean bolCreateOpp {get;set;}
public String strAccountId {get;set;}
public String strContactId {get;set;}



//////////////////////////
// Constructors / GETers
//////////////////////////
public XXCSRLeadConvertClass(ApexPages.StandardController scMain) {



ldSource = [SELECT Id, FirstName, LastName, OwnerId, Company, Street, City, State, PostalCOde, Country, Phone, Fax,Status,ApprovalStatus__c FROM Lead WHERE Id = :scMain.getId()];
bolCreateOpp = false;

    
}

public List<SelectOption> getlstCompanyInfo() {

String strCompanyWildcard = '%' + ldSource.Company + '%';
List<Account> lstAcct = [SELECT Id, Name, Owner.Name FROM Account WHERE Name LIKE :strCompanyWildcard];

List<SelectOption> lstCompanies = new List<SelectOption>();

// Add New Account if not found
lstCompanies.add(new SelectOption('1','Create New Account: ' + ldSource.Company));

// Add found Accounts to SelectList
for(Account a : lstAcct) {
lstCompanies.add(new SelectOption(a.Id, 'Attach to Existing: ' + a.Name + ' (' + a.Owner.Name + ')'));
}

return lstCompanies;      
}

    public List<SelectOption> getlstContactInfo(){
       
       string strContactFirst = '%'+ldSource.FirstName+'%';
        string strContactLast = '%'+ldSource.LastName+'%';
        List<Contact> lsContact = [select Id ,FirstName,LastName,AccountId,Owner.Name from Contact where (FirstName like : strContactFirst and LastName like :strContactLast)
                                   and AccountId = :[select Id from Account where Name like :ldSource.Company]];
       List<SelectOption> lstContact = new List<SelectOption>();
       
        // Add New Contact if not found
lstContact.add(new SelectOption('1','Create New Contact: ' + ldSource.FirstName+''+ldSource.LastName));

// Add found Accounts to SelectList
for(Contact c : lsContact) {
lstContact.add(new SelectOption(c.Id, 'Attach to Existing: ' + c.FirstName +' '+c.LastName+ ' (' + c.Owner.Name + ')'));
    }
return lstContact;         
    }
//////////////////////////
// Action Methods
//////////////////////////

public void doNothing() {  }

public PageReference convertLead() {

//check if status = qualified and Approved
if (ldSource.Status == 'Qualified' && ldSource.ApprovalStatus__c == 'Approved'){


// Create LeadConvert object
Database.LeadConvert lc = new Database.LeadConvert();

        
lc.setLeadId(ldSource.Id);
lc.setOwnerId(ldSource.OwnerId);
if(strAccountId.length() > 1) { lc.setAccountId(strAccountId); }
if(strContactId.length() > 1) { lc.setContactId(strContactId); }
lc.setDoNotCreateOpportunity(bolCreateOpp);

// Set Opportunity Name
if(bolCreateOpp == true) { lc.setOpportunityName(ldSource.Company); }

// Set Lead Converted Status
LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
lc.setConvertedStatus(convertStatus.MasterLabel);



// Convert!
Database.LeadConvertResult lcr = Database.convertLead(lc);

// Mop up Opportunity
if(bolCreateOpp == true) {
Opportunity o = new Opportunity(Id=lcr.getOpportunityId());
update o;
}
// Redirect...
PageReference prResult;
if(lcr.isSuccess()) {
prResult = new PageReference('/' + lcr.getAccountId());
prResult.setRedirect(true);
return prResult;  
} else {
return null;
}
}else{
ldSource.addError('Lead cannot be converted without Lead status Qualified and Approved !'); 
      ldSource.addError('Please Go back to Lead screen to change status'); 
    }
   
return null;}
}


Here is my test code

@IsTest(seealldata=true)
private class TestXXCSRLeadConvertClass{

        static testMethod void TestXXCSRLeadConvertClass() {
      
       test.startTest();
           Boolean bolCreateOpp;
           String strAccountId;
     String strContactId;
            Lead l = new Lead();
            l.FirstName = 'CRM Testing First';
            l.LastName = 'CRM Testing Last';
            l.Company = 'CRM Testing INCtest';
            l.description = 'Test descr';
            l.city = 'test';
            l.street = 'test';
            l.state = 'CA';
            l.country = 'United States';
            l.status = 'Qualified';
            l.email = 'test@testnetgear.com';
            l.website = 'www.testcrm.com';
            l.ApprovalStatus__c='Approved';
            l.RecordTypeId='012110000004b9Q';
             
        
            insert l;
       
      Id leadId = l.Id;
  bolCreateOpp = false;
  //Create a reference to the VF page
  PageReference pageRef = Page.XXCSR_LEAD_CONVERT;
        Test.setCurrentPageReference(pageRef);

     //Create an instance of the controller extension and call the autoRun method.
  //autoRun must be called explicitly even though it is "autoRun".
  ApexPages.StandardController sc = new ApexPages.standardController(l);
  XXCSRLeadConvertClass leadconvt = new XXCSRLeadConvertClass(sc);
   String nextPage = sc.save().getUrl();
 
      
       List<SelectOption> testacct = new List<SelectOption>();
       testacct = leadconvt.getlstCompanyInfo();
        system.debug(testacct);
    
       
  List<SelectOption> testcon = new List<SelectOption>();
       testcon = leadconvt.getlstContactInfo();
        system.debug(testcon);
 
   leadconvt.doNothing();
 
             //Retrieve the converted Lead info and the opps and roles.
   l = [select Id, IsConverted, ConvertedAccountId, ConvertedContactId ,Status, ApprovalStatus__c,
    Company,OwnerId,firstname,lastname,city,country from Lead where Id = :leadId];
         
          system.assert(!l.IsConverted,'Lead Converted' ); 
          test.stopTest();
        


        }
  
        

}

Thanks
Pallavi
Hi,

I'm not so experinced in APEX developement, I have developed a VF page and controller and to cusomtize convert button. Everythign works fine in sandbox.
When i try to move to LIVE. I get this error message.

Average test coverage across all Apex Classes and Triggers is 52%, at least 75% test coverage is required.

I see each of my test calss seperately says 100 % coverage. But overall coverage is only 52%.

I saw posting and does'nt seem to be having perfect solution.
I really appreaciate if some one can help me how i can increase test code.


Thanks
Pallavi
I have a test class which was moved to live a year ago. I run the test and i get error message

System.DmlException: Insert failed. First exception on row 0; first error: STANDARD_PRICE_NOT_DEFINED, No standard price defined for this product: []

I can't figure out why is this happening.

Hi,

 

I just downloaded excel connector  for EE version.

I can update  one cell form excel. when i select multiple rows and try updating. I get  error.

 

Am i missing somehting? did multiple selections  work for anyone?

 

Thanks

Pallavi

 

 

Hi,
PLease help.
I have a custom object and a trigger, I see its working in sandbox , with test case coverage of 100% i migrated to production. This trigger is not working.
is there anything to do special for custom triggers?
 when a field is updated , oan custom object record is created with a trigger, after record is created I want opportunity object to be updated back.

Here is the code
trigger UpdateRefExist on Customer_Ref_Design__c (after insert) {
List <Opportunity> oppupdate = new List <Opportunity>();
    for (Customer_Ref_Design__c ref : Trigger.new){
        Opportunity opp = [select Id,RefDesignExist__c from Opportunity where Id = :ref.Oppid__c]; 
        opp.RefDesignExist__c='Y';  
           oppupdate.add(opp);
        }
     try {
         update oppupdate;
         } catch (system.Dmlexception e) {
             system.debug (e);
         }
}

Thanks
Pallavi
Hi ,

I created a trigger on Lead object and some custom lookup fields to update after insert.
It works fine. I added test code and the code coverage is not covering all code.
Really appreciate of some one can help with what I missed. Here is my trigger and class.
FYI, my test code also includes convert lead whcih is extra.

***Trigger***
trigger UpdateLeadDistifields on Lead (after insert) {
    Set<ID> LeadId = new Set<Id>();
    for (Lead cLead : Trigger.New){
        
        Lead l = [select Id,OwnerId,PartnerAccountId,RecordTypeId from Lead where  Id = :cLead.Id];
        RecordType rt = [select Name FROM RecordType where Id = :l.RecordTypeId];
        
        
        if (rt.name == 'DealRegistration'){
            User u = [select Id ,AccountId from User where Id = :l.OwnerId and AccountId  != '' and ContactId != '' and IsPortalEnabled = true];
            Account a = [select Id, RecordTypeId from Account where Id = :u.AccountId ];
            RecordType accrt = [select Name FROM RecordType where Id = :a.RecordTypeId];
            l.PortalUser__c = u.Id;
        l.PortalAccount__c = u.AccountId;
        if (accrt.Name == 'Distributor'){
            l.DistiAccount__c = l.PartnerAccountId ;
            
            
        }
        
        }else {
            l.PortalUser__c = l.OwnerId;
            l.PortalAccount__c = l.PartnerAccountId;
        }
        update l;
    }
}


********test**********

@IsTest
private class TestXXCSRLeadConvertClass{
 
        static testMethod void TestXXCSRLeadConvertClass() {
       
       test.startTest();
           Boolean bolCreateOpp;
           String strAccountId;
           String strContactId;
            
            User usr = [select Id,PartnerApprover__c,AccountId from User where  Name='Tim House' and IsPortalEnabled = true];
            RecordType rt = [select Id,Name FROM RecordType where Name='Deal Registration'];
            Lead l = new Lead();
            l.FirstName = 'CRM Testing First';
            l.LastName = 'CRM Testing Last';
            l.Company = 'CRM Testing INCtest';
            l.description = 'Test descr';
            l.city = 'test';
            l.street = 'test';
            l.state = 'CA';
            l.country = 'United States';
            l.status = 'Qualified';
            l.email = 'test@testnetgear.com';
            l.website = 'www.testcrm.com';
            l.ApprovalStatus__c='Approved';
            l.RecordTypeId= rt.Id;
            l.OwnerId = usr.Id; //Timhouse
            
                
              
         
            insert l;
         //update
       
        l = [select Id,OwnerId,PartnerAccountId,RecordTypeId,DistiAccount__c,PortalUser__c ,PortalAccount__c from Lead where  Id = :l.Id];
      
           // system.debug("Owner"+l.OwnerId);
         //    system.debug("AccountId"+usr.AccountId);
            if (rt.Name == 'DealRegistration'){
                 User usr1 = [select Id ,AccountId from User where Id = :l.OwnerId and AccountId  != '' and ContactId != '' and IsPortalEnabled = true];
                Account a = [select Id, RecordTypeId from Account where Id = :usr1.AccountId ];
                RecordType accrt = [select Name FROM RecordType where Id = :a.RecordTypeId];
                // user usr1  = [select Id,AccountId from User where Id = :l.OwnerId];
                // Account a = [select Id, RecordTypeId from Account where Id = :usr1.AccountId and IsPartner = true];
                // RecordType accrt = [select Name FROM RecordType where Id = :a.RecordTypeId];
                 system.assertEquals(l.OwnerId,usr1.Id );
                system.assertEquals(l.PartnerAccountId,usr1.AccountId);
            
                if (accrt.Name == 'Distributor'){
                     system.assertEquals(l.PartnerAccountId ,usr1.AccountId);
                }
            }
            
            Id leadId = l.Id;
        bolCreateOpp = false;
        //Create a reference to the VF page
        PageReference pageRef = Page.XXCSR_LEAD_CONVERT;
        Test.setCurrentPageReference(pageRef);
    
           //Create an instance of the controller extension and call the autoRun method.
        //autoRun must be called explicitly even though it is "autoRun".
        ApexPages.StandardController sc = new ApexPages.standardController(l);
        XXCSRLeadConvertClass leadconvt = new XXCSRLeadConvertClass(sc);
        leadconvt.autoRun();
         //String nextPage = sc.save().getUrl();
        
       
       List<SelectOption> testacct = new List<SelectOption>();
       testacct = leadconvt.getlstCompanyInfo();
        system.debug(testacct);
     
        
     List<SelectOption> testcon = new List<SelectOption>();
       testcon = leadconvt.getlstContactInfo();
        system.debug(testcon);
        
         leadconvt.doNothing();
        
         leadconvt.strAccountId= '1';
         leadconvt.strcontactId= '1';
         leadconvt.convertlead();
        
        
             //Retrieve the converted Lead info and the opps and roles.
            l = [select Id, IsConverted, ConvertedAccountId, ConvertedContactId ,Status, ApprovalStatus__c,
             Company,OwnerId,firstname,lastname,city,country from Lead where Id = :leadId];
          
            
           
        //  system.assert(!l.IsConverted,'Lead Converted' );  
          test.stopTest();
         

        }
   
         

}

Thank you for your help,

Pallavi
 
Here is my VF page for lead conversion. not able to figure out what else needs in my test class to increase the coverage. PLease help.

<apex:page standardController="Lead" extensions="XXCSRLeadConvertClass"   title="Convert Lead" id="pgConvertLead">

<apex:form id="frmConvert">

    <apex:actionFunction name="afOpportunity" action="{!doNothing}" rerender="pbsConvert" immediate="true" />

    <apex:pageBlock title="Convert Lead" mode="edit">
   
        <apex:pageBlockButtons >
            <apex:commandButton id="cmdConvert" action="{!convertLead}" value="Convert" />
            <apex:commandButton id="cmdCancel" action="{!cancel}" value="Cancel" />
        </apex:pageBlockButtons>
       
        <apex:messages ></apex:messages>
       
        <apex:pageBlockSection id="pbsConvert" title="Convert Lead" columns="1">
                       
            <apex:inputField id="ifOwnerId" value="{!ldSource.OwnerId}" />
            <apex:selectList id="soAccount" value="{!strAccountId}" label="Account Name" size="1">
                <apex:selectOptions value="{!lstCompanyInfo}" />
            </apex:selectList>
            <apex:selectList id="soContact" value="{!strContactId}" label="Contact Name" size="1">
                <apex:selectOptions value="{!lstContactInfo}" />
            </apex:selectList>
                      
        </apex:pageBlockSection>
   
    </apex:pageBlock>

</apex:form>

</apex:page>

Here is extension class

public class XXCSRLeadConvertClass {
public Lead ldSource {get;set;}
public Boolean bolCreateOpp {get;set;}
public String strAccountId {get;set;}
public String strContactId {get;set;}



//////////////////////////
// Constructors / GETers
//////////////////////////
public XXCSRLeadConvertClass(ApexPages.StandardController scMain) {



ldSource = [SELECT Id, FirstName, LastName, OwnerId, Company, Street, City, State, PostalCOde, Country, Phone, Fax,Status,ApprovalStatus__c FROM Lead WHERE Id = :scMain.getId()];
bolCreateOpp = false;

    
}

public List<SelectOption> getlstCompanyInfo() {

String strCompanyWildcard = '%' + ldSource.Company + '%';
List<Account> lstAcct = [SELECT Id, Name, Owner.Name FROM Account WHERE Name LIKE :strCompanyWildcard];

List<SelectOption> lstCompanies = new List<SelectOption>();

// Add New Account if not found
lstCompanies.add(new SelectOption('1','Create New Account: ' + ldSource.Company));

// Add found Accounts to SelectList
for(Account a : lstAcct) {
lstCompanies.add(new SelectOption(a.Id, 'Attach to Existing: ' + a.Name + ' (' + a.Owner.Name + ')'));
}

return lstCompanies;      
}

    public List<SelectOption> getlstContactInfo(){
       
       string strContactFirst = '%'+ldSource.FirstName+'%';
        string strContactLast = '%'+ldSource.LastName+'%';
        List<Contact> lsContact = [select Id ,FirstName,LastName,AccountId,Owner.Name from Contact where (FirstName like : strContactFirst and LastName like :strContactLast)
                                   and AccountId = :[select Id from Account where Name like :ldSource.Company]];
       List<SelectOption> lstContact = new List<SelectOption>();
       
        // Add New Contact if not found
lstContact.add(new SelectOption('1','Create New Contact: ' + ldSource.FirstName+''+ldSource.LastName));

// Add found Accounts to SelectList
for(Contact c : lsContact) {
lstContact.add(new SelectOption(c.Id, 'Attach to Existing: ' + c.FirstName +' '+c.LastName+ ' (' + c.Owner.Name + ')'));
    }
return lstContact;         
    }
//////////////////////////
// Action Methods
//////////////////////////

public void doNothing() {  }

public PageReference convertLead() {

//check if status = qualified and Approved
if (ldSource.Status == 'Qualified' && ldSource.ApprovalStatus__c == 'Approved'){


// Create LeadConvert object
Database.LeadConvert lc = new Database.LeadConvert();

        
lc.setLeadId(ldSource.Id);
lc.setOwnerId(ldSource.OwnerId);
if(strAccountId.length() > 1) { lc.setAccountId(strAccountId); }
if(strContactId.length() > 1) { lc.setContactId(strContactId); }
lc.setDoNotCreateOpportunity(bolCreateOpp);

// Set Opportunity Name
if(bolCreateOpp == true) { lc.setOpportunityName(ldSource.Company); }

// Set Lead Converted Status
LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
lc.setConvertedStatus(convertStatus.MasterLabel);



// Convert!
Database.LeadConvertResult lcr = Database.convertLead(lc);

// Mop up Opportunity
if(bolCreateOpp == true) {
Opportunity o = new Opportunity(Id=lcr.getOpportunityId());
update o;
}
// Redirect...
PageReference prResult;
if(lcr.isSuccess()) {
prResult = new PageReference('/' + lcr.getAccountId());
prResult.setRedirect(true);
return prResult;  
} else {
return null;
}
}else{
ldSource.addError('Lead cannot be converted without Lead status Qualified and Approved !'); 
      ldSource.addError('Please Go back to Lead screen to change status'); 
    }
   
return null;}
}


Here is my test code

@IsTest(seealldata=true)
private class TestXXCSRLeadConvertClass{

        static testMethod void TestXXCSRLeadConvertClass() {
      
       test.startTest();
           Boolean bolCreateOpp;
           String strAccountId;
     String strContactId;
            Lead l = new Lead();
            l.FirstName = 'CRM Testing First';
            l.LastName = 'CRM Testing Last';
            l.Company = 'CRM Testing INCtest';
            l.description = 'Test descr';
            l.city = 'test';
            l.street = 'test';
            l.state = 'CA';
            l.country = 'United States';
            l.status = 'Qualified';
            l.email = 'test@testnetgear.com';
            l.website = 'www.testcrm.com';
            l.ApprovalStatus__c='Approved';
            l.RecordTypeId='012110000004b9Q';
             
        
            insert l;
       
      Id leadId = l.Id;
  bolCreateOpp = false;
  //Create a reference to the VF page
  PageReference pageRef = Page.XXCSR_LEAD_CONVERT;
        Test.setCurrentPageReference(pageRef);

     //Create an instance of the controller extension and call the autoRun method.
  //autoRun must be called explicitly even though it is "autoRun".
  ApexPages.StandardController sc = new ApexPages.standardController(l);
  XXCSRLeadConvertClass leadconvt = new XXCSRLeadConvertClass(sc);
   String nextPage = sc.save().getUrl();
 
      
       List<SelectOption> testacct = new List<SelectOption>();
       testacct = leadconvt.getlstCompanyInfo();
        system.debug(testacct);
    
       
  List<SelectOption> testcon = new List<SelectOption>();
       testcon = leadconvt.getlstContactInfo();
        system.debug(testcon);
 
   leadconvt.doNothing();
 
             //Retrieve the converted Lead info and the opps and roles.
   l = [select Id, IsConverted, ConvertedAccountId, ConvertedContactId ,Status, ApprovalStatus__c,
    Company,OwnerId,firstname,lastname,city,country from Lead where Id = :leadId];
         
          system.assert(!l.IsConverted,'Lead Converted' ); 
          test.stopTest();
        


        }
  
        

}

Thanks
Pallavi
Hi,

I'm not so experinced in APEX developement, I have developed a VF page and controller and to cusomtize convert button. Everythign works fine in sandbox.
When i try to move to LIVE. I get this error message.

Average test coverage across all Apex Classes and Triggers is 52%, at least 75% test coverage is required.

I see each of my test calss seperately says 100 % coverage. But overall coverage is only 52%.

I saw posting and does'nt seem to be having perfect solution.
I really appreaciate if some one can help me how i can increase test code.


Thanks
Pallavi

Is it possible to hide the 'Task' section altogether on LeadConvert.jsp page? I guess building a VisualForce page is the answer, but I would really appreciate if somebody could point me to sample code that does something similar. I want to retain most of the functionality on that page and just customize the layout a bit.

 

Thanks much! 

  • January 10, 2012
  • Like
  • 0