function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
pranavshahpranavshah 

Lead Code Explaination

Can anyone explain me below line of codes


public class myWeb2LeadExtension
{
private final Lead weblead;
public myWeb2LeadExtension(ApexPages.StandardController stdController) 
{
weblead = (Lead)stdController.getRecord();

public PageReference saveLead() {
try 
{
insert(weblead);
 }
catch(System.DMLException e) {
 ApexPages.addMessages(e);
return null;
}
PageReference p = Page.ThankYou;
p.setRedirect(true);
       return p;
     }
 
Best Answer chosen by pranavshah
RKSalesforceRKSalesforce
Hi Pranav,

Basically this code is extension class for your standard controller Lead. Please find explanation of each line in comment
public class myWeb2LeadExtension // Your class Name
{
	private final Lead weblead; // Created new instance of type Lead
	public myWeb2LeadExtension(ApexPages.StandardController stdController) // Standard Controller extension
	{
		//stdController standard controller variable
		weblead = (Lead)stdController.getRecord(); // To get your lead record
	} 
	public PageReference saveLead() { // Method declaration to save lead record
		try 
		{
			insert(weblead); // Insert Lead record if no error comes
		}
		catch(System.DMLException e) { // Come to Catch block if error comes
			ApexPages.addMessages(e); // add DMLException Message on the visualforce page
			return null;
		}
		PageReference p = Page.ThankYou; // Page reference defenation
		p.setRedirect(true); // to take controller to the ThankYou page in your salesforce org
		return p; //return Pagereference
	}
}
Please let me know if helped.

Regards,
Ramakant
 

All Answers

RKSalesforceRKSalesforce
Hi Pranav,

Basically this code is extension class for your standard controller Lead. Please find explanation of each line in comment
public class myWeb2LeadExtension // Your class Name
{
	private final Lead weblead; // Created new instance of type Lead
	public myWeb2LeadExtension(ApexPages.StandardController stdController) // Standard Controller extension
	{
		//stdController standard controller variable
		weblead = (Lead)stdController.getRecord(); // To get your lead record
	} 
	public PageReference saveLead() { // Method declaration to save lead record
		try 
		{
			insert(weblead); // Insert Lead record if no error comes
		}
		catch(System.DMLException e) { // Come to Catch block if error comes
			ApexPages.addMessages(e); // add DMLException Message on the visualforce page
			return null;
		}
		PageReference p = Page.ThankYou; // Page reference defenation
		p.setRedirect(true); // to take controller to the ThankYou page in your salesforce org
		return p; //return Pagereference
	}
}
Please let me know if helped.

Regards,
Ramakant
 
This was selected as the best answer
pranavshahpranavshah
hey Ramakant,

will you please explain these.. this code is for inserting opportunity amount and updating the field on Account

public class opportunityhandler
  {
     public void opportunityamount(list<opportunity> newopportunity)
    {
     set<Id> setOppName=new set<Id>();
     List<Account> lstActs =new list<Account>();
     List<Opportunity> opps=new list<Opportunity>();
    for(opportunity opp:newopportunity)
    {
      setOppname.add(opp.Accountid);
    }
    
    list<Account> LstAccs= [select id,Name,Total_Opportunity_Amount__c,(select id, Amount from opportunities) from account where Id IN:setOppname];
    for(Account acc: lstAccs)
    { 
    double TotalAmount=0;
    for(Opportunity opp:acc.opportunities)
    {
     if(opp.Amount!=null)
    {  
     totalAmount=TotalAmount+opp.Amount;
    }
    }  
    acc.Total_Opportunity_Amount__c=totalAmount;
    lstacts.add(acc);
    }
    update lstacts;
    }
  }