Coding Genius (Trigger)

The following practice questions are for Salesforce developers who are new to salesforce and wish to solve some basic programming questions. Write a trigger

1. On Account create a default contact every time an account is created. What is Trigger

Click here to learn more

trigger Accounttir on Account (after insert) {

list<contact> con = new list<contact>();

for(Account acc : trigger.new){

contact c = new contact();

c.LastName = acc.Name;

c.AccountID = acc.ID;

con.add(c);

}

insert con;

}

2. Bulkify the above trigger to manage multiple record insertion. Trigger Bulkify

Click here to learn more

trigger Accounttir on Account (after insert) {

list<contact> con = new list<contact>();

for(Account acc : trigger.new){

contact c = new contact();

c.LastName = acc.Name;

c.AccountID = acc.ID;

con.add(c);

}

insert con;

}

3. On Opportunity to not let the user insert Opportunities with pass closed Date with following Message “Please enter a future Closed Date”. This can also be implemented by a validation rule but we want a Trigger to be written

Click here to learn more

trigger opportunitydate on Opportunity (before insert) {

for(opportunity opp : trigger.new) {

if(opp.Closedate<=Date.Today()){

opp.adderror(‘please eneter a future closed date’);

}

}

}

4. On Product to setup default Pricebook entry in the “Standard Pricebook” as 1$. Product Schema Diagram

Click here to learn more

trigger Productupdate on Product2 (after insert) {

list<PricebookEntry> pblist = new list<PricebookEntry>();

Pricebook2 pb=[Select id FROM Pricebook2 WHERE IsStandard=true];

for(Product2 pro:trigger.new){

PriceBookEntry pbe=new PriceBookEntry();

pbe.pricebook2id = pb.id;

pbe.Unitprice=1;

pbe.Product2Id=pro.id;

pblist.add(pbe);

} insert pblist;

}

5. On Contact to update the Account Name field with contact Last Name, concatenated in the end. Example If “Tata” Account gets a contact “Ratan” created then Account Name field will be updated as “TataRatan”.

Click here to learn more

trigger updateAccname on Contact (after insert,before delete) {

List<Account> accountlist=new List<Account>();

if(trigger.isInsert){

for(Contact con:[select Accountid,Account.Name,LastName from Contact WHERE Id

IN:trigger.new]){

if(con.Account.Name!=null){

con.Account.Name+=con.LastName;

accountlist.add(con.Account);

}

}

}else if(trigger.isDelete){

for(Contact con : [select AccountId, Account.Name, LastName from Contact WHERE Id IN:

trigger.old]){

system.debug(‘** contact –‘+con + ‘ *** Account –‘ + con.AccountId + ‘ *** Account Name — ‘+

con.Account.Name);

con.Account.Name = con.Account.Name.replace(con.LastName,”);

accountlist.add(con.Account);

}

}

system.debug(‘*** ‘ +accountlist);

update accountlist;

}

6. Update the above trigger to delete the Last Name from the Account Company field when a Contact is deleted without deleting the other Last name. Example If “TataRatanNori” Account already have “Ratan” and “Nori” as its contacts and then contact “Ratan” gets deleted then Account Name field will be updated as “TataNori”.

Click here to learn more

trigger updateAccname on Contact (after insert,before delete) {

List<Account> accountlist=new List<Account>();

if(trigger.isInsert){

for(Contact con:[select Accountid,Account.Name,LastName from Contact WHERE Id

IN:trigger.new]){

if(con.Account.Name!=null){

con.Account.Name+=con.LastName;

accountlist.add(con.Account);

}

}

}else if(trigger.isDelete){

for(Contact con : [select AccountId, Account.Name, LastName from Contact WHERE Id IN:

trigger.old]){

system.debug(‘** contact –‘+con + ‘ *** Account –‘ + con.AccountId + ‘ *** Account Name — ‘+

con.Account.Name);

con.Account.Name = con.Account.Name.replace(con.LastName,”);

accountlist.add(con.Account);

}

}

system.debug(‘*** ‘ +accountlist);

update accountlist;

}

7. On Opportunity to alert the user when an Opportunity is being closed with no Opportunity line items in it.

Click here to learn more

trigger Opportunityalert on Opportunity (after update) {

for(Opportunity opp : [Select Id,StageName, (Select Id FROM OpportunityLineItems) FROM

Opportunity WHERE Id IN :Trigger.new])

{

if(opp.StageName == ‘Closed Won’ || opp.StageName == ‘CLosed Lost’ &&

opp.OpportunityLineItems.size() == 0 ){

trigger.newmap.get(opp.id).adderror(‘There is no opportunity Line Item ‘);

}

}

}

 

Author: AJ

Share This Post On

2 Comments

  1. Dear Sir,

    Great sir, There is No Other words…….

    Post a Reply
  2. Your comment is awaiting moderation.

    life insurance
    Plumber Carrollwood FL, Carrollwood FL
    plumbing, plumber, plumbers, carrollwood, 33618, 33624, 33625, clogged, stoppage, sewer, drains, leaks, water heaters, garbage disposals, water softeners, sinks, toilets, Video Aliona Moon O mie Diaspora version, and it is a whole lot less Plumber Carrollwood FL, Carrollwood FL Plumber Carrollwood FL, Carrollwood FL same coverages. Car insurance Plumber Carrollwood FL, Carrollwood FL differ from state to state and even from one ZIP code to the next, jaguar Insurance. Family members attending school away from home and a spouse living elsewhere during a Plumber Carrollwood FL, Carrollwood FL separation also are covered, Plumber Carrollwood FL, Carrollwood FL popular. Strada 150 …
    The post Plumber Carrollwood FL, Carrollwood FL appeared first on Car.

    Maryland Finance
    tonne
    refrigerated
    first community mortgage lake
    kinky
    car

    BONUS TOP 100 DOFOLLOW TRUST LINK LIST SITE

    Online Banking, Secure online banking, Co-op Bank, cooperative bank.
    Price Optimization: Being A Loyal Auto Insurance Customer Can Cost You: NPR
    University Programs: Online Speech Pathology CEUs & Speech Pathology Jobs
    Auto Liability Insurance Coverage from Nationwide
    Compare Cheap Business Insurance Quotes Online at
    Motorcycle Insurance – Free Motorcycle Insurance Quotes
    Online Quotes
    Auto Insurance Quotes Compare, car insurance quotes online.
    Travel Insurance Companies. Compare Your Travel Insurance Company at
    Central Station vs Local Alarm – What are the Differences?
    Best Cheap Car Insurance in South Carolina for 2017
    Co-op and Condo Insurance: A Guide to Getting the Best Coverage And The Best Rates
    CSA Auto Home Insurance Plan – Canadian Snowbird Association
    Tips to Choose The Best Health Insurance Policy In India – Max Bupa Health Articles
    Cockroaches Profile: Info, Photos, Extermination
    Three arrested over LV stolen car insurance details probe – BBC News
    Cheap Hawaii Auto Insurance – Compare 10 Quotes Online
    Your access to this site has been limited
    Compare Cheap Car Insurance Quotes, very cheap car insurance.
    Read the Law
    Data Security Requirements
    16 Free and Open-Source Business Intelligence Tools – DZone Big Data
    Instant Health Insurance Quote
    Bad Credit Score Could Impact Car Insurance Rates.
    Marley Plumbing & Drainage Soil Systems – Pipes & fittings
    Cheapest Car Insurance in Florida – Save up to 70% on Florida Car Insurance Rates
    Business liability insurance
    Compare Home Insurance – Money Expert
    Cheap car insurance in 8 steps, discount auto insurance.
    Acceptance Insurance
    21st Century Auto Insurance
    Buy Term Life Insurance Online
    Rehab Center Run By Scientologist Shut Down – NewsChannel 5 Nashville
    Carpet Cleaning Nashville TN Mr, cleaning services nashville tn.
    CIS Insurance Services
    High Risk Insurance Quoteline
    My Modern Met – The Big City That Celebrates Creative Ideas, my credit.
    Affordable Car Insurance for High Risk Cars – Drivers, car insurance uk.
    Home, Auto, Farm and Commercial Insurance, Direct-Line Insurance, commercial vehicle insurance.
    West Bend Mutual Insurance Co. Reviews
    How to Get the Cheapest Motorcycle Insurance
    Auto Insurance Texas
    Geico Insurance Quote, auto insurance comparison.
    Van Insurance
    Who is Elizabeth Olsen dating? Elizabeth Olsen boyfriend, husband
    Cheap Home Insurance Quotes. Compare Low Cost Rates and Save
    New Jersey Auto Insurance
    Comprehensive Vs Collision Coverage
    USA-Generator – Home Portable generators, Home Backup
    AAMI Car Insurance Reviews.
    Dartmouth NS Insurance Agency, Nova Scotia Home Insurance, Nova Scotia Auto Insurance, Nova Scotia Business Insurance
    How to Get Health Insurance
    National Truck Insurance Company Provides Commercial Isurance Coverage for Owner Operator and Small Fleet, isurance.
    Fortis Health Insurance
    Truck Insurance Quote
    No Dental Insurance? Here are 3 Options
    Liability Auto Insurance
    How to Get the Best Car Insurance Rate Discounts В» News
    Bigger cars get better insurance rates
    Customized Java Training Courses
    Welcome to, direct bank.
    Payday Loans – Cash In Your Account in 15 Minutes, short term loans.
    Alliance Car Insurance – Insurance At Its Best
    Homes for Sale – Sell Your Home – Long and Foster, commercial real estate.
    Car Insurance Rates Mobile Form, car insurance rates.
    Are drivers ready for Big Brother car insurance plans?
    International Automotive Technicians Network, auto shop.
    Bad Credit Loans up to $1, 000 – Personal Loans up to $35, 000, personal loan.
    Atlanta Answering Service – MAP Communications
    Mexican Auto Insurance – Compare 7 Mexican Insurance Rates
    Car Insurance Companies: How To Choose One.
    Business Intelligence Tools
    Finding Cheap RV Insurance Rates that Save Money
    Calculate Your GPA, online chemistry courses for college credit.
    Domestic appliance insurance
    BMW car insurance information and online quotes
    Collector Vehicle Insurance
    Understanding Life Insurance Ratings
    Cheap Car Insurance: Looking for the Cheapest Car Insurance?
    North Carolina Car Insurance
    Should You Buy Rental Car Insurance?
    My Auto Insurance Guide Tips
    Why You Ought To Employ Auto Insurance Quotes Comparison
    Car Insurance Rates for Different Vehicle Types
    Michigan – s Top Ten Worst Automobile Insurance Companies
    Auto, Automobile, Car, Vehicle Insurance – Colorado Insurance Broker, Inc. in Denver, Lakewood, Arvada, Aurora, Westminster, Littleton
    RTC Insurance Advisors – Florida Home
    Drivers Can Now Get Instant Auto Insurance Quotes from Top Agencies! The Business Journals
    American Safety Indemnity Company v. Admiral Insurance Company – Lewis Brisbois Bisgaard – Smith LLP
    Instant Online Auto Insurance Quote Ontario – Cheap Car Insurance
    Welcome to New York Theological Seminary – New York Theological Seminary
    Cheap Auto Insurance Quotes in Utah
    Insurance Jobs
    Get IFA Insurance
    Car Insurance – Get A Car Insurance Quote Online, M – S Bank, car insurance online quote.
    Auto, Automobile, Car, Vehicle Insurance in Hendersonville, Tennessee – Coker, Wolfe & Associates, Inc.
    Web hosting packages
    Cheap Insurance Massachusetts
    How to Buy Life Insurance
    Who Has the Cheapest Car Insurance in New Jersey?

    Post a Reply

Submit a Comment

Your email address will not be published. Required fields are marked *