• Malli G
  • NEWBIE
  • 20 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 19
    Questions
  • 13
    Replies
Hi All 
Please help me out i got only 50%  code coverage for this controller class

Here my controller class
Here my code:
public class Partner_For_Account {
    public list<Partner_For_Account__c>partners{set;get;}
    public string partnerAccountid{set;get;}
    private final Account acct;
    public integer rowno{set;get;}
    public list<Partner_For_Account__c> PartnerAccount { get; set; }
    public id Accountid;
     //string id= Apexpages.currentPage().getparameters().get('id');
    public Partner_For_Account(Apexpages.standardcontroller controller){
        Accountid=controller.getid();
         System.debug('Accountid'+Accountid);
        system.debug('partnerAccountid'+partnerAccountid);
        partners=new list<Partner_For_Account__c>();
       PartnerAccount = new list<Partner_For_Account__c>();
        Partner_For_Account__c p=new Partner_For_Account__c();
        p.Account__c=Accountid;
       
      partners.add(p);
        system.debug('partners'+partners);
       
        system.debug('Name'+'Malli');
        
         PartnerAccount =[select id,Partner__c,Partner_Manager__c,Partner_Segment__c,Partner_Sales_Person__c ,Account__c from Partner_For_Account__c where Account__c =:Accountid];
        
    }
    public void addrow(){
        partners.add(new Partner_For_Account__c(Account__c=Accountid));
    }
     public void deleterow(){
        rowno=integer.valueOf(apexpages.currentPage().getparameters().get('index'));
        partners.remove(rowno);
    }
    public void savepartner(){
        insert partners;
        partners=new list<Partner_For_Account__c>();
         Partner_For_Account__c p=new Partner_For_Account__c();
        p.Account__c=Accountid;
       
      partners.add(p);
      refreshing();
    }
    public void deletepartnerAccount()
    {
        system.debug('partnerAccountid'+partnerAccountid);
        Partner_For_Account__c PartnerAccounts=[select Partner__c,Partner_Manager__c,Partner_Segment__c,Partner_Sales_Person__c ,Account__c from Partner_For_Account__c  where id=:partnerAccountid];
        delete PartnerAccounts;
 refreshing();
    }
    
    public void refreshing(){
          PartnerAccount =[select Partner__c,Partner_Manager__c,Partner_Segment__c,Partner_Sales_Person__c ,Account__c from Partner_For_Account__c where Account__c =:Accountid];
    }
}
 
whenever we create a record in any object that record will be visible to to the custom object record using apex code or anyway

please letme know how we can do that
Hai Hall please help me get a code coverage
trigger afterundeletethecontact on Contact (After undelete) {
    list<Account>acc=new list<Account>();
    for(contact c:trigger.new)
    {
       
        Account a=new Account();
        a.id=c.AccountId;
        a.name=c.lastname;
        a.phone=c.phone;
    acc.add(a);
        
    
        
    }
    update acc;

}
testclass
@istest
public class Afterundeletecontacttest {
@istest
    static void testme(){
        Account a1=new Account(name='jjjj',phone='9999');
            insert a1;
        contact c=new contact(lastname='SSS',phone='1111',Accountid=a1.id);
        insert c;
        
        contact cf=[select lastname,phone from contact where id=:c.id];
        delete cf;
        contact ce=new contact(lastname='SSS',phone='1111',Accountid=a1.id);
        insert ce;
        Account af=[select id,name,phone from account where id=:a1.id];
        af.id=ce.AccountId;
        af.name=ce.lastname;
        af.phone=ce.phone;
        update af;
        system.assertEquals(af.id,ce.AccountId);
        system.assertEquals(af.name,ce.lastname);
        system.assertEquals(af.phone,ce.phone);
        
    }
}
 
Hai hall  i wrote my trigger code & test class  i dont get code coverage. please help me
trigger activeopportunity on Motor_Insurance__c (after insert) {
list<id>listid=new list<id>();
    for(Motor_Insurance__c c:trigger.new){
        if(c.status__c==true){
            listid.add(c.Opportunity__c);
        }
    }
    list<opportunity>opps=[select id,customerproject__c from opportunity where id in:listid];
    for(opportunity o:opps){
        o.customerproject__c=true;
    }
    update opps;
}

testclass
@istest
public class activeopportunitytest {
@istest
    static void testme(){
        opportunity op1=new opportunity();
        op1.name='AAA';
        op1.StageName='Qualification';
        op1.CloseDate=system.today();
        op1.customerproject__c=false;
        insert op1;
         Motor_Insurance__c  mot=new  Motor_Insurance__c ();
        mot.Opportunity__c=op1.id;
        mot.No_of_Terms__c=3;
        mot.Premium_Amount__c=1000;
        mot.status__c=true;
       insert mot;
        //boolean customerpro=true;
        opportunity opps=[select id,stagename,closedate,name,
                           customerproject__c from opportunity where id=:op1.id];
        //opps.customerproject__c=customerpro;
        //update opps;
    system.assertEquals(true, opps.customerproject__c);
        
    }
}
 
hai hall
i have two customobjects  one is the payment and next one is the customer , both having lookuprelation ,payment having a total 10 records out of 10 , 6 records having one owner and 4 records having another user .if i deacivate the customer owner records,which is having more than 5records on payment object records owner will be  populate to the customer objects records note:payment is the parent customer is the child
hai hall
i have two customobjects  one is the payment and next one is the customer , both having lookuprelation ,payment having a total 10 records out of 10 , 6 records having one owner and 4 records having another user .if i deacivate the customer owner records,which is having more than 5records on payment object records owner will be  populate to the customer objects records
hai hall
we know incase  of masterdetailrelationship if delete the parentrecords child will also deleted
i have  a requirement if i delete the account record account will be deleted but  i dont want to delete the contacts records in case of masterdetailrelationship please can any one helpme
hai all 
on vfpage i have 4 inputcheckbox, if i selected checkbox 1 add to integer and then display the selected seat is 1 and if i selected checkbox 3 add to integer and then display the selected seat is 3  Iwant display the statically or dynamically
i wrote the code
it will count the noof seats
public class adds {
    public integer count{set;get;}
    public boolean book1{set;get;}
     public boolean book2{set;get;}
     public boolean book3{set;get;}
     public boolean book4{set;get;}
    public boolean book5{set;get;}
    public integer index{set;get;}
    public adds(){
      
        count=0;
    }
    public  void add1(){
        if(book1==true){
            count=count+1;
          index=1;
        }else if(book2==true){
            count=count+1;
            index=2;
        }else if(book3==true){
            count=count+1;
           
        }else if(book4==true){
            count=count+1;
        }else if(book5==true){
            count=count+1;
        }
    }
}
vfpage
<apex:page controller="adds" >
    <apex:form >
     <apex:pageblock id="one">
         <apex:inputCheckbox value="{!book1}">
             <apex:actionsupport event="onchange" action="{!add1}" rerender="one"/>
         </apex:inputCheckbox>&nbsp;&nbsp;
         <apex:inputCheckbox value="{!book2}"><apex:actionsupport event="onchange" action="{!add1}" rerender="one"/>
         </apex:inputCheckbox>&nbsp;&nbsp;
         <apex:inputCheckbox value="{!book3}"><apex:actionsupport event="onchange" action="{!add1}" rerender="one"/>
         </apex:inputCheckbox>&nbsp;&nbsp;&nbsp;
          <apex:inputCheckbox value="{!book4}"><apex:actionsupport event="onchange" action="{!add1}" rerender="one"/>
         </apex:inputCheckbox>&nbsp;&nbsp;
          <apex:inputCheckbox value="{!book5}"><apex:actionsupport event="onchange" action="{!add1}" rerender="one"/>
         </apex:inputCheckbox>&nbsp;&nbsp;
          
         {!count} selected seats{!index}
        </apex:pageblock>
    </apex:form>
</apex:page>

 
hai all
 when i am trying to insert a new record if it is already existing database it throws an error ,but i want those Errors wil be come on csv file ,can we do this on trigger give me some example
when we want disable all the validationrules for a specific user on all the sobjects how we can achieve this give me some examples
and how to deactivate the triggers for a specific user
hai all 
i need a write dynamically add a pagelayouts to the profile through apex code using vfpage also
how can i do that
hai all
before delete the account record we cannot delete the opportunity  as well delete account record
I wrote this code
 i am getting error Attempts to de reference to null object


public class sample2 {

    public List<AggregateResult> Result {get;set;}    
    public List<Summary> SummaryList {get;set;}
    public List<Account> AcctList;
    public Map<Id, Account> IdAccount;
    List<Id> Ids;
    
    public void show() {
        SummaryList = new List<Summary>();
        Result = new List<AggregateResult>();
        Ids = new List<Id>();
        AcctList = new List<Account>();
        IdAccount = new Map<Id, Account>();
        
        Result = [SELECT Count(Id) Total , AccountId FROM Contact GROUP BY AccountId];               
        
        for(AggregateResult a : Result) {   
            Ids.add((Id)a.get('AccountId'));
        }
        
        AcctList = [SELECT Name FROM Account WHERE Id IN : Ids];
        
        System.debug('Account List' + AcctList);
        
        for(Account a : AcctList) {
            IdAccount.put(a.Id, a);            
        }
        
        System.debug('Ids and Accounts are ' + IdAccount);
                
        for(AggregateResult a : Result) {
            Account TempAcct = new Account();            
            tempacct= IdAccount.get((Id)(a.get('AccountId')));
          
            system.debug('Account Name is ' + TempAcct.acctName);
            SummaryList.add(new summary(a));                
        }    
    }
    
    public class Summary {
        public Integer Total {get;set;}
        public string AcctName {get;set;}
        
        public Summary(AggregateResult a, string AccountName) {
            Total =  (Integer)a.get('Total');
            AcctName = AccountName;
        }
    }

}
hello
I need to to find records for each and every user ,and find who had the highest record count then the user is owner of the remaining records.
haiiiii

trigger opportunity on Account (after insert,after update) {
list<opportunity>oops=new list<opportunity>();
    for(account a:trigger.new){
        if(a.industry=='electronics'){
         opportunity op=new opportunity(); 
            op.name=a.name;
           op.accountid=a.id;
          op.stagename='proposal';
           op.closedate=system.today()+30;
            op.amount=1000;
            op.description=a.description;
            oops.add(op);
            
        }
    }
    if(oops.isEmpty()==false){
        database.upsert(oops);
    }
   
}
i need to write a testclass for this trigger



trigger example5 on Lead (after insert) {
    Integer total;
    List<Contact> contacts=new List<Contact>();
    for(Lead l:Trigger.New){
        total=0;
        if(l.firstName!=null && l.firstname!='')
            total=total+10;
        if(l.phone!=null && l.phone!='')
            total=total+10;
        if(l.email!=null && l.email!='')
            total=total+10;
        if(total>=20){
            Contact c=new Contact();
            c.lastname=l.lastname;
            c.firstName=l.firstName;
            c.phone=l.phone;
            c.Email=l.email;
            c.ownerId=l.ownerId;
            contacts.add(c);
        }
    }
    insert contacts;
}
i wrote this code;

trigger contactstrigger on Contact (after insert,after delete) {
  if(Trigger.isInsert && Trigger.isAfter)
        TriggerContact.increment(Trigger.New);
    else
        TriggerContact.increment(Trigger.Old);

public class TriggerContact {
    public static void increment(List<Contact> cons){
        set<Id> accid=new Set<id>();
        for(Contact c:cons){
           accId.add(c.AccountId); 
        }
       List<Account> accs=[select id,count_of_contact__c ,(select id from Contacts ) from Account where id in:accId];
        for(Account a:accs){
            a.count_of_contact__c=a.contacts.size();
        }
        update accs;
    }

}

testclass for this code
istest
public class testforcontact {
@istest
    static void testme(){
        account a1=new account(name='aaa',phone='9908294936');
insert a1;
contact c1=new contact(lastname='suresh', firstname='malli',accountid=a1.id);
insert c1;    
        
        list<account>acc=[select id,count_of_contact__c,(select id,lastname from contacts) from account where id=:c1.id];
        for(account a:acc){
            a.count_of_contact__c=a.contacts.size();
        }
        update acc;
    }
}










 
i have an account and contact object, if i didn't select "Account lookup" in "contact", after saving the record i want to display a string value in place of "account name"  in detail page using triggers.
hai all 
on vfpage i have 4 inputcheckbox, if i selected checkbox 1 add to integer and then display the selected seat is 1 and if i selected checkbox 3 add to integer and then display the selected seat is 3  Iwant display the statically or dynamically
i wrote the code
it will count the noof seats
public class adds {
    public integer count{set;get;}
    public boolean book1{set;get;}
     public boolean book2{set;get;}
     public boolean book3{set;get;}
     public boolean book4{set;get;}
    public boolean book5{set;get;}
    public integer index{set;get;}
    public adds(){
      
        count=0;
    }
    public  void add1(){
        if(book1==true){
            count=count+1;
          index=1;
        }else if(book2==true){
            count=count+1;
            index=2;
        }else if(book3==true){
            count=count+1;
           
        }else if(book4==true){
            count=count+1;
        }else if(book5==true){
            count=count+1;
        }
    }
}
vfpage
<apex:page controller="adds" >
    <apex:form >
     <apex:pageblock id="one">
         <apex:inputCheckbox value="{!book1}">
             <apex:actionsupport event="onchange" action="{!add1}" rerender="one"/>
         </apex:inputCheckbox>&nbsp;&nbsp;
         <apex:inputCheckbox value="{!book2}"><apex:actionsupport event="onchange" action="{!add1}" rerender="one"/>
         </apex:inputCheckbox>&nbsp;&nbsp;
         <apex:inputCheckbox value="{!book3}"><apex:actionsupport event="onchange" action="{!add1}" rerender="one"/>
         </apex:inputCheckbox>&nbsp;&nbsp;&nbsp;
          <apex:inputCheckbox value="{!book4}"><apex:actionsupport event="onchange" action="{!add1}" rerender="one"/>
         </apex:inputCheckbox>&nbsp;&nbsp;
          <apex:inputCheckbox value="{!book5}"><apex:actionsupport event="onchange" action="{!add1}" rerender="one"/>
         </apex:inputCheckbox>&nbsp;&nbsp;
          
         {!count} selected seats{!index}
        </apex:pageblock>
    </apex:form>
</apex:page>

 
whenever we create a record in any object that record will be visible to to the custom object record using apex code or anyway

please letme know how we can do that
Hai Hall please help me get a code coverage
trigger afterundeletethecontact on Contact (After undelete) {
    list<Account>acc=new list<Account>();
    for(contact c:trigger.new)
    {
       
        Account a=new Account();
        a.id=c.AccountId;
        a.name=c.lastname;
        a.phone=c.phone;
    acc.add(a);
        
    
        
    }
    update acc;

}
testclass
@istest
public class Afterundeletecontacttest {
@istest
    static void testme(){
        Account a1=new Account(name='jjjj',phone='9999');
            insert a1;
        contact c=new contact(lastname='SSS',phone='1111',Accountid=a1.id);
        insert c;
        
        contact cf=[select lastname,phone from contact where id=:c.id];
        delete cf;
        contact ce=new contact(lastname='SSS',phone='1111',Accountid=a1.id);
        insert ce;
        Account af=[select id,name,phone from account where id=:a1.id];
        af.id=ce.AccountId;
        af.name=ce.lastname;
        af.phone=ce.phone;
        update af;
        system.assertEquals(af.id,ce.AccountId);
        system.assertEquals(af.name,ce.lastname);
        system.assertEquals(af.phone,ce.phone);
        
    }
}
 
Hai hall  i wrote my trigger code & test class  i dont get code coverage. please help me
trigger activeopportunity on Motor_Insurance__c (after insert) {
list<id>listid=new list<id>();
    for(Motor_Insurance__c c:trigger.new){
        if(c.status__c==true){
            listid.add(c.Opportunity__c);
        }
    }
    list<opportunity>opps=[select id,customerproject__c from opportunity where id in:listid];
    for(opportunity o:opps){
        o.customerproject__c=true;
    }
    update opps;
}

testclass
@istest
public class activeopportunitytest {
@istest
    static void testme(){
        opportunity op1=new opportunity();
        op1.name='AAA';
        op1.StageName='Qualification';
        op1.CloseDate=system.today();
        op1.customerproject__c=false;
        insert op1;
         Motor_Insurance__c  mot=new  Motor_Insurance__c ();
        mot.Opportunity__c=op1.id;
        mot.No_of_Terms__c=3;
        mot.Premium_Amount__c=1000;
        mot.status__c=true;
       insert mot;
        //boolean customerpro=true;
        opportunity opps=[select id,stagename,closedate,name,
                           customerproject__c from opportunity where id=:op1.id];
        //opps.customerproject__c=customerpro;
        //update opps;
    system.assertEquals(true, opps.customerproject__c);
        
    }
}
 
hai hall
we know incase  of masterdetailrelationship if delete the parentrecords child will also deleted
i have  a requirement if i delete the account record account will be deleted but  i dont want to delete the contacts records in case of masterdetailrelationship please can any one helpme
hai all
 when i am trying to insert a new record if it is already existing database it throws an error ,but i want those Errors wil be come on csv file ,can we do this on trigger give me some example
I wrote this code
 i am getting error Attempts to de reference to null object


public class sample2 {

    public List<AggregateResult> Result {get;set;}    
    public List<Summary> SummaryList {get;set;}
    public List<Account> AcctList;
    public Map<Id, Account> IdAccount;
    List<Id> Ids;
    
    public void show() {
        SummaryList = new List<Summary>();
        Result = new List<AggregateResult>();
        Ids = new List<Id>();
        AcctList = new List<Account>();
        IdAccount = new Map<Id, Account>();
        
        Result = [SELECT Count(Id) Total , AccountId FROM Contact GROUP BY AccountId];               
        
        for(AggregateResult a : Result) {   
            Ids.add((Id)a.get('AccountId'));
        }
        
        AcctList = [SELECT Name FROM Account WHERE Id IN : Ids];
        
        System.debug('Account List' + AcctList);
        
        for(Account a : AcctList) {
            IdAccount.put(a.Id, a);            
        }
        
        System.debug('Ids and Accounts are ' + IdAccount);
                
        for(AggregateResult a : Result) {
            Account TempAcct = new Account();            
            tempacct= IdAccount.get((Id)(a.get('AccountId')));
          
            system.debug('Account Name is ' + TempAcct.acctName);
            SummaryList.add(new summary(a));                
        }    
    }
    
    public class Summary {
        public Integer Total {get;set;}
        public string AcctName {get;set;}
        
        public Summary(AggregateResult a, string AccountName) {
            Total =  (Integer)a.get('Total');
            AcctName = AccountName;
        }
    }

}
haiiiii

trigger opportunity on Account (after insert,after update) {
list<opportunity>oops=new list<opportunity>();
    for(account a:trigger.new){
        if(a.industry=='electronics'){
         opportunity op=new opportunity(); 
            op.name=a.name;
           op.accountid=a.id;
          op.stagename='proposal';
           op.closedate=system.today()+30;
            op.amount=1000;
            op.description=a.description;
            oops.add(op);
            
        }
    }
    if(oops.isEmpty()==false){
        database.upsert(oops);
    }
   
}
i wrote this code;

trigger contactstrigger on Contact (after insert,after delete) {
  if(Trigger.isInsert && Trigger.isAfter)
        TriggerContact.increment(Trigger.New);
    else
        TriggerContact.increment(Trigger.Old);

public class TriggerContact {
    public static void increment(List<Contact> cons){
        set<Id> accid=new Set<id>();
        for(Contact c:cons){
           accId.add(c.AccountId); 
        }
       List<Account> accs=[select id,count_of_contact__c ,(select id from Contacts ) from Account where id in:accId];
        for(Account a:accs){
            a.count_of_contact__c=a.contacts.size();
        }
        update accs;
    }

}

testclass for this code
istest
public class testforcontact {
@istest
    static void testme(){
        account a1=new account(name='aaa',phone='9908294936');
insert a1;
contact c1=new contact(lastname='suresh', firstname='malli',accountid=a1.id);
insert c1;    
        
        list<account>acc=[select id,count_of_contact__c,(select id,lastname from contacts) from account where id=:c1.id];
        for(account a:acc){
            a.count_of_contact__c=a.contacts.size();
        }
        update acc;
    }
}










 

I need to export a report as a CSV to an FTP site or email it on a daily or weekly basis.

 

I have a Report.  I need to get the report out of Salesforce somehow into CSV format.

 

Ideally, this would be scheduled.


I'm a developer so I can do developer stuff.  However, I don't know APEX and I don't know VisualForce.  I can get someone to do that stuff if we need to.


Thanks!

  • July 26, 2011
  • Like
  • 2