• Anik soni 7
  • NEWBIE
  • 20 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 1
    Replies
When an account is inserted or updated,check whether any opportunity is linked to it or not,if not then create one whose name is ‘First Opportunity -<Account Name>’.
Here is my code:


trigger CheckOpportunitys on Account (before insert, before update) 
{
    if(trigger.isafter)
    {
        if(trigger.isinsert)
        {
            for(account acc : trigger.new)
            {
                List<opportunity> op = [Select Name from opportunity where accountid = :acc.Id];
                if(op.isempty())
                {
                    Opportunity opp = new opportunity(Name = 'First opportunity'+ acc.Name, Stagename ='Qualification',CloseDate = date.today(), accountid = acc.Id);
                    op.add(opp); 
                } 
                Else
                {
                    System.debug('This opportunity is already EXIST'); 
                }
                insert op;
            }
        }
    }
    else if(trigger.isBefore)
    {
        if(trigger.isupdate)
        {
            for(account ac: trigger.old)
            {
                List<opportunity> op =[Select name from opportunity where accountid = :ac.id]; 
                if(op.isEmpty())
                {
                    Opportunity opp = new opportunity(Name = 'First opportunity'+ ac.Name, Stagename ='Qualification',CloseDate = date.today(), accountid = ac.Id);
                    op.add(opp);
                }
                Else
                {
                    op.addError('This opportunity is already Exits');
                }
                insert op;
            }
        }
    } 
}
There is a field Number_of _contact__c in which I want the total number of contacts of particular account for instance if account A has 4 contacts so in the field of the account whose name is Number_of _contacts__c show's 4 and if we delete 1 so it shows 3. User-added imageUser-added image 
Q1. How to insert account with the help of 2D List.
Q2. How to insert 100,000 records without using Betch class.
Hi, I am not able to Install the DreamHouse app, even though i follow the steps after that i am stuck on the DATA IMPORT step when i click on that tab it is continuously loading the page there is no option is coming to click on  Initialize Sample Data. What do i do and it showsThis message is showing on Trailhead..!!This image is continuously loading the error on the trailhead page like...
 
How to find out those accounts who's opportunity is more than 2? 
When an opportunity is inserted check for it’s a delicacy on the basis of its name and the account to which it is related to i.e. If it has the same name and it’s linked to the same Account then append “Duplicate Opportunity” in the name.
When an opportunity is inserted check for it’s a delicacy on the basis of its name and the account to which it is related to i.e. If it has the same name and it’s linked to the same Account then append “Duplicate Opportunity” in the name.