• mallikhajuna gunda
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 0
    Replies
HI
i am new to salesforce

i am getting only 50% code coverage only
please write the test class for this 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];
    }
}
 
Hi All
please write   the  test class , i am not getting the full code coverage
Here my code:
public class AppsL_AppointmentDetails {
    
    @auraEnabled
    public static  list<Appointment_c__c >  getAppointmentdetials(){  
       user u=[select id,name,contactid from user where id=:userinfo.getUserId()];
        //user u=[select id,name,contactid from user where id='0057A000001Wlky'];
        system.debug('========u.contactId '+u.contactid);
        list< Appointment_c__c> Appointment=[select id,Appointed_With__c,StartDateTime__c,Doctor_Appointed__c,Contact_First_Name__r.FirstName  from Appointment_c__c where First__c =:u.contactid];
        system.debug('==========Appointment '+Appointment);
        return Appointment;
    }
    @Auraenabled
    public static string getname(){
        string patientname;
         user u=[select id,name,contactid from user where id=:userinfo.getUserId()];
      // user u=[select id,name,contactid from user where id='0057A000001Wlky'];
        contact c=[select id,name from contact where id=:u.contactid];
        patientname=c.name;
        return patientname;
    }
    
      @Auraenabled
    public static string getdoctornames(){
        string docNames;
         user u=[select id,name,contactid from user where id=:userinfo.getUserId()];
        //user u=[select id,name,contactid from user where id='0057A000001Wlky'];
        list<id>eventids=new list<id>();
        list<id>eventrelationids=new list<id>();
       list<event> e=[select id,whoid from event where  whoid=:u.ContactId];
        for(event e1:e){
         eventids.add(e1.id);
                       } 
        system.debug('eventids'+eventids);
        
        //RelationID specify the  user (doctor) and contact
       
       list<eventrelation>everelation=[select id,relationid from eventrelation where eventid in:eventids];
        
        for(eventrelation es:everelation){
            eventrelationids.add(es.relationid);
        }
        system.debug('eventrelationids'+eventrelationids);
       list<user>username=[select id,username,firstname,lastname from user where id in:eventrelationids];
        for(user ue:username){
            docNames=ue.firstname;
        }
        system.debug('DocNames'+docNames);
        return docNames;
    }
    
    @Auraenabled
    public  static list<string> getnames(){
        list<string>names=new list<string>{'Alnylam_Support','Insurance_Support','Patient_Advocate'};
            return names;
    }
    @Auraenabled
    public static string getpiclistvalues( string picvalues){
        string pic=picvalues;
        system.debug('%%%%%%%%%%%%%pic%%%%%%%%'+pic);
        return pic;
    }
    
}
Hi hall,

if i click on the existing records,i need to edit the  records.
please do i needful urgently
here i am poste the my code:

Apex controller::
public class SaveRecord_Lightning {
    @AuraEnabled
    public static list<Account>getAllRecords(){
        return [select id,name,AccountNumber from Account];
    }
    
    @AuraEnabled
    public static Account SaveRecord(Account RecordDetail){
        upsert RecordDetail;
        
        Return RecordDetail;
    }
}

saverecord.cmp:
<aura:component controller="SaveRecord_Lightning" >
    <aura:attribute name="RecordDetails" type="Account[]"/>
    <ltng:require styles="resource/slds235"/>
    <!--<aura:handler name="init" value="{!this}" action="{!c.doinit}"/>-->
    <!--setting the default value-->
    <aura:attribute name="newrecordDetails" type="Account" default="{'sobjectType':'Account','Name':'',
                                                                    'AccountNumber':''}"/>
    
    <!--inputform using component-->
    <div class="slds-align--absolute-center">
    <div class="EmpName">
        
    <div class="container">
      <form class="slds-form--stacked">
          <div class="slds-form-element slds-is-required">
              <div class="slds-form-element__control">
       <ui:inputText aura:id="EmpName" value="{!v.newrecordDetails.Name}" label="Name" class="slds-input"  labelclass="slds-form-element__label" required="true"/>
                               
              </div>
          </div>
        <div class="slds-form-element__control">
       <ui:inputText aura:id="EmMobile" value="{!v.newrecordDetails.AccountNumber}" label="Account Number" class="slds-input"  labelclass="slds-form-element__label" required="true"/>
         </div>
          <div class="slds-form-element">
              <ui:button label="submit" buttontype="submit" class="slds-button slds-neutral" labelclass="label" press="{!c.createRecord}"/>
          </div>
          <div class="slds-form-element">
              <ui:button  label="View" press="{!c.doinit}" />
          </div>
        </form>
    </div>
    </div>
    </div>
    <!--End of the Inputform-->
    <!--Data table-->
    
    <table class="slds-table slds-table--bordered slds-table--cell-buffer" style="width:800px">
  <thead>
    <tr class="slds-text-title--caps">
      <th>
               <span class="slds-truncate" title="Name">Name</span>      
            </th>
      <th>
               <span class="slds-truncate" title="AccountNumber">AccountNumber</span>      
            </th>
      
      </tr>
  </thead>
  <tbody>
      <aura:iteration items="{!v.RecordDetails}" var="c">
    <tr>
      
      <td scope="row">
                  <div class="slds-truncate" title="{!c.Name}"><a>{!c.Name}</a></div>
               </td>
      <td scope="row">
          <div class="slds-truncate" title="{!c.AccountNumber}"><a>{!c.AccountNumber}</a></div>
               </td>
      
    </tr>
    </aura:iteration>
  </tbody>
</table>
</aura:component>

controller js

({
    doinit : function(component, event, helper) {
        helper.getAllRecords(component);
    },
    createRecord:function(component, event, helper) {
        var newrecordDetails=component.get("v.newrecordDetails");
        helper.createRecord(component,newrecordDetails);
    },
    
    Edit:function(component, event, helper) {
        
    }
})

Helper js:
({
    getAllRecords : function(component) {
        
        var action = component.get("c.getAllRecords");
        action.setCallback(this,function(a){
                var state = a.getState();
            if (component.isValid() && state === "SUCCESS") {
                var result = a.getReturnValue();
               component.set("v.RecordDetails",result);
            }
            });
$A.enqueueAction(action);
             
    },
    
    createRecord : function(component,RecordDetail){
        this.upsertrecord(component,RecordDetail, function(response){
            var RecordDetails=component.get("v.RecordDetails");
            var newrecordDetails=component.get("v.newrecordDetails");
            RecordDetails.push(response.getReturnValue());
            component.set("v.RecordDetails",RecordDetails);
            var records={'sobjectType':'Account','Name':'','AccountNumber':''};
                component.set("v.newrecordDetails",records);
                  
            
        });
    },
    
    upsertrecord : function(component,Record,callback){
        var action=component.get("c.SaveRecord");
          action.setParams({ "RecordDetail" : Record});
        if(callback){
            action.setCallback (this,callback);
                
            
        }
      $A.enqueueAction(action); 
        
    }
    
})





 
HI
i am new to salesforce

i am getting only 50% code coverage only
please write the test class for this 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];
    }
}