• Sitanshu Tripathi
  • NEWBIE
  • 110 Points
  • Member since 2017
  • Software Engineer
  • CLOUDCENTRIC INFOTECH


  • Chatter
    Feed
  • 3
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 0
    Questions
  • 18
    Replies
Hello
I am new to writing test class. I need help in writing test class for the following code.
scenairo: when I create a new account from UI, a nee opportunity record gets created under the account.
public class CreateNewOpportunity
{
   public List<Opportunity> oppList=new List<Opportunity>();
   
   public void CreateOpportunity(List<Account> accList)
   {
     for(Account a:accList)
     {
       Opportunity o = new Opportunity();
       o.AccountID=a.ID;
       
       o.Name=a.Name;
       o.CloseDate=System.Today().addDays(3);
       
       o.StageName='Prospecting';
       
       oppList.add(o);
     }
     
     if (oppList.size() > 0)
         Database.Insert(oppList);
   }
}

trigger trg_createnewoppor on Account (after Insert,after update)
{
  if ((Trigger.isInsert) || (Trigger.IsBefore))
  {
    CreateNewOpportunity o = new CreateNewOpportunity();
    o.CreateOpportunity(Trigger.New);
  }
}


Thanks
smita
trigger trigger52 on India__c (after insert) {
  list<san_francisco__c> con =new list<san_francisco__c>();  

    for(India__c h : trigger.new){
     san_francisco__c s = new san_francisco__c();
      s.Name=h.Name;
        s.Company__c=h.Company__c;
        s.Mobile__c=h.Mobile__c;
           s.Email__c=h.Email__c;
        con.add(s);
        
        
    }
    insert con;
}
hi,
   scenario is implement rollup summary to a lookup relationship
   i have taken account---parent
                        contact---child
  my code is______ 
public class triggeronContact

    public list<id> accidlist{get; set;}
   
    public triggeroncontact(){
       
     accidlist = new list<id>();
 
    }
    public void Trigconmeth(list<contact> connew)
    {
       
        if(trigger.isinsert || trigger.isundelete)
        {
            for(contact con : connew)
            {   
                if(con.AccountId != null)  {
                accidlist.add(con.accountid);
                system.debug('*****accidlist are*****:'+accidlist);               
            }
        }
        }
        if(trigger.isdelete)
        {
            for(contact condel : [select id from contact] )
            {
                accidlist.add(condel.accountid);
               
            }
        }
        list<account> accupdatelist = new list<account>();
       
        for(account acc : [select total_contacts__c,(select id from contacts)from account where id =: accidlist])
        {
            acc.total_contacts__c = acc.contacts.size();
            accupdatelist.add(acc);
        }
        try
        {
            update accupdatelist;
        }  
        catch(exception e)
        {
            system.debug('Exception:'+e.getMessage());
        }
    }      
}
while executing below error is coming...line number 13 means  here...  if(trigger.isinsert || trigger.isundelete)
 User-added image
Hello
I am new to writing test class. I need help in writing test class for the following code.
scenairo: when I create a new account from UI, a nee opportunity record gets created under the account.
public class CreateNewOpportunity
{
   public List<Opportunity> oppList=new List<Opportunity>();
   
   public void CreateOpportunity(List<Account> accList)
   {
     for(Account a:accList)
     {
       Opportunity o = new Opportunity();
       o.AccountID=a.ID;
       
       o.Name=a.Name;
       o.CloseDate=System.Today().addDays(3);
       
       o.StageName='Prospecting';
       
       oppList.add(o);
     }
     
     if (oppList.size() > 0)
         Database.Insert(oppList);
   }
}

trigger trg_createnewoppor on Account (after Insert,after update)
{
  if ((Trigger.isInsert) || (Trigger.IsBefore))
  {
    CreateNewOpportunity o = new CreateNewOpportunity();
    o.CreateOpportunity(Trigger.New);
  }
}


Thanks
smita
I keep failing the Syntax Check for my Lead_Quality_Helper.  

IF(ISBLANK(Company), 0, 1)+ 
IF(ISBLANK(Title), 0, 1)+ 
IF(ISBLANK(Email), 0, 1)+ 
IF(ISBLANK(Phone), 0, 1)+ 
IF(ISPICKVAL(Industry,""), 0, 1)

i'm getting the error  Error: Formula result is data type (Number), incompatible with expected data type (true or false).

and if I change it to false, true 
I get this error: 
 Error: Incorrect parameter type for operator '+'. Expected Number, Date, DateTime, received Boolean. 

IF(ISBLANK(Company), false, true)+ 
IF(ISBLANK(Title), false, true)+ 
IF(ISBLANK(Email), false, true)+ 
IF(ISBLANK(Phone), false, true)+ 
IF(ISPICKVAL(Industry,""), false, true)


Am I missing something?  Any help is greatly appreciated.  Thanks! 
Does anyone have any pointer for tweaking this section?​
User-added image
How can I retake a challenge in Trailhead?  I thought I was able to this before.  I am in one of my Trailhead playgrounds.

Thanks,
Steve
trigger trigger52 on India__c (after insert) {
  list<san_francisco__c> con =new list<san_francisco__c>();  

    for(India__c h : trigger.new){
     san_francisco__c s = new san_francisco__c();
      s.Name=h.Name;
        s.Company__c=h.Company__c;
        s.Mobile__c=h.Mobile__c;
           s.Email__c=h.Email__c;
        con.add(s);
        
        
    }
    insert con;
}
I am new to Visualforce and I am doing the Trailhead: Visualforce Basics Module - Use Standard Controllers.  The instructions state:
To preview your page in the context of Lightning Experience, open your browser’s developer console and enter:
$A.get("e.force:navigateToURL").setParams(
    {"url": "/apex/pageName"}).fire();
I am not sure where to enter this.  When I enter it in the Visualforce page the text just show up on the Visualforce page preview.  I must be missing something.  Any help will be greatly appreciated.
 

am writing a code, where i need to compare the name which contains some specific letters. what is the syntax for it?

 

Account acc;

(if acc.Name Contains 'ABC')

{

}

 

 

  • January 20, 2011
  • Like
  • 0

Is there any way to create a full screen experience for my visualforce page while still being hosted on Salesforce? I don't want to migrate the front end to my site unless I have to.

trigger trigger52 on India__c (after insert) {
  list<san_francisco__c> con =new list<san_francisco__c>();  

    for(India__c h : trigger.new){
     san_francisco__c s = new san_francisco__c();
      s.Name=h.Name;
        s.Company__c=h.Company__c;
        s.Mobile__c=h.Mobile__c;
           s.Email__c=h.Email__c;
        con.add(s);
        
        
    }
    insert con;
}