• Sakthi Ganesh R
  • NEWBIE
  • 10 Points
  • Member since 2014
  • Salesforce Developer
  • Tandture systems Pvt Ltd, Chennai

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

Hello team,

I have a look-up field that i'm displaying on visualforce page. But user should not see their recent items when they type something in inputfield box. Is anyone know how can we restrict it?

I'm Trying to get the code coverage for the following trigger.
Trigger AutoConverter on Lead (after insert,after update,before update) {
 if(trigger.isafter)
{
          LeadStatus convertStatus = [
          select MasterLabel
          from LeadStatus
          where IsConverted = true
          limit 1
          ];
         List<Database.LeadConvert> leadConverts = new List<Database.LeadConvert>();

          for (Lead lead: Trigger.new) {
          if (!lead.isConverted && lead.Is_the_lead_from_CSA_Sign_Up_page__c == 'Yes') {
               Database.LeadConvert lc = new Database.LeadConvert();
               String oppName = lead.Name;
               
               lc.setLeadId(lead.Id);
               //lc.setOpportunityName(oppName);
               lc.setDoNotCreateOpportunity(true);
               lc.setConvertedStatus(convertStatus.MasterLabel);
               
               leadConverts.add(lc);
          }
        }
       if (!leadConverts.isEmpty()) {
          List<Database.LeadConvertResult> lcr = Database.convertLead(leadConverts);
          if(trigger.isupdate&&lcr[0].success==true){
                  ///
       }
       }
}
Here's the test class:
@isTest
private class Testleadconversiontrigger
{
    private static id leadid;
    //{
      static{
          
          Lead L1 = new Lead();
          L1.firstname = 'f1';
          L1.lastname = 'l1';
          L1.title = 'manager';
          L1.leadsource = 'word of mouth';
          L1.company = 'MOD';
          L1.Is_the_lead_from_CSA_Sign_Up_page__c='Yes';
          Insert L1;
          
          leadid=L1.id;
      }
      static testMethod void Test_LeadConvert(){
          Database.LeadConvert lc = new database.LeadConvert();
          lc.setLeadId(leadid);
          lc.setDoNotCreateOpportunity(true);
          test.StartTest();
          LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus 
          where IsConverted=true limit 1];         
          //lc.setOwnerId(testUser1.id);
          lc.setConvertedStatus(convertStatus.MasterLabel);
          Database.LeadConvertResult lcr = Database.convertLead(lc);
          System.assert(lcr.isSuccess());
          test.StopTest();
     }
    //}
}
But i'm getting the follwoing error on line no 28 in test class,

Error MessageSystem.DmlException: ConvertLead failed. First exception on row 0; first error: ENTITY_IS_DELETED, entity is deleted: []
Stack TraceClass.Testleadconversiontrigger.Test_LeadConvert: line 28, column 1

Can anyone help me on this?

Thanks in Advance.
 
I have written a trigger, like

 Billing_MVA__c Bill = trigger.new[0];
     string sdate = Bill.Billing_cycle_from__c;
     string edate = bill.Billing_cycle_to__c;
        
    string[] stdate = sdate.split('/');
        string[] endate = edate.split('/');

            string sday = stdate[2];
            string smonth = stdate[1];
            string syear = stdate[0];
            date startdate = date.parse(smonth+'/'+sday+'/'+syear);
            system.debug('*************'+startdate);

I got debug log output like 
USER_DEBUG|[21]|DEBUG|*************2014-01-01 00:00:00

But i don't want to like this, I want only date as mm/day/year format. can any one help me?

Thanks in advance
 
I have written a trigger and i got this error Incompatible element type SOBJECT:Billing_MVA__c for collection of SOBJECT:Opportunity.

My trigger:

trigger totalBillinghrs on Billing_MVA__c (before insert)
{
    //date startdate;
    //date enddate;
    list<opportunity> opp = new list<opportunity>();
    Billing_MVA__c Bill = trigger.new[0];
    integer counter = [select count() from opportunity where BCRNo__c != null];
    if(counter >0)
    {
        string sdate = Bill.Billing_cycle_from__c;
        string edate = bill.Billing_cycle_from__c;
        string[] stdate = sdate.split('/');
        string[] endate = edate.split('/');
       // if(stdate !=null)
        
            string sday = stdate[2];
            string smonth = stdate[0];
            string syear = stdate[1];
            date startdate = date.parse(smonth+'/'+sday+'/'+syear);
            system.debug('*************'+startdate);
       // if(endate != null)
        
            string eday = endate[2];
            string emonth = endate[0];
            string eyear = endate[1];
            date enddate = date.parse(emonth+'/'+eday+'/'+eyear);
            system.debug('*************'+enddate);
        
        list<opportunity> opplist = [SELECT id,Billing_cycle__c,totalhrs__c FROM opportunity WHERE (Billing_cycle__c>:startdate) and (Billing_cycle__c<:enddate)];
         system.debug('*************'+opplist);
        for(opportunity oppnew : opplist)
        {
            Bill.Total_MVA_billing_hrs__c = oppnew.totalhrs__c;
            opp.add(Bill);
        }
        upsert opp;
        
    }
}

can any one help me?

Thanks in advance

Sakthi
Hi all,

My VF Page,

<apex:page controller="AccountSearchController" sidebar="false">
    <apex:form>
        <apex:pageBlock title="Find Accounts" mode="edit">
            <table width="100%" border="0">
              <tr>  
                <td width="200" valign="top">
                    <apex:pageBlock title="Parameters" mode="edit" id="pb2">
                        <table cellpadding="2" cellspacing="2">
                           <!-- <tr>
                                <td style="font-weight:bold;">Owner of Account<br/>
                                <apex:inputField value="{!Accounts.owner.id}" label="Owner of Account" id="owner" onkeyup="doSearch();"/>
                                </td>
                              </tr>-->
                            <tr>
                                <td style="font-weight:bold;">Type of Account<br/>
                                <select id="type" onchange="doSearch();">
                                    <option value=""></option>
                                    <apex:repeat value="{!Type1}" var="type1">
                                          <option value="{!type1}">{!type1}</option>
                                    </apex:repeat>
                                  </select>
                                </td>
                              </tr>
                            <tr>
                                <td style="font-weight:bold;">Upsell Opportunity<br/>
                                <select id="Opportunity" onchange="doSearch();">
                                    <option value=""></option>
                                    <apex:repeat value="{!upsell}" var="upsell">
                                          <option value="{!upsell}">{!upsell}</option>
                                    </apex:repeat>
                                  </select>
                                </td>
                              </tr>
                            <tr>
                                <td style="font-weight:bold;">Customer Priority<br/>
                                <select id="Priority" onchange="doSearch();">
                                    <option value=""></option>
                                    <apex:repeat value="{!cusprity}" var="cusprity">
                                          <option value="{!cusprity}">{!cusprity}</option>
                                    </apex:repeat>
                                  </select>
                                </td>
                              </tr>
                        </table>
                    </apex:pageBlock>
                </td>
                <td valign="top">
                    <apex:pageBlock mode="edit" id="results">
                    <apex:pageBlockTable value="{!Accounts}" var="acc">
                        <apex:column >
                            <apex:facet name="header">
                                <apex:commandLink value="Acc.Name" action="{!toggleSort}" rerender="results,debug">
                                    <apex:param name="sortField" value="acc.Name" assignTo="{!sortField}"/>
                                </apex:commandLink>
                            </apex:facet>
                            <apex:outputField value="{!Account.Name}"/>
                        </apex:column>
                        <apex:column >
                            <apex:facet name="header">
                                <apex:commandLink value="Acc.Number" action="{!toggleSort}" rerender="results,debug">
                                    <apex:param name="sortField" value="acc.Number" assignTo="{!sortField}"/>
                                </apex:commandLink>
                            </apex:facet>
                            <apex:outputField value="{!Account.AccountNumber}"/>
                        </apex:column>
                        <apex:column >
                            <apex:facet name="header">
                                <apex:commandLink value="Annual Revenue" action="{!toggleSort}" rerender="results,debug">
                                    <apex:param name="sortField" value="annualrevenue" assignTo="{!sortField}"/>
                                </apex:commandLink>
                            </apex:facet>
                            <apex:outputField value="{!Account.AnnualRevenue}"/>
                        </apex:column>
                        <apex:column >
                            <apex:facet name="header">
                                <apex:commandLink value="Address" action="{!toggleSort}" rerender="results,debug">
                                    <apex:param name="sortField" value="address" assignTo="{!sortField}"/>
                                </apex:commandLink>
                            </apex:facet>
                            <apex:outputField value="{!Account.Address}"/>
                        </apex:column>
                        <apex:column >
                            <apex:facet name="header">
                                <apex:commandLink value="Opportunities" action="{!toggleSort}" rerender="results,debug">
                                    <apex:param name="sortField" value="upsellopportunity" assignTo="{!sortField}"/>
                                </apex:commandLink>
                            </apex:facet>
                            <apex:outputField value="{!Account.Upsellopportunity__c}"/>
                        </apex:column>
                    </apex:pageBlockTable>
                    </apex:pageBlock>
                </td>
                </tr>
            </table>
            <apex:pageBlock title="Debug - SOQL" id="debug">
                  <apex:outputText value="{!debugSoql}" />           
              </apex:pageBlock> 
        </apex:pageBlock>
    </apex:form>
</apex:page>
****************************************************************************
My Apex class,

public with sharing class AccountSearchController {
    private string soql{get;set;}
    public list<Account> Accounts{get;set;}
    
    public string[] getType1()
    {
        return new string[]{'Prospect','Customer - Direct','Customer - Channel','Channel Partner / Reseller','Installation Partner','Technology Partner','Other'};
    }
    public string[] getupsell()
    {
        return new string[]{'Maybe','No','Yes'};
    }
    public string[] getcusprity()
    {
        return new string[]{'High','Medium','Low'};
    }
    public string sortDir
    {
        get
        {
            if(sortDir == null){sortDir = 'asc';} return sortDir;
        }
        set;
    }
    public string sortField
    {
        get
        {
            if(sortField == null){sortField = 'acc.Name';}return sortField;    
        }
        set;
    }
    public string debugSoql
    {
        get
        {
            return soql+ 'order by' + sortField+' '+sortDir+' '+'limit 20';
        }
    }
    public AccountSearchController()
    {
        soql = 'select Name,AccountNumber,Type,ownerid,AnnualRevenue,Address,UpsellOpportunity__c,Customerpriority__c from Account';
        runquery();
    }
    
    public void toggleSort()
    {
        sortDir = sortDir.equals('asc')? 'desc': 'asc';
        runquery();
    }
    public void runquery()
    {
        try
        {
            //accounts=new list<Account>();
            accounts = Database.query(soql+' order by '+sortField+' '+sortDir+' limit 20');    
        }
        catch(Exception e)
        {
             ApexPages.addmessage(new Apexpages.Message(Apexpages.Severity.ERROR,'oops!'));           
        }
    }
    
    public pagereference runSearch()
    {
        string owner = ApexPages.currentPage().getParameters().get('owner');
        string type = ApexPages.currentPage().getParameters().get('type');
        string Opporutnity = ApexPages.currentPage().getParameters().get('Opportunity');
        string priority = ApexPages.currentPage().getparameters().get('priority');
        
        soql = 'select Name,AccountNumber,Type,AnnualRevenue,Address,UpsellOpportunity__c,customerpriortiy__c from Account';
        
        if(!owner.equals(' '))
            soql += ' and owner LIKE\' '+string.escapeSingleQuotes(owner)+'%\'';
        if(!type.equals(' '))
            soql += ' and type LIKE\' '+string.escapeSingleQuotes(type)+'%\'';
        //if(!Opportunity.equals(' '))
          // soql += ' and UpsellOpportunity__c includes (\' '+Opportunity+'\')';
        if(!priority.equals(' '))
            soql += ' and priority LIKE\' '+string.escapeSingleQuotes(priority)+'%\'';
        runquery();
        return null;
    }
}

I am getting Unknown property 'AccountSearchController.Account' Error when saving VF page. Any one can help me?

Thanks,