• aress
  • NEWBIE
  • 60 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 34
    Questions
  • 4
    Replies
I want to show multiple dashboard on a single page.
Can anyone suggest how to enabe that as on Home page only one dashboard is displayed at a time.
  • September 05, 2018
  • Like
  • 0
I have attached the requirement. Can anyone suggest how should i Proceed.
What all custom object and custom fields i require?

The company provides bus/coach transport services. They are looking for a solution that will allow parents to book bus tickets for their children so that they can catch the bus to school.
 Vehicles object to store information about coaches/buses including capacity
 Routes object to store information about a route.
 Vehicle Routes junction object to allocate one or more vehicles to a particular route
 Stops object to store information about the stops along a route including geolocation. Certain stops may be denoted as ‘schools’
 Route Stops junction object to connect stops to routes
 Customer Route junction object to book a person account to a route. Booking may be confirmed or waitlist and have a number of tickets (numeric field) Availability of a Route is based on capacity (from sum of vehicle capacity) less number of customer route tickets for that route.

Visualforce web-page that progresses through a booking process…
 Ask for house number and postcode of visitor, select a school from a list of all school stops
 Display a list of Bus Routes that include the selected school stop, ordered by nearest to postcode based on google distance API (walking)
 User to select a route and select the number of tickets required. Upon selection of route and number of tickets, availability to be displayed.
 If there is availability, be taken to a booking page where the account information can be captured. Create a customer route record with status Confirmed.
 If there is no availability, be taken to a waitlist page and enter their information to create an account and customer route record with status Waitlist
  • September 04, 2018
  • Like
  • 0
Hello Experts,
I have to use batch class to send email to primary_contact about the sum of all opportunity amount assosciated with that contact.
I have written batch class that is sending mail to given email id.
How to send mail to email id of all primary contact assosciated with that opportunity.
Any help will be appreciated.


----------------------------------------------------------------------------------------------------------------------------------------------------------------------
global class OpportunityAggregate implements Database.Batchable<SObject>, Database.Stateful {
    Map<Contact, Map<String, Double>> mapConOpps = new Map<Contact, Map<String, Double>>();
    global Database.QueryLocator start(Database.BatchableContext BC) {
        return Database.getQueryLocator([
            SELECT 
                Id, 
                (SELECT Id, Name FROM Contacts WHERE Primary__c=true),
                (SELECT Id, Name, Amount FROM Opportunities WHERE StageName='Closed Won')
            FROM
                Account
            WHERE
                Id
            IN
                (SELECT AccountId FROM Contact WHERE Primary__c=true)]);
    }
    global void execute(Database.BatchableContext BC, List<Account> scope) {
        for(Account acc : scope) {
            Map<String, Double> mapOppAmo = new Map<String, Double>();
            for(Opportunity objOpp : acc.Opportunities) {
                mapOppAmo.put(objOpp.Name, objOpp.Amount);
            }
            mapConOpps.put(acc.Contacts, mapOppAmo);
        }
    }
    global void finish(Database.BatchableContext BC) {
        Map<Contact, Double> mapCon_Amount = new Map<Contact, Double>();
        List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        List<String> sendTo = new List<String>();
        sendTo.add('ayish@gmail.com');
        mail.setToAddresses(sendTo);
        mail.setReplyTo('hello@world.com');
        mail.setSenderDisplayName('Apex batches');
        mail.setSubject('URGENT BUSINESS PROPOSAL');
        String body = '';
        for(Contact con : mapConOpps.keySet()) {
            Double sumAmount = 0;
            body+='Contact : ' + con.Name + '<br>------------------------------------<br>';
            for(String opp : mapConOpps.get(con).keySet()) {
                body+='Opportunity : ' + opp + ' and amount = ' + mapConOpps.get(con).get(opp) +
                                                                                            '<br>';
                sumAmount+=mapConOpps.get(con).get(opp);
            }
            body+='The aggregate opportunity amount = ' + sumAmount + '<br><br>';
        }
        mail.setHtmlBody(body);
        mails.add(mail);
        Messaging.sendEmail(mails);
    }
}
  • September 04, 2018
  • Like
  • 0
I need to prepare ER diagram for order management that consist of standard object like opportunity,product, order etc. what should i use?
  • September 03, 2018
  • Like
  • 0
I need a custom button on opportunity detail page that will open the report assosciated with opportunity. what should i do? Can anyone help?
  • September 03, 2018
  • Like
  • 0
I have a requirement that on order creation i want to send detail mail to the corresponding opportunity that created the order.
How to achieve that?
  • September 02, 2018
  • Like
  • 0
I want to insert 2000 record using dataloader,In the CSV file there is a date field whose format is dd/mm/yyyy
I want to insert record in an org whose locale is Los Angeles, USA. date format (yyyy-mm-ddThh:mm:ss.000Z)
How can i convert the date so that record are inserted succesfully
  • August 27, 2018
  • Like
  • 0
Can anyone explain the scenario and what all object to consider to implement.?

The idea is to develop an Order Management app that will help create, track and manage Purchase Orders created by Customers in conjunction to purchasing Product(s). The idea is to perform end to end tracking of the various activities
  • August 24, 2018
  • Like
  • 0
Need TEST CLASS for following batch scenario
USE CASE:
​A. Collection of Closed Won Opportunities 1. The Primary contact associated with an account needs to know which all are the closed won opportunities for his account per day. 2. Create a process which will run every day in the midnight & collect all the Closed won opportunities of that account in a day & send an email to Primary Contact. 3. The email body should contain the Opportunity Name & it's respective amount with the aggregated amount in the end.




---------------------------------------------------------BATCH CLASS----------------------------

global class ContactWithClosedWonOpportunities
implements Database.Batchable<sObject>, Database.Stateful {
/**
This Map will store the contact email IDs and respective List of Opportunites.
*/
Map<String,List<Opportunity>> contactOpprtunitiesMap =
new Map<String,List<Opportunity>>();
/**
This method will Query all Contacts associate with Account having Closed Won Opportunities.
@return Database.QueryLocator
*/
global Database.QueryLocator start(Database.BatchableContext BC) {
return Database.getQueryLocator(
'SELECT ' +
'Name, ' +
'( SELECT Email FROM Contacts WHERE Preferred_Contact__c = TRUE LIMIT 1 ), ' +
'( SELECT Name, Amount FROM Opportunities WHERE StageName LIKE \'Closed Won\') ' +
'FROM ' +
'Account ' +
'WHERE ' +
'id ' +
'IN ' +
'(SELECT AccountId FROM Contact WHERE Preferred_Contact__c = TRUE)'
);
}
/**
This method will add the values in contactOpportunitesMap.
@return Nothing.
*/
global void execute(Database.BatchableContext BC, List<sObject> scope) {
List<Account> accountList = (List<Account>) scope;
System.debug(scope + '------------------------- ');
for(Account accountRecord : accountList) {
if(accountRecord.Contacts[0].email != null) {
contactOpprtunitiesMap.put(
accountRecord.Contacts[0].email,
accountRecord.Opportunities
);
}
}
}
/**
This method will send to each primary contact with Opportunity name and Amount.
@return Nothing.
*/
global void finish(Database.BatchableContext BC) {
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
for( String mailId : contactOpprtunitiesMap.keySet() ) {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
List<String> sendTo = new List<String>();
sendTo.add(mailId);
mail.setToAddresses(sendTo);
mail.setReplyTo('ayisha.sr@gmail.com');
mail.setSubject('All Closed Won Opportunities');
String body = '<html><body>Dear Sir/Mam, <br/><br/>';
body += 'All Closed Won Opportunities are - <br/>';
Decimal total = 0;
for( Opportunity opportunityRecord : contactOpprtunitiesMap.get(mailId) ) {
body += '&nbsp;&nbsp;&nbsp;&nbsp;' + opportunityRecord.Name + ': ' +
opportunityRecord.Amount + '<br/>';
total += opportunityRecord.Amount;
}
body += '<br/>&nbsp;&nbsp;&nbsp;&nbsp; <b>Total: ' + total + '</b></body></html>';
mail.setHtmlBody(body);
System.debug(body);
mails.add(mail);
}
Messaging.sendEmail(mails);
}
}

------------------------------------------------------------------SCHEDULER-------------------------------------------
global class ScheduleClosedWonOpportunities implements Schedulable {
/**
This method will execute RemoveDuplicateLeads Apex batch.
@return Nothing.
*/
global void execute(SchedulableContext sc) {
ContactWithClosedWonOpportunities batchObject = new ContactWithClosedWonOpportunities();
Database.executeBatch(batchObject);
}
}
  • August 24, 2018
  • Like
  • 0
Need Test class for following Rest Service class to insert update delete Lead record.
Can anyone help? please provide positive negative bulk test scenarios.






global class LeadManipulationSOAPService {

    /**
        This Wrapper class is created for returning the Response in this format.
     */
    global class ManipulationResponse {
        webservice Boolean isSuccess;
        webservice String lead;
        webservice String status;
    }


  /**
        This Method creates Lead using SOAP Webservice.
        @return ManipulationResponse - Response for external system.
     */
  webservice static ManipulationResponse createLead(
    String firstName, 
        String lastName, 
        String company,
        String email, 
        String phone
  ){
    Lead leadRecord = new Lead();
        ManipulationResponse returnResponse = new ManipulationResponse();
        returnResponse.isSuccess = false;
        returnResponse.lead = '';
            
        if( lastName == null || lastName.equals('') ) {
            returnResponse.status = 'Lead : Last Name is missing.';
            return returnResponse;
        } else if( company == null || company.equals('') ) {
            returnResponse.status = 'Lead : Company is missing.';
            return returnResponse;
        }

        leadRecord.FirstName = firstName;
        leadRecord.LastName = lastName;
        leadRecord.Email = email;
        leadRecord.Phone = phone;
        leadRecord.Company = company;

        try {
            insert leadRecord;
        } catch (DMLException ex) {
            returnResponse.status = 'Lead: Insertion Exception';
            return returnResponse;
        }

        returnResponse.isSuccess = true;
        returnResponse.lead = leadRecord.id;
        returnResponse.status = 'Success';

        return returnResponse;
  }


  /**
        This Method updates Lead using SOAP Webservice.
        @return ManipulationResponse - Response for external system.
     */
    webservice static ManipulationResponse updateLead(
        String firstName,
        String lastName,
        String newEmail,
        String newPhone
    ) {
        ManipulationResponse returnResponse = new ManipulationResponse();
        returnResponse.isSuccess = false;
        returnResponse.lead = '';
        List<Lead> leadList;
       
        leadList = [
            SELECT
                id,
                Email,
                Phone
            FROM
                Lead
            WHERE
                FirstName = :firstName 
            AND
                LastName = :lastName
        ];
        

    if(leadList.size() == 0) {
            returnResponse.status = 'Lead Update : No Lead found for Input Parameters.';
            return returnResponse;
        }

        for( Lead leadRecord : leadList ) {
            leadRecord.Email = newEmail;
            leadRecord.Phone = newPhone;
        }

        try {
            update leadList;
        } catch(DMLException ex) {
            returnResponse.status = 'Lead Updation : Failed';
            return returnResponse;
        }

        returnResponse.isSuccess = true;
        returnResponse.lead = leadList[0].id;
        returnResponse.status = 'Success';
        return returnResponse;
    }




  /**
        This Method deletes Lead using SOAP Webservice.
        @return ManipulationResponse - Response for external system.
     */
    webservice static ManipulationResponse deleteLead(
    String firstName,
        String lastName,
        String email,
        String phone
  ) {
        List<Lead> leadList;
        ManipulationResponse returnResponse = new ManipulationResponse();
        returnResponse.isSuccess = false;
        returnResponse.lead = '';

        leadList = [
            SELECT
                id
            FROM
                Lead
            WHERE
                FirstName = :firstName 
            AND
                LastName = :lastName
            AND 
                Email = :email
            AND
                Phone = :phone
        ];
        
        
        if(leadList.size() == 0) {
            returnResponse.status = 'Lead Deletion : No Lead found for Input Parameters.';
            return returnResponse;
        }

        try {
            delete leadList;
        } catch(DMLException ex) {
            returnResponse.status = 'Lead Deletion : Failed';
            return returnResponse;
        }

        returnResponse.isSuccess = true;
        returnResponse.lead = firstName + ' ' + lastName ;
        returnResponse.status = 'Success';
        return returnResponse;
    }

}
  • August 21, 2018
  • Like
  • 0
Need Test class for following Rest Service class to insert update delete Lead record.
Can anyone help? please provide positive negative bulk test scenarios.
@RestResource(urlMapping='/Lead')
global class LeadManipulationService {
    
    global class Result {
        public Boolean isSuccess;
        public String lead;
        public String status;
    }
    
  @HttpPost
    global static Result createLead(String firstName, String lastName, String email, String phone, String company) {
        Result res= new Result();
        res.isSuccess = false;
        res.status = 'Error';
        
        Lead l = new Lead();
        l.FirstName = firstName;
        l.LastName = lastName;
        l.Email = email;
        l.Phone = phone;
        l.Company = company;
        
        
        try {
            insert l;
        }catch(DMLException e) {
            return res;
        }
        
     res.isSuccess = true;
        res.status = 'Success';
        res.lead = l.Id;
        return res;   
        
    }
    
    
    @HttpPut
    global static Result updateLead(String firstName, String lastName, String email, String phone) {
        Result res= new Result();
        res.isSuccess = false;
        res.status = 'Error';
        
        List<Lead> l = [
            SELECT
              FirstName,
              LastName,
              Email,
              Phone
            FROM
              Lead
            WHERE
        FirstName LIKE :firstName
            AND
              LastName LIKE :lastName
            LIMIT 1
        ];
        l[0].FirstName = firstName;
        l[0].LastName = lastName;
        l[0].Email = email;
        l[0].Phone = phone;
        
        
        try {
            update l;
        }catch(DMLException e) {
            return res;
        }
        
     res.isSuccess = true;
        res.status = 'Success';
        res.lead = l[0].Id;
        return res;   
        
    }
    
    
    
    @HttpDelete
   global static Result deleteLead() {
        Result res= new Result();
        res.isSuccess = false;
        res.status = 'Error';
        
        String firstName = RestContext.request.params.get('firstName');
        String lastName = RestContext.request.params.get('lastName');
        String email = RestContext.request.params.get('email');
        String phone = RestContext.request.params.get('phone');
        

        List<Lead> leadList = [
            SELECT
                id
            FROM
                Lead
            WHERE
                FirstName = :firstName 
            AND
                LastName = :lastName
            AND 
                Email = :email
            AND
                Phone = :phone
        ];
        
        try {
            delete leadList;
        }catch(DMLException e) {
            return res;
        }
        
     res.isSuccess = true;
        res.status = 'Success';
        res.lead = leadList[0].Id;
        return res;   
        
    }
 
    
}
  • August 21, 2018
  • Like
  • 0
Can anyone provide Test class for following use Case.
Consider all positive negative and bulk test case

Use case ::
Collection of Closed Won Opportunities
1. The Primary contact associated with an account needs to know which all are the closed won opportunities for his account per day.
2. Create a process which will run every day in the midnight & collect all the Closed won opportunities of that account in a day & send an email to Primary Contact.
3. The email body should contain the Opportunity Name & it's respective amount with the aggregated amount in the end.

-----------------------------------------------------------------------Batch Class-------------------------------------------------------------
global class ContactWithClosedWonOpportunities
implements Database.Batchable<sObject>, Database.Stateful {
/**
This Map will store the contact email IDs and respective List of Opportunites.
*/
Map<String,List<Opportunity>> contactOpprtunitiesMap =
new Map<String,List<Opportunity>>();
/**
This method will Query all Contacts associate with Account having Closed Won Opportunities.
@return Database.QueryLocator
*/
global Database.QueryLocator start(Database.BatchableContext BC) {
return Database.getQueryLocator(
'SELECT ' +
'Name, ' +
'( SELECT Email FROM Contacts WHERE Preferred_Contact__c = TRUE LIMIT 1 ), ' +
'( SELECT Name, Amount FROM Opportunities WHERE StageName LIKE \'Closed Won\') ' +
'FROM ' +
'Account ' +
'WHERE ' +
'id ' +
'IN ' +
'(SELECT AccountId FROM Contact WHERE Preferred_Contact__c = TRUE)'
);
}
/**
This method will add the values in contactOpportunitesMap.
@return Nothing.
*/
global void execute(Database.BatchableContext BC, List<sObject> scope) {
List<Account> accountList = (List<Account>) scope;
//System.debug(scope + '------------------------- ');
for(Account accountRecord : accountList) {
if(accountRecord.Contacts[0].email != null) {
contactOpprtunitiesMap.put(
accountRecord.Contacts[0].email,
accountRecord.Opportunities
);
}
}
}
/**
This method will send to each primary contact with Opportunity name and Amount.
@return Nothing.
*/
global void finish(Database.BatchableContext BC) {
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
for( String mailId : contactOpprtunitiesMap.keySet() ) {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
List<String> sendTo = new List<String>();
sendTo.add(mailId);
mail.setToAddresses(sendTo);
mail.setReplyTo('ayisa@gmail.com');
mail.setSubject('All Closed Won Opportunities');
String body = '<html><body>Dear Sir/Mam, <br/><br/>';
body += 'All Closed Won Opportunities are - <br/>';
Decimal total = 0;
for( Opportunity opportunityRecord : contactOpprtunitiesMap.get(mailId) ) {
body += '&nbsp;&nbsp;&nbsp;&nbsp;' + opportunityRecord.Name + ': ' +
opportunityRecord.Amount + '<br/>';
total += opportunityRecord.Amount;
}
body += '<br/>&nbsp;&nbsp;&nbsp;&nbsp; <b>Total: ' + total + '</b></body></html>';
mail.setHtmlBody(body);
System.debug(body);
mails.add(mail);
}
Messaging.sendEmail(mails);
}
}
  • August 20, 2018
  • Like
  • 0
Can anyone provide Test class for following scenario.Consider all positive negative Bulk testing for the given batch class.

Use Case ::
Removal of duplicate Leads
1. During the Campaigning, It might happen that representative creates duplicate leads in an org.
2. So admin want to build a process which will run every 3 hours/day & remove the duplicate leads from the org.
3. The criteria to find the duplicate records should be configurable. Ex. If there are two leads in a system with same Email address then keep the first lead entry & remove all the other leads. So the field like Email, Name which will be deciding the uniqueness should be configurable.


--------------------------------------------------BATCH class----------------------------------------------
global class RemoveDuplicateLeads implements Database.Batchable<sObject>, Database.Stateful {
/**
Map will Keep count of Lead which are having same field
*/
Map<String,Integer> countMap = new Map<String,Integer>();
/**
Constructor to initialize the countMap. Which will be useful for every batch operation.
*/
global RemoveDuplicateLeads() {
Database.QueryLocatorIterator iterator =
Database.getQueryLocator('select ' + System.Label.Lead_Field + ' from Lead').iterator();
while (iterator.hasNext())
{
Lead leadRecord = (Lead) iterator.next();
if(leadRecord.get(System.Label.Lead_Field) != null) {
countMap.put((String)leadRecord.get(System.Label.Lead_Field), 0);
}
}
}

/**
This method will start the batch execution.
@return Database.QueryLocator - This will contain all Leads.
*/
global Database.QueryLocator start(Database.BatchableContext BC) {
return Database.getQueryLocator('select ' + System.Label.Lead_Field + ' from lead');
}

/**
This method will execute for every batch and deletes the duplicate leads.
@return Nothing.
*/
global void execute(Database.BatchableContext BC, List<sObject> scope) {
List<Lead> leadList = new List<Lead>();
for(SObject lead : scope) {
if(lead.get(System.Label.Lead_Field) != null) {
if(countMap.get((String)lead.get(System.Label.Lead_Field)) >= 1 ) {
leadList.add((Lead)lead);
} else {
countMap.put((String)lead.get(System.Label.Lead_Field),1);
}
}
}
Database.delete(leadList,false);
}
/**
This method will execute at end of Batch apex process.
@return Nothing.
*/
global void finish(Database.BatchableContext BC) {
}
}
  • August 20, 2018
  • Like
  • 0
Need Test class for following Batch apex that check closed won opportunity and send mail every midnight.
Please add positive negative and bulk test cases with 100% code coverage.

global class ContactWithClosedWonOpportunities 
  implements Database.Batchable<sObject>, Database.Stateful {
  
  /**
    This Map will store the contact email IDs and respective List of Opportunites.
   */
  Map<String,List<Opportunity>> contactOpprtunitiesMap = 
    new Map<String,List<Opportunity>>();
  
  /**
    This method will Query all Contacts associate with Account having Closed Won Opportunities.
    @return Database.QueryLocator
   */
  global Database.QueryLocator start(Database.BatchableContext BC) {
    return Database.getQueryLocator(
      'SELECT ' +
        'Name, ' +
        '( SELECT Email FROM Contacts WHERE Preferred_Contact__c = TRUE LIMIT 1 ), ' +
        '( SELECT Name, Amount FROM Opportunities WHERE StageName LIKE \'Closed Won\') ' +
      'FROM ' +
        'Account ' +
      'WHERE ' +
        'id ' +
      'IN ' +
        '(SELECT AccountId FROM Contact WHERE Preferred_Contact__c = TRUE)'
    );
  }

  /**
    This method will add the values in contactOpportunitesMap.
    @return Nothing.
   */
     global void execute(Database.BatchableContext BC, List<sObject> scope) {
    List<Account> accountList = (List<Account>) scope;
    System.debug(scope + '-------------------------  ');
    for(Account accountRecord : accountList) {
      if(accountRecord.Contacts[0].email != null) {
        contactOpprtunitiesMap.put(
          accountRecord.Contacts[0].email, 
          accountRecord.Opportunities
        );
      }
    }
  }
  
  /**
    This method will send to each primary contact with Opportunity name and Amount.
    @return Nothing.
   */
  global void finish(Database.BatchableContext BC) {
    List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
    for( String mailId : contactOpprtunitiesMap.keySet() ) {
      Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

      List<String> sendTo = new List<String>();
          sendTo.add(mailId);
          mail.setToAddresses(sendTo);

      mail.setReplyTo('ayisha@gmail.com');
      mail.setSubject('All Closed Won Opportunities');

      String body = '<html><body>Dear Sir/Mam, <br/><br/>'; 
      body += 'All Closed Won Opportunities are - <br/>';
      Decimal total = 0;
      for( Opportunity opportunityRecord : contactOpprtunitiesMap.get(mailId) ) {
        body += '&nbsp;&nbsp;&nbsp;&nbsp;' + opportunityRecord.Name + ':  ' + 
            opportunityRecord.Amount + '<br/>';
        total += opportunityRecord.Amount;
      }
      body += '<br/>&nbsp;&nbsp;&nbsp;&nbsp; <b>Total: ' + total + '</b></body></html>';
      mail.setHtmlBody(body);
      System.debug(body);
      mails.add(mail);
    }
    Messaging.sendEmail(mails);
  }
  
}
  • August 20, 2018
  • Like
  • 0
Need Test Class for following scenario..Where VF Page display a form that take input and add record in Student object.
Please consider all positive negative test cases.

---------------------------------------------------VF Page----------------------------------------------------------
<apex:page standardController="Student__c" extensions="StudentRegFormExtension" language="{!selectedLang }"
    sidebar="false" 
>
    <apex:form >
        <apex:selectList value="{!selectedLang}" size="1">
            <apex:selectoptions value="{!listOfLang}"/>
            <apex:actionsupport event="onchange" reRender="form"/>
        </apex:selectlist>

        <apex:outputPanel id="pageMessage">
            <apex:pageMessages rendered="true" ></apex:pageMessages>
        </apex:outputPanel>

        <apex:pageblock >
                <apex:pageblocksection id="form">
                    <apex:inputfield value="{! Student__c.Name }"/>
                    <apex:inputfield value="{! Student__c.Roll_Number__c }"/>
                   
                    <apex:inputfield value="{! Student__c.Gender__c }"/>
                    <apex:inputfield value="{! Student__c.Course_Applying_For__c }"/>
                    <apex:inputfield value="{! Student__c.SSC__c }"/>
                    <apex:inputfield value="{! Student__c.HSC__c }"/>
                    <apex:inputfield value="{! Student__c.City__c }"/>
                    <apex:inputfield value="{! Student__c.State__c }"/>
                    <apex:inputfield value="{! Student__c.Country__c }"/>
                </apex:pageblocksection>
                <div align="center" draggable="false" >
                       <apex:commandButton value="{!$Label.Record_Inserted}" action="{! save}" reRender="pageMessage"/>
                       </div>
        </apex:pageblock>
    </apex:form>
</apex:page>

---------------------------------------------------CONTROLLER-------------------------------------------------------------
public class StudentRegFormExtension {
    
    public Boolean showMessage{get;set;}
    public String selectedLang{get;set;}
    public List<SelectOption> listOfLang {get;set;}
    public ApexPages.StandardController controller{get;set;}
  
    
    public StudentRegFormExtension(ApexPages.StandardController con) {
       controller = con;
       showMessage = false;
        listOfLang = new List<SelectOption>();
        listOfLang.add(new SelectOption('en','English'));
        listOfLang.add(new SelectOption('es','Spanish'));
        listOfLang.add(new SelectOption('fr','French'));
     if(ApexPages.currentPage().getParameters().get('Success') != null ) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,
            System.Label.Record_Inserted));
       
    }
    }
    
     public PageReference save() {

        Student__c student = (Student__c)controller.getRecord();
        PageReference pr;
        if(student.Name == null) {
             ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,
                System.Label.Error_Inserting_Record));

        }else {
            controller.save();
            pr = new PageReference('/apex/StudentRegForm?Success=true');
            pr.setRedirect(true);
        }
        return pr;
    }
}
  • August 20, 2018
  • Like
  • 0
Hello Experts,
Need test class for following VF page that display a registeration form with name,roll number,gender fields. all save the result and display form in multiple language.

--------------------------VF PAGE-------------------------------
<apex:page standardController="Student__c" extensions="StudentRegFormExtension" language="{!selectedLang }"
    sidebar="false" 
>
    <apex:form >
        <apex:selectList value="{!selectedLang}" size="1">
            <apex:selectoptions value="{!listOfLang}"/>
            <apex:actionsupport event="onchange" reRender="form"/>
        </apex:selectlist>

        <apex:outputPanel id="pageMessage">
            <apex:pageMessages rendered="true" ></apex:pageMessages>
        </apex:outputPanel>

        <apex:pageblock >
                <apex:pageblocksection id="form">
                    <apex:inputfield value="{! Student__c.Name }"/>
                    <apex:inputfield value="{! Student__c.Roll_Number__c }"/>
                   
                    <apex:inputfield value="{! Student__c.Gender__c }"/>
                    <apex:inputfield value="{! Student__c.Course_Applying_For__c }"/>
                    <apex:inputfield value="{! Student__c.State__c }"/>
                    <apex:inputfield value="{! Student__c.Country__c }"/>
                </apex:pageblocksection>
                <div align="center" draggable="false" >
                       <apex:commandButton value="{!$Label.Record_Inserted}" action="{! save}" reRender="pageMessage"/>
                       </div>
        </apex:pageblock>
    </apex:form>
</apex:page>
-------------------------------------------Controller------------------------------------------


public class StudentRegFormExtension {
    
    public Boolean showMessage{get;set;}
    public String selectedLang{get;set;}
    public List<SelectOption> listOfLang {get;set;}
    public ApexPages.StandardController controller{get;set;}
  
    
    public StudentRegFormExtension(ApexPages.StandardController con) {
       controller = con;
       showMessage = false;
        listOfLang = new List<SelectOption>();
        listOfLang.add(new SelectOption('en','English'));
        listOfLang.add(new SelectOption('es','Spanish'));
        listOfLang.add(new SelectOption('fr','French'));
     if(ApexPages.currentPage().getParameters().get('Success') != null ) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,
            System.Label.Record_Inserted));
       
    }
    }
    
     public PageReference save() {

        Student__c student = (Student__c)controller.getRecord();
        PageReference pr;
        if(student.Name == null) {
             ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,
                System.Label.Error_Inserting_Record));

        }else {
            controller.save();
            pr = new PageReference('/apex/StudentRegForm?Success=true');
            pr.setRedirect(true);
        }
        return pr;
    }
    
}
  • August 17, 2018
  • Like
  • 0
Hello Experts,
Need test class for following VF page that display a dependent picklist which is a customSetting. Consider all positive negative test cases

--------------------------VF PAGE-----------------------------
<apex:page controller="CountryDependentController" showHeader="true" sidebar="false">    
    <apex:pageBlock >
        <apex:form >
        <!-- actionFunction -->
            <apex:actionFunction action="{!getCountrylist}" name="rerenderCities" rerender="Cities" >
                <apex:param name="firstParam" assignTo="{!country}" value="" />
            </apex:actionFunction>
            
            <!-- SelectList-->
            Country :   <apex:selectList value="{!country}" size="1" onchange="rerenderCities(this.value)">
                            <apex:selectOptions value="{!CountryList}"></apex:selectOptions>
                        </apex:selectList> <br/> <br/>
            City :      <apex:selectList id="Cities" value="{! cities}" size="1">
                            <apex:selectOptions value="{!CityList}"></apex:selectOptions>
                        </apex:selectList>
        </apex:form>
    </apex:pageBlock>
</apex:page>

------------------------------------CONtroller--------------------------------------------------
 public class CountryDependentController {
        Map<String, Country__c> countryMap = Country__c.getall();
        public String cities{ get; set; }
        public String country{ get; set;}
    
    public List<SelectOption> getCountrylist() {
    
    /* Method will give list of countries   
     * @param: NA
     * @return: selectoption: The country which will be selected by user will be returned
     */ 
        List<SelectOption> selectoptionList = new List<SelectOption>();
        for(String country : countryMap.keySet()){
        selectoptionList.add(new selectoption(country,country));
        }
        return selectoptionList;
        }
    
    /* Method will give list of cities   
     * @param: NA
     * @return: selectoptionList: Based on selected country user can select any city related to that country.
     */     
    public List<SelectOption> getCityList() {      
    List<SelectOption> selectoptionList = new List<SelectOption>();
        if( country == null ) {
            return selectoptionList;
        } else {
    List<City__c> cityList = City__c.getAll().values();
            for(City__c city : cityList) {
                if(city.Country__c == country ) {
                    selectoptionList.add(new selectoption(city.Name, city.Name));
                } 
            }
        }
        return selectoptionList;
        }
    } 
  • August 17, 2018
  • Like
  • 0
@isTest
public class PagingDemoWithAlpabetsTest {
  

  /**
    This method tests Searching functionality of AlphabeticSearchExtension.
    @return Nothing.
   */
  @isTest 
  public static void testSearch() {
    PageReference pageRef = Page.ContactAlphaSearch;
    Contact contactObject = new Contact(LastName='Eternus');
    ApexPages.StandardController StandardControllerObject = new ApexPages.StandardController(contactObject);
    PagingDemoWithAlpabets alpabetsTestObject = new PagingDemoWithAlpabets(StandardControllerObject);
    PagingDemoWithAlpabets.SearchVar = 'A';

    pageRef.getParameters().put('Alphabet','T');
   // Test.setCurrentPage(pageRef);

    System.Test.startTest();
    PagingDemoWithAlpabets.display();
    System.Test.stopTest();

    System.assertEquals(0,size, 
      'PagingDemoWithAlpabets Failed for Searching');
  }

  /**
    This method tests Searching functionality of AlphabeticSearchExtension for Alphabets.
    @return Nothing.
   */
   
  @isTest static void testSearchAlpha() {
    PageReference pageRef = Page.ContactAlphaSearch;
    pageRef.getParameters().put('Alphabet','A');
    Test.setCurrentPage(pageRef);
    AlphabeticSearchExtension searchExtension = new AlphabeticSearchExtension();

    Test.startTest();
    searchExtension.search();
    Test.stopTest();

    System.assertEquals(searchExtension.renderTable, false, 
      'AlphabeticSearchExtension Failed for Searching A characher');
  }

  /**
    This method tests Searching functionality of AlphabeticSearchExtension for No parameter.
    @return Nothing.
   */
  @isTest static void testSearchNoParam() {
    PageReference pageRef = Page.ContactAlphaSearch;
    Test.setCurrentPage(pageRef);
    AlphabeticSearchExtension searchExtension = new AlphabeticSearchExtension();

    Test.startTest();
    searchExtension.search();
    Test.stopTest();

    System.assertEquals(searchExtension.renderTable, false, 
      'AlphabeticSearchExtension Failed for Searching  No parameter');
  }

  /**
    This method tests Searching functionality of AlphabeticSearchExtension for All character.
    @return Nothing.
   */
  @isTest static void testSearchAll() {
    PageReference pageRef = Page.ContactAlphaSearch;
    pageRef.getParameters().put('Alphabet','All');
    Test.setCurrentPage(pageRef);
    AlphabeticSearchExtension searchExtension = new AlphabeticSearchExtension();

    Test.startTest();
    searchExtension.search();
    Test.stopTest();

    System.assertEquals(searchExtension.renderTable, false, 
      'AlphabeticSearchExtension Failed for Searching All characher');
  }

  /**
    This method tests Searching functionality of AlphabeticSearchExtension for Other than Alphabets.
    @return Nothing.
   */
  @isTest static void testSearchOther() {
    PageReference pageRef = Page.ContactAlphaSearch;
    pageRef.getParameters().put('Alphabet','Other');
    Test.setCurrentPage(pageRef);
    AlphabeticSearchExtension searchExtension = new AlphabeticSearchExtension();

    Test.startTest();
    searchExtension.search();
    Test.stopTest();

    System.assertEquals(searchExtension.renderTable, false, 
      'AlphabeticSearchExtension Failed for Searching Other characher');
  }

  /**
    This method tests deletion functionality of AlphabeticSearchExtension.
    @return Nothing.
   */
  @isTest static void testDelete() {
    PageReference pageRef = Page.ContactAlphaSearch;
    List<Contact> contactRecord = TestDataFactory.createContact(1);
    insert contactRecord;
    Test.setCurrentPage(pageRef);

    Test.startTest();
    AlphabeticSearchExtension.deleteContact(contactRecord[0].id);
    Test.stopTest();

    contactRecord = [
      SELECT
        id
      FROM
        Contact
    ];

    System.assertEquals( contactRecord.size(), 0, 
      'AlphabeticSearchExtension Failed for Delete contact functionality.');
  }

}
User-added image
  • August 17, 2018
  • Like
  • 0
I am new to Vf and test class. Can anyone please help me in test class for following Visual Force. Requirement is to display all Account record and when clicked on Account Name Related contact must be displayed.
Following is the VF PAge and Controller
-----------------------------------------------------------------------------------VF-----------------------------------------------------------------
<apex:page standardController="Account" extensions="SearchAccountExtensions1" showHeader="false" sidebar="false">
    <apex:form >
        <apex:pageBlock >
            <apex:outputPanel id="table">
            <br/>
                <h1> Account List</h1>
            <br/>
            <br/>
                <apex:outputPanel rendered="{! renderTable }">
                    <apex:pageBlockTable value="{! accountList }" var="account">
                        <apex:column headerValue="Account Name">
                          <apex:outputLink value="/apex/RelatedContactSearch?AccId={!account.id}">
                                {!account.name}
                          </apex:outputLink> 
                        </apex:column>
                        <apex:column value="{!account.Name}"/>
                        <apex:column value="{!account.Phone}"/>
                        <apex:column value="{!account.BillingStreet}"/>
                        <apex:column value="{!account.BillingCity}"/>
                        <apex:column value="{!account.BillingState}"/>
                        <apex:column value="{!account.BillingPostalCode}"/>
                        <apex:column value="{!account.BillingCountry}"/>                            
                    </apex:pageBlockTable> 
                </apex:outputPanel>   
            </apex:outputPanel>
        </apex:pageBlock>   
    </apex:form>
</apex:page>

----------------------------------------------------------------------------------Controller------------------------------------------------------------
public class SearchAccountExtensions1 {

    public SearchAccountExtensions1(ApexPages.StandardController controller) {
            this();
    }

    public List<Account> accountList{ get;set; }
    public String inputString{get;set;}
    public Boolean renderTable{get;set;}

    /**
        This is constructor of extension which initialize initial rendering of Account Table.
     */
    public SearchAccountExtensions1() {
        renderTable = true;
        inputString = ApexPages.currentPage().getParameters().get('input');
        if( inputString == null ) {
            accountList = [
                SELECT
                    Name,
                    Phone,
                    BillingStreet, BillingCity, BillingState, BillingPostalCode,BillingCountry
                FROM
                    Account  
            ];
        }
    }
}
  • August 17, 2018
  • Like
  • 0
Can anyone provide test class for following VF PAGE . The requirement is to search text in account,,contact,lead.
Please Include minimum 5 Asserts and test cases for positive negative bulk scenarios.

-------------------------------------------------VF--------------------------------------------
<apex:page Controller="SOSLController">
  <apex:form >
    <apex:inputText value="{!searchStr}"/>
    <apex:commandButton value="Search in Account, Contact, Opportunity" action="{!search}" reRender="accountId,error,opportunityId,contactId" status="actStatusId"/>
    <apex:actionStatus id="actStatusId">
      <apex:facet name="start" >
      <img src="/img/loading.gif"/>                    
      </apex:facet>
    </apex:actionStatus>
  </apex:form>
    
  <apex:outputPanel title="" id="error">
    <apex:pageMessages ></apex:pageMessages>
  </apex:outputPanel>
  
  
  <apex:pageBlock title="Accounts" id="accountId">
    <apex:pageblockTable value="{!accountList }" var="accountVar">
      <apex:column value="{!accountVar.name}"/>
      <apex:column value="{!accountVar.Type}"/>
    </apex:pageblockTable>
  </apex:pageBlock>

  
 
  <apex:pageBlock title="Contacts" id="contactId">
    <apex:pageblockTable value="{!contactList}" var="contactVar">
      <apex:column value="{!contactVar.name}"/>
      <apex:column value="{!contactVar.email}"/>
    </apex:pageblockTable>
  </apex:pageBlock>
  
  
      
  
  <apex:pageBlock title="Opportunities" id="opportunityId">
    <apex:pageblockTable value="{!OpportunityList}" var="opportunityVar">
      <apex:column value="{!opportunityVar.name}"/>
      <apex:column value="{!opportunityVar.StageName}"/>
    </apex:pageblockTable>
  </apex:pageBlock>
</apex:page>
-------------------------------------------------Controller------------------------------------------

Public with sharing class SOSLController{
  Public List<Opportunity> OpportunityList {get;set;}
  Public List<contact> contactList{get;set;}
  Public List<account> accountList{get;set;}
    
  Public String searchStr{get;set;}
    Public SOSLController(){
    }
    /**
    Method:searchText 
    Description : Method use SOSL Query to search the text.
    @return : searchText or Error Message */
    Public List<List<sObject>> search(){
      OpportunityList = New List<Opportunity>();
      contactList = New List<contact>();
      accountList = New List<account>();
     
      String searchStr1 = '*'+searchStr+'*';
      String searchQuery = 'FIND \'' + searchStr1 + '\' IN Name FIELDS RETURNING  Account (Id,Name,type),Contact(name,email),Opportunity(name,StageName)';
      List<List <sObject>> searchList = search.query(searchQuery);
      accountList = ((List<Account>)searchList[0]);
      contactList  = ((List<contact>)searchList[1]);
      OpportunityList = ((List<Opportunity>)searchList[2]);
      if(accountList.size() == 0 && contactList.size() == 0 && OpportunityList.size() == 0){
          apexPages.addmessage(new apexpages.message(apexpages.severity.Error, 'Sory, no results returned with matching string..'));
          
      }
    return searchList;
    }
}
  • August 17, 2018
  • Like
  • 0
Create a new link on the contact row to delete the contact from the account. On clicking the link, the contact should be deleted this time using VisualForce Remoting. On successful deletion, an alert should be displayed on the page stating “The contact has been deleted”.
  • August 04, 2018
  • Like
  • 1
I need a custom button on opportunity detail page that will open the report assosciated with opportunity. what should i do? Can anyone help?
  • September 03, 2018
  • Like
  • 0
Need Test class for following Rest Service class to insert update delete Lead record.
Can anyone help? please provide positive negative bulk test scenarios.
@RestResource(urlMapping='/Lead')
global class LeadManipulationService {
    
    global class Result {
        public Boolean isSuccess;
        public String lead;
        public String status;
    }
    
  @HttpPost
    global static Result createLead(String firstName, String lastName, String email, String phone, String company) {
        Result res= new Result();
        res.isSuccess = false;
        res.status = 'Error';
        
        Lead l = new Lead();
        l.FirstName = firstName;
        l.LastName = lastName;
        l.Email = email;
        l.Phone = phone;
        l.Company = company;
        
        
        try {
            insert l;
        }catch(DMLException e) {
            return res;
        }
        
     res.isSuccess = true;
        res.status = 'Success';
        res.lead = l.Id;
        return res;   
        
    }
    
    
    @HttpPut
    global static Result updateLead(String firstName, String lastName, String email, String phone) {
        Result res= new Result();
        res.isSuccess = false;
        res.status = 'Error';
        
        List<Lead> l = [
            SELECT
              FirstName,
              LastName,
              Email,
              Phone
            FROM
              Lead
            WHERE
        FirstName LIKE :firstName
            AND
              LastName LIKE :lastName
            LIMIT 1
        ];
        l[0].FirstName = firstName;
        l[0].LastName = lastName;
        l[0].Email = email;
        l[0].Phone = phone;
        
        
        try {
            update l;
        }catch(DMLException e) {
            return res;
        }
        
     res.isSuccess = true;
        res.status = 'Success';
        res.lead = l[0].Id;
        return res;   
        
    }
    
    
    
    @HttpDelete
   global static Result deleteLead() {
        Result res= new Result();
        res.isSuccess = false;
        res.status = 'Error';
        
        String firstName = RestContext.request.params.get('firstName');
        String lastName = RestContext.request.params.get('lastName');
        String email = RestContext.request.params.get('email');
        String phone = RestContext.request.params.get('phone');
        

        List<Lead> leadList = [
            SELECT
                id
            FROM
                Lead
            WHERE
                FirstName = :firstName 
            AND
                LastName = :lastName
            AND 
                Email = :email
            AND
                Phone = :phone
        ];
        
        try {
            delete leadList;
        }catch(DMLException e) {
            return res;
        }
        
     res.isSuccess = true;
        res.status = 'Success';
        res.lead = leadList[0].Id;
        return res;   
        
    }
 
    
}
  • August 21, 2018
  • Like
  • 0
Can anyone provide Test class for following use Case.
Consider all positive negative and bulk test case

Use case ::
Collection of Closed Won Opportunities
1. The Primary contact associated with an account needs to know which all are the closed won opportunities for his account per day.
2. Create a process which will run every day in the midnight & collect all the Closed won opportunities of that account in a day & send an email to Primary Contact.
3. The email body should contain the Opportunity Name & it's respective amount with the aggregated amount in the end.

-----------------------------------------------------------------------Batch Class-------------------------------------------------------------
global class ContactWithClosedWonOpportunities
implements Database.Batchable<sObject>, Database.Stateful {
/**
This Map will store the contact email IDs and respective List of Opportunites.
*/
Map<String,List<Opportunity>> contactOpprtunitiesMap =
new Map<String,List<Opportunity>>();
/**
This method will Query all Contacts associate with Account having Closed Won Opportunities.
@return Database.QueryLocator
*/
global Database.QueryLocator start(Database.BatchableContext BC) {
return Database.getQueryLocator(
'SELECT ' +
'Name, ' +
'( SELECT Email FROM Contacts WHERE Preferred_Contact__c = TRUE LIMIT 1 ), ' +
'( SELECT Name, Amount FROM Opportunities WHERE StageName LIKE \'Closed Won\') ' +
'FROM ' +
'Account ' +
'WHERE ' +
'id ' +
'IN ' +
'(SELECT AccountId FROM Contact WHERE Preferred_Contact__c = TRUE)'
);
}
/**
This method will add the values in contactOpportunitesMap.
@return Nothing.
*/
global void execute(Database.BatchableContext BC, List<sObject> scope) {
List<Account> accountList = (List<Account>) scope;
//System.debug(scope + '------------------------- ');
for(Account accountRecord : accountList) {
if(accountRecord.Contacts[0].email != null) {
contactOpprtunitiesMap.put(
accountRecord.Contacts[0].email,
accountRecord.Opportunities
);
}
}
}
/**
This method will send to each primary contact with Opportunity name and Amount.
@return Nothing.
*/
global void finish(Database.BatchableContext BC) {
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
for( String mailId : contactOpprtunitiesMap.keySet() ) {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
List<String> sendTo = new List<String>();
sendTo.add(mailId);
mail.setToAddresses(sendTo);
mail.setReplyTo('ayisa@gmail.com');
mail.setSubject('All Closed Won Opportunities');
String body = '<html><body>Dear Sir/Mam, <br/><br/>';
body += 'All Closed Won Opportunities are - <br/>';
Decimal total = 0;
for( Opportunity opportunityRecord : contactOpprtunitiesMap.get(mailId) ) {
body += '&nbsp;&nbsp;&nbsp;&nbsp;' + opportunityRecord.Name + ': ' +
opportunityRecord.Amount + '<br/>';
total += opportunityRecord.Amount;
}
body += '<br/>&nbsp;&nbsp;&nbsp;&nbsp; <b>Total: ' + total + '</b></body></html>';
mail.setHtmlBody(body);
System.debug(body);
mails.add(mail);
}
Messaging.sendEmail(mails);
}
}
  • August 20, 2018
  • Like
  • 0
Can anyone provide test class for following VF PAGE . The requirement is to search text in account,,contact,lead.
Please Include minimum 5 Asserts and test cases for positive negative bulk scenarios.

-------------------------------------------------VF--------------------------------------------
<apex:page Controller="SOSLController">
  <apex:form >
    <apex:inputText value="{!searchStr}"/>
    <apex:commandButton value="Search in Account, Contact, Opportunity" action="{!search}" reRender="accountId,error,opportunityId,contactId" status="actStatusId"/>
    <apex:actionStatus id="actStatusId">
      <apex:facet name="start" >
      <img src="/img/loading.gif"/>                    
      </apex:facet>
    </apex:actionStatus>
  </apex:form>
    
  <apex:outputPanel title="" id="error">
    <apex:pageMessages ></apex:pageMessages>
  </apex:outputPanel>
  
  
  <apex:pageBlock title="Accounts" id="accountId">
    <apex:pageblockTable value="{!accountList }" var="accountVar">
      <apex:column value="{!accountVar.name}"/>
      <apex:column value="{!accountVar.Type}"/>
    </apex:pageblockTable>
  </apex:pageBlock>

  
 
  <apex:pageBlock title="Contacts" id="contactId">
    <apex:pageblockTable value="{!contactList}" var="contactVar">
      <apex:column value="{!contactVar.name}"/>
      <apex:column value="{!contactVar.email}"/>
    </apex:pageblockTable>
  </apex:pageBlock>
  
  
      
  
  <apex:pageBlock title="Opportunities" id="opportunityId">
    <apex:pageblockTable value="{!OpportunityList}" var="opportunityVar">
      <apex:column value="{!opportunityVar.name}"/>
      <apex:column value="{!opportunityVar.StageName}"/>
    </apex:pageblockTable>
  </apex:pageBlock>
</apex:page>
-------------------------------------------------Controller------------------------------------------

Public with sharing class SOSLController{
  Public List<Opportunity> OpportunityList {get;set;}
  Public List<contact> contactList{get;set;}
  Public List<account> accountList{get;set;}
    
  Public String searchStr{get;set;}
    Public SOSLController(){
    }
    /**
    Method:searchText 
    Description : Method use SOSL Query to search the text.
    @return : searchText or Error Message */
    Public List<List<sObject>> search(){
      OpportunityList = New List<Opportunity>();
      contactList = New List<contact>();
      accountList = New List<account>();
     
      String searchStr1 = '*'+searchStr+'*';
      String searchQuery = 'FIND \'' + searchStr1 + '\' IN Name FIELDS RETURNING  Account (Id,Name,type),Contact(name,email),Opportunity(name,StageName)';
      List<List <sObject>> searchList = search.query(searchQuery);
      accountList = ((List<Account>)searchList[0]);
      contactList  = ((List<contact>)searchList[1]);
      OpportunityList = ((List<Opportunity>)searchList[2]);
      if(accountList.size() == 0 && contactList.size() == 0 && OpportunityList.size() == 0){
          apexPages.addmessage(new apexpages.message(apexpages.severity.Error, 'Sory, no results returned with matching string..'));
          
      }
    return searchList;
    }
}
  • August 17, 2018
  • Like
  • 0
I needed a trigger to create clone of account record on insert.
To avoid recursion I have used a boolean. Is there any method to stop recursion that can be used in this place.
-------------------------------------------------------------------------------------
public class CloneAccountTriggerHandler {
public static Boolean cloneRecord = true;
/**
Method : cloneAccountRecord
Type : Test Method
Description : Method To create Clone of Account Record when inserted
*/
public static List<Account> cloneAccountRecord(List<Account> newAccount){
List<Account> listAccount = new List<Account>();
if(cloneRecord) {
System.debug(newAccount);
cloneRecord = false;
for(Account account : newAccount) {
listAccount.add(account.clone(false));
}
Database.insert(listAccount,false);
}
return listAccount;
}
}
  • August 07, 2018
  • Like
  • 0