• SFDC Dev 2269
  • NEWBIE
  • 48 Points
  • Member since 2018

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 6
    Replies
global class Batch_contact_delete implements Database.Batchable<sobject> {
    global Database.QueryLocator start(Database.BatchableContext bc){
        string query='Select LastName,CreatedDate,AccountId,Account.Id from Contact where CreatedDate=LAST_MONTH';
        return Database.getQueryLocator(query);
    }
    global Void execute(Database.BatchableContext bc,List<contact> conList){
        delete conlist;
    }
    global void finish(Database.BatchableContext bc){
         system.debug('****************Start Finish********************');
    }
}
-------------------
Test Class
--------------------
@isTest
private class Batch_contact_delete_Test_Class {
	@isTest
    static void delConAcc(){
        Account a = new Account();
        a.Name='Raju';
        Insert a;
        Contact c = new contact();
        c.LastName='Ravi';
        c.AccountId=a.id;
        insert c;
        Test.startTest();
        	Batch_contact_delete bd = new Batch_contact_delete();
        	Id JobId = Database.executeBatch(bd,10);
        Test.stopTest();        
        Integer count = [Select count() from Contact where accountId=:a.id];
        System.assertEquals(0, count);
    }
}

I am getting Code covarage as 66% only. Is there any issue with Test class 
Actually this is my apex class for addition of 2 numbers 
public class Addition         //define class
{
  public integer a=5;        //define variables
  public integer b=4;
  public integer c;

  public integer add()               //define function or method
  {
  c=a+b;
  system.debug('the result is '+c);
        return c;
  }
}// end of class


My Test class
----------------
@isTest
public class Additiontest
{
    static testmethod void testadd()
    {
     integer a=5;
     integer b=7;
     integer c=12;
     system.assertEquals(12,12); 
    }  
    
}

and when executing the test class it is showing as pass...

Please need help on this....thanks
I have a requirement to download a word document from VF page. I am facing some issues with CSS of the page. Below is the code snippet:
<apex:page showHeader="true" sidebar="true" StandardController="Application__c"
    cache="true" extensions="DownloadApplication_Ctrl" contentType="application/msword#DownloadWord.doc">
    <html xmlns:w="urn:schemas-microsoft-com:office:word">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <head>
        <style type="text/css">
                .fontFamily {
                    font-family: Source Sans Pro;
                }
                .alignCenter {
                    text-align: center;
                }
                .fontWeightBold {
                    font-weight: Bold;
                    font-family: Source Sans Pro;
                }
                .formHeader {
                    font-size: 20px;
                    color: #000000;
                    text-align: center;
                }
                .width50 {
                    width: 50%;
                }
                .width100 {
                    width: 100%;
                }
            </style>
        <body>
            <div class="fontFamily">
                <div class="formHeader">
                    <apex:outputText escape="false" value="Your application goes here" />
                </div> <br/>
                <div class="width100">
                    <span class="width50">
                        <apex:outputText styleClass="fontWeightBold" escape="false"
                            value="Submitted Date:" />
                        <apex:outputText value="{0,date,MM'/'dd'/'yyyy}">
                            <apex:param value="{!application.Submitted_Date__c}" />
                        </apex:outputText>
                    </span>
                    <span class="width50">
                        <apex:outputText styleClass="fontWeightBold" escape="false"
                            value="Application Number:" />
                        <apex:outputText value="{!application.Name}" />
                    </span><br/>
                </div>
              </div>
          </body>
    </html>
</apex:page>
In the above code the width50 and width100 classes are not applied in the downloaded Word document.
What is the correct way to apply css in these word documents?
Thanks!
I have a requirement to download a word document from VF page. I am facing some issues with CSS of the page. Below is the code snippet:
<apex:page showHeader="true" sidebar="true" StandardController="Application__c"
    cache="true" extensions="DownloadApplication_Ctrl" contentType="application/msword#DownloadWord.doc">
    <html xmlns:w="urn:schemas-microsoft-com:office:word">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <head>
        <style type="text/css">
                .fontFamily {
                    font-family: Source Sans Pro;
                }
                .alignCenter {
                    text-align: center;
                }
                .fontWeightBold {
                    font-weight: Bold;
                    font-family: Source Sans Pro;
                }
                .formHeader {
                    font-size: 20px;
                    color: #000000;
                    text-align: center;
                }
                .width50 {
                    width: 50%;
                }
                .width100 {
                    width: 100%;
                }
            </style>
        <body>
            <div class="fontFamily">
                <div class="formHeader">
                    <apex:outputText escape="false" value="Your application goes here" />
                </div> <br/>
                <div class="width100">
                    <span class="width50">
                        <apex:outputText styleClass="fontWeightBold" escape="false"
                            value="Submitted Date:" />
                        <apex:outputText value="{0,date,MM'/'dd'/'yyyy}">
                            <apex:param value="{!application.Submitted_Date__c}" />
                        </apex:outputText>
                    </span>
                    <span class="width50">
                        <apex:outputText styleClass="fontWeightBold" escape="false"
                            value="Application Number:" />
                        <apex:outputText value="{!application.Name}" />
                    </span><br/>
                </div>
              </div>
          </body>
    </html>
</apex:page>
In the above code the width50 and width100 classes are not applied in the downloaded Word document.
What is the correct way to apply css in these word documents?
Thanks!
I have an apex trigger that runs on an object that is 3 levels down in a master detail hierarchy. I'm starting to write a test class for the trigger but need to set up the test data for the test methods. Due to the complexity of requiring a parent and grandparent in place before creating the actual records being tested I figured I would use a utility class.

Having investigated various onine resources I can see lots of examples of using a utility class to create a single type of object record and have that returned as an array which can be processed in the test class but I'm not sure how you deal with multiple levels of relationship and different object types if you need to access both the parent and grandparent records from the test methods as they are both required.

As an example:

Firstly create in Utility Class
Grandparent Record (Custom Object A)
  ->    Parent Record (Custom Object B)

Then the following is created in the test Class methods but needs to access both objects created above
     ->   Detail Record test 1 (Custom Object C) (Child of Object B which is child of Object A)
     ->   Detail Record test 2 (Custom Object C) (Child of Object B which is child of Object A)
     ->   Detail Record test 3 (Custom Object C) (Child of Object B which is child of Object A)

I may be over thinking this, any advice, examples or tips appreciated!

 
global class Batch_contact_delete implements Database.Batchable<sobject> {
    global Database.QueryLocator start(Database.BatchableContext bc){
        string query='Select LastName,CreatedDate,AccountId,Account.Id from Contact where CreatedDate=LAST_MONTH';
        return Database.getQueryLocator(query);
    }
    global Void execute(Database.BatchableContext bc,List<contact> conList){
        delete conlist;
    }
    global void finish(Database.BatchableContext bc){
         system.debug('****************Start Finish********************');
    }
}
-------------------
Test Class
--------------------
@isTest
private class Batch_contact_delete_Test_Class {
	@isTest
    static void delConAcc(){
        Account a = new Account();
        a.Name='Raju';
        Insert a;
        Contact c = new contact();
        c.LastName='Ravi';
        c.AccountId=a.id;
        insert c;
        Test.startTest();
        	Batch_contact_delete bd = new Batch_contact_delete();
        	Id JobId = Database.executeBatch(bd,10);
        Test.stopTest();        
        Integer count = [Select count() from Contact where accountId=:a.id];
        System.assertEquals(0, count);
    }
}

I am getting Code covarage as 66% only. Is there any issue with Test class 
Actually this is my apex class for addition of 2 numbers 
public class Addition         //define class
{
  public integer a=5;        //define variables
  public integer b=4;
  public integer c;

  public integer add()               //define function or method
  {
  c=a+b;
  system.debug('the result is '+c);
        return c;
  }
}// end of class


My Test class
----------------
@isTest
public class Additiontest
{
    static testmethod void testadd()
    {
     integer a=5;
     integer b=7;
     integer c=12;
     system.assertEquals(12,12); 
    }  
    
}

and when executing the test class it is showing as pass...

Please need help on this....thanks
I added the below lines of code for upsert operation to record the duplicate record set.But I face compile time error .Please note that the dmloptions work for database.insert and database.update.Please help
Lines of Code:
Database.DMLOptions dml1 = new Database.DMLOptions();
  dml1.DuplicateRuleHeader.AllowSave = true;
  Database.upsert(lstOfEqup1, dml1);

Error message :
Method does not exist or incorrect signature: void upsert(List<Account>, Database.DMLOptions) from the type Database