Create New opportunity based on account criteria

Hi Guys,
Hope you enjoyed Diwali 😎 
Today I came here with a scenario which i faced recently

Business case : If Account rating is “Hot”, need to create new opportunity. So we need to Create New opportunity based on account criteria
we can achieve this with process builder and trigger. Here I try to explained you in way on trigger.

Today I am facing error that while i am entering into my salesforce org. I find out salesforce org is requesting to check our identity, It send me to check my verification to my email and need to paste code on our salesforce login page . So I though it make issue while i am working on major escalation and need to passed this issue . I found the google chrome plugin and which helps me to reslove that in a couple of minutes so i like to share here. I know lot of developer got same issue as faced to me.



Trigger


trigger createOpportunity on Account (after insert) {
    List oppsToUpdate = new List();
    for(Account ac : Trigger.new) {
    if (ac.Rating== 'Hot') {
    Opportunity o = new Opportunity (); 
    o.StageName = 'Closed Won'; 
    o.CloseDate = Date.today(); 
    o.Name = 'Opp';
    oppsToUpdate.add(o);
    }
    
    }
    insert oppsToUpdate; 
    }

                        

Test Class


    @isTest
    private class opp_Test{
        static testMethod void test_createOpportunity(){
            test.startTest();
            account a = new account();
            a.name = 'ForceLearn Pvt Ltd';
            a.rating = 'hot';
            Insert a; 
            test.stopTest();
           }
       }                           
                        



Download: SalesforceQA


Please comments us for more updates and share to other to help.
Keep Visiting us for more updates
Like us for more updates
Fb Page : ForceLearn
keep share to help others  😎 😎 😎