• bonny mankotia
  • NEWBIE
  • 40 Points
  • Member since 2014
  • AnalogForce

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 14
    Questions
  • 11
    Replies
I have a piece of code that show above error on

d.FolderId = UserInfo.getUserId();
         d.Name = 'Data2'; 
         String myContent = this.name+ '\n ' +this.pass+ '\n ' + this.age+ '\n ' +this.mail; 
         d.body += Blob.valueof(mycontent);
         d.ContentType = 'text/plain';
         d.Type = 'txt';
         upsert d;
         return null;
}

d.body += Blob.valueof(mycontent);(Show error in this line)
Hi i have Custom Visualforce page "Registration" on which whenever i insert the record through page its create new file in Document object and enter the record values on that file I need a functionality that insert the record in same file instead of creating a new file whenever user create a new record TIA

public with sharing class Registration {
public string name{get;set;}
public string pass{get;set;}
public string age{get;set;}
public string mail{get;set;}
public Registration(String name,string pass,string age,string mail) {
this.name = name;
this.pass = pass;
this.age = age;
this.mail = mail; }
public Registration() { }
public pagereference save() { return null; }
public PageReference reset() {
PageReference newpage = new PageReference(System.currentPageReference().getURL());
newpage.getParameters().clear();
newpage.setRedirect(true); return newpage; }
public PageReference Store() {
Document d = new Document();
d.FolderId = UserInfo.getUserId();
d.Name = 'Data2';
String myContent = this.name+ '\n ' +this.pass+ '\n ' + this.age+ '\n ' +this.mail;
d.body= Blob.valueof(mycontent);
d.ContentType = 'text/plain';
d.Type = 'txt'; insert d;
return null; } }
public with sharing class AssertEx 
{
    
    public integer sum()
    {
         integer a =10;
            integer b =20;
         integer c;
         c=a+b;
         system.debug('======'+c);
         //system.assert();
         //system.assertequals();
         //System.assertNotEquals();
         return c;
    }
}
User-added image
Not able to cover the else block.Below is the test Class

@isTest
public class TestConTrigg 
{
    static testmethod void testFun()
    {
        account acc = new account();
        acc.name ='less';
        insert acc;
        
        contact con = new contact();
        con.lastname = 'ram';
        con.password__c = 'sdaf';
        con.Accountid = acc.Id;
        insert con;
        
        account acc1 = new account();
        acc1.name ='less';
        insert acc1;
        
        contact con1 = new contact();
        con1.Accountid = acc1.Id;
        con1.account.name = con1.lastname = ' ';
        con1.password__c = 'sdaqwe';
        update con1;
    }    
}
Here is the Code.

public class actionFunctionController {
    public Account acc{get;set;}
    public Boolean showPhone{get;set;}
 
    public actionFunctionController(){
        acc = new Account();
        showPhone = false;
    }
 
    public PageReference priorityChanged(){
        if(acc.CustomerPriority__c == 'High'){
            showPhone = true;
        }
        else
        {
            showPhone = false;
        }
        return null;
    }
}
trigger ClosedOpportunityTrigger on Opportunity (before insert) 
{    
    list<task> carry = new list<task>();
    for(opportunity opp: trigger.new)
    {
        if(opp.StageName == 'Closed Won')
        {
           task t = new task(whatid=opp.id,Subject = 'Follow Up Test Task');
            carry.add(t); 
        }
   }
     insert carry;
}

Here is my test class

@isTest
public class TestOppTrig 
{
    static testmethod void testFun()
    {
        Opportunity opp = new opportunity();
        opp.Name = 'Bob';
        opp.StageName = 'closed won';
        opp.CloseDate = system.today();
        insert opp;
        task t = new task();
        t.whatid=opp.id;
        t.subject = 'dasfsdfds';
        insert t;
    }
}
I use simple jquery code in vf page but its not work please help.

<apex:page standardController="Account" tabStyle="Account" sidebar="false">
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
        <script>
            $(document).ready(function()
            {
                 $("#Button").click(function()
                 {
                      $("#nm").hide();
                 });
           });
        </script>
    </head>
     
     <apex:form >   
     <apex:pageBlock title="Jquery Ex">
         <apex:outputText value="{!account.name}" label="NAME" id="nm"/>
        <apex:pageBlockButtons >
                <apex:commandButton id="Button" value="Jquery"/>
            </apex:pageBlockButtons>
     </apex:pageBlock>
     </apex:form>
</apex:page>

This is my code.
I need a code coverage of catch block of this class.
public class AccountHandler {

    public static Account insertNewAccount (String accName){
        
        
    if(accName!=''){    
        try{
            Account a = new Account(Name=accName);
            insert a;
            System.debug('Bravo Andrè! Account created');
            return a;
        } catch(Exception e){
            System.Debug('Account not created');
            return null;
        }
    } else {
        return null;
    }
    }    
}

This is my test class.

@isTest
public class accounthandlerTest 
{
static testMethod void accounthandlerTest()
{
   /*account a = new account();
   a.Name='bonsy';
   insert a;*/
   //system.assert(a.id!= null,'The Test Account did not insert properly, please check validation rules and other mechanisms');
   AccountHandler.insertNewAccount('bonsy'); 
    AccountHandler.insertNewAccount('');       
 }
}
Hello Guys I need a Test Class for Below Class Please help me.

public with sharing class Accountcontactpicklist 
{
    public String selectedAccId{get;set;}
    public String selectedConId{get;set;}
      
          public List<SelectOption> getAccountNames()
           {
                  List<SelectOption> accOptions= new List<SelectOption>();
                  accOptions.add( new SelectOption('','--Select--'));
                  for( Account acc : [select Id,name from Account where name like '[abc]%' limit 5 ] ) 
                  {
                          accOptions.add( new SelectOption(acc.Id,acc.name));
                  }
                 
                 return accOptions;
           }
         
           public List<SelectOption> getContactNames() 
           {
                  
                  List<SelectOption> conOptions= new List<SelectOption>();
                  List<SelectOption> options = new List<SelectOption>();
                    if(selectedAccId != null)
                    {     
                       for( contact con : [select Id,name,accountid from contact where accountid=:selectedAccId ] ) 
                       {
                          conOptions.add( new SelectOption(con.Id,con.name));
                       }
                    }                  
                    else
                    {
                        conOptions.add( new SelectOption('--None--','--None--'));
                    }
                 return conOptions;
           }
    }
Hello guys.I have this simple trigger i need to compare old and new values for this trigger and if its not match then update the phone field.Can somebody sort out this problem with code?

trigger SameobjTrg on Contact (before insert) 
{
    for(contact con:trigger.new)
    {
        con.MobilePhone = '9816175515';
      }
}
Hello guys.I have this simple trigger i need to compare old and new values for this trigger and if its not match then update the phone field.Can somebody sort out this problem with code?

trigger SameobjTrg on Contact (before insert) 
{
    for(contact con:trigger.new)
    {
        con.MobilePhone = '98765436523';
      }
}
Hello Guys.I have the following code its show an error Line: 16, Column: 1System.NullPointerException: Attempt to de-reference a null object.I want to know the reason behind this error.Is this not proper way to declare and initiliaze object like this way please help me.

public with sharing class MapExampleTwo 
{
    public void display()
    {
        account acc4;
        acc4.name = 'Peter';
        account acc5;
        acc5.name = 'corey';
        account acc = new account();
       acc.name = 'bonny';
       account acc1 = new account();
       acc1.name = 'bonsy';
       account acc3 = new account(name = 'bonson');
       map<integer,account>map1 = new map<integer,account>{0 => acc,1 => acc1,2 => acc3};
       system.debug('The first index is' + map1.get(0));
       system.debug('====='+map1.keyset());
       system.debug('===='+map1.values());
   }
}
I just want to know what is the difference between these two statements.

1) list acc = new list([select id,name,Site from account limit 5]);

2)list acc4 = [select id,name,Site from account limit 10];

Both gave the same output.
rigger OppOnAccount on Account(after insert,after update) 
{
    if(trigger.isinsert)
    {
      list<opportunity> Listopp  = new list<opportunity>();
        for(account acc:Trigger.new)
        {
            opportunity opp = new opportunity();
            opp.name = acc.name;
            opp.AccountId = acc.id;
            opp.StageName = 'Proposal';
            opp.CloseDate= system.today()+10;
            Listopp.add(opp);
        }
        
            insert Listopp;
     }   
I have a piece of code that show above error on

d.FolderId = UserInfo.getUserId();
         d.Name = 'Data2'; 
         String myContent = this.name+ '\n ' +this.pass+ '\n ' + this.age+ '\n ' +this.mail; 
         d.body += Blob.valueof(mycontent);
         d.ContentType = 'text/plain';
         d.Type = 'txt';
         upsert d;
         return null;
}

d.body += Blob.valueof(mycontent);(Show error in this line)
public with sharing class AssertEx 
{
    
    public integer sum()
    {
         integer a =10;
            integer b =20;
         integer c;
         c=a+b;
         system.debug('======'+c);
         //system.assert();
         //system.assertequals();
         //System.assertNotEquals();
         return c;
    }
}
Here is the Code.

public class actionFunctionController {
    public Account acc{get;set;}
    public Boolean showPhone{get;set;}
 
    public actionFunctionController(){
        acc = new Account();
        showPhone = false;
    }
 
    public PageReference priorityChanged(){
        if(acc.CustomerPriority__c == 'High'){
            showPhone = true;
        }
        else
        {
            showPhone = false;
        }
        return null;
    }
}
Hello Guys I need a Test Class for Below Class Please help me.

public with sharing class Accountcontactpicklist 
{
    public String selectedAccId{get;set;}
    public String selectedConId{get;set;}
      
          public List<SelectOption> getAccountNames()
           {
                  List<SelectOption> accOptions= new List<SelectOption>();
                  accOptions.add( new SelectOption('','--Select--'));
                  for( Account acc : [select Id,name from Account where name like '[abc]%' limit 5 ] ) 
                  {
                          accOptions.add( new SelectOption(acc.Id,acc.name));
                  }
                 
                 return accOptions;
           }
         
           public List<SelectOption> getContactNames() 
           {
                  
                  List<SelectOption> conOptions= new List<SelectOption>();
                  List<SelectOption> options = new List<SelectOption>();
                    if(selectedAccId != null)
                    {     
                       for( contact con : [select Id,name,accountid from contact where accountid=:selectedAccId ] ) 
                       {
                          conOptions.add( new SelectOption(con.Id,con.name));
                       }
                    }                  
                    else
                    {
                        conOptions.add( new SelectOption('--None--','--None--'));
                    }
                 return conOptions;
           }
    }
Hello guys.I have this simple trigger i need to compare old and new values for this trigger and if its not match then update the phone field.Can somebody sort out this problem with code?

trigger SameobjTrg on Contact (before insert) 
{
    for(contact con:trigger.new)
    {
        con.MobilePhone = '9816175515';
      }
}
Hello guys.I have this simple trigger i need to compare old and new values for this trigger and if its not match then update the phone field.Can somebody sort out this problem with code?

trigger SameobjTrg on Contact (before insert) 
{
    for(contact con:trigger.new)
    {
        con.MobilePhone = '98765436523';
      }
}
rigger OppOnAccount on Account(after insert,after update) 
{
    if(trigger.isinsert)
    {
      list<opportunity> Listopp  = new list<opportunity>();
        for(account acc:Trigger.new)
        {
            opportunity opp = new opportunity();
            opp.name = acc.name;
            opp.AccountId = acc.id;
            opp.StageName = 'Proposal';
            opp.CloseDate= system.today()+10;
            Listopp.add(opp);
        }
        
            insert Listopp;
     }