• Sumanth Meenavol
  • NEWBIE
  • 5 Points
  • Member since 2017
  • Salesforce Consultant

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Hi all, 

I have a problem with this challenge :

Create a Queueable Apex class that inserts the same Contact for each Account for a specific state. Write unit tests that achieve 100% code coverage for the class.
Create an Apex class called 'AddPrimaryContact' that implements the Queueable interface.
Create a constructor for the class that accepts as its first argument a Contact sObject and a second argument as a string for the State abbreviation.
The execute method must query for a maximum of 200 Accounts with the BillingState specified by the State abbreviation passed into the constructor and insert the Contact sObject record associated to each Account. Look at the sObject clone() method.
Create an Apex test class called 'AddPrimaryContactTest'.
In the test class, insert 50 Account records for BillingState "NY" and 50 Account records for BillingState "CA". Create an instance of the AddPrimaryContact class, enqueue the job and assert that a Contact record was inserted for each of the 50 Accounts with the BillingState of "CA".
The unit tests must cover all lines of code included in the AddPrimaryContact class, resulting in 100% code coverage.
Run your test class at least once (via 'Run All' tests the Developer Console) before attempting to verify this challenge.


I haven't 100% for my test class. 
 
@isTest
 public class AddPrimaryContactTest {
   
   
     @isTest static void TestList(){
         List<Account> Teste = new List <Account>();
         for(Integer i=0;i<50;i++){
             
             Teste.add(new Account(BillingState = 'CA', name = 'Test'+i));
         }
             for(Integer j=0;j<50;j++){
             
             Teste.add(new Account(BillingState = 'NY', name = 'Test'+j));
         
         }
         insert Teste;
         Contact co = new Contact();
          String state = 'CA';
     AddPrimaryContact apc = new AddPrimaryContact(co, state);
	Test.startTest();
	System.enqueueJob(apc);
     Test.stopTest();
         for (Account t:Teste){
             if( t.BillingState == 'CA'){
               	  
             	System.assertEquals(1, t.Number_of_contacts__c);
            
             
         }
         }      
}
 }
 
public class AddPrimaryContact implements Queueable{
    private Contact c;
    private String state;
    public  AddPrimaryContact(Contact c, String state){
        this.c = c;
        this.state = state;
        
    }
     public void execute(QueueableContext context) {
        List<Account> ListAccount = [SELECT ID, Name FROM ACCOUNT WHERE BillingState = :state LIMIT 200];
         for (Account l:ListAccount){
             for (Contact co:l.Contacts){
                 
                 c = co.clone(false,false,false,false);
                 insert c;
             }
                 
                 
             }
             
         }

}


Anyone can help me please?
Thanks!
Hi,
     I am using XML Spread sheet code in visual force page which contains Multisheets,there is a requirement i should put color for cell based on condition,For ex:if cell contains 10% the put RED color,Ifit contains 20% then put BLUE color.But i din get the approach to put condition in Visualforce page.I tried to achieve this taking an example program that i have written below,

<apex:page controller="ExcelControllerCheck2" contentType="txt/xml#myTest.xls" cache="true">
<apex:outputText value="{!xlsHeader}"/>  

<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
    xmlns:o="urn:schemas-microsoft-com:office:office"
    xmlns:x="urn:schemas-microsoft-com:office:excel"
     xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
    xmlns:html="http://www.w3.org/TR/REC-html40"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">   
  <Styles>
   <Style ss:ID="s1">
   <Alignment/>
   <Borders/>
   <Font ss:Bold="1" ss:Color="RED"/>
   <Interior ss:Pattern='Solid' ss:Color="#B8B8B8"/>
    <NumberFormat/>
    <Protection/>
  </Style>
    
   <Style ss:ID="s2">
   <Alignment/>
   <Borders/>
   <Font ss:Color="BLUE"/> 
    <NumberFormat/>
    <Protection/>
   </Style>
     
    
     <!--
     <Style ss:ID="s2">
   <Alignment/>
   <Borders/>
   <Font ss:Bold="1" />

   <Interior ss:Color="Gray75"/>
    <NumberFormat/>
    <Protection/>
     </Style>
     -->
   </Styles>
   
<Worksheet ss:Name="Accounts">
  <Table x:FullColumns="1" x:FullRows="1">
  <Column ss:Width="170"/>
  <Row>
<Cell ss:StyleID="s1"><Data ss:Type="String" >Account Name</Data></Cell>
</Row>
  <apex:repeat value="{!accountList}" var="account">
  <Row>
<Cell><Data ss:Type="String">{!account.name}</Data></Cell>
</Row>
</apex:repeat>
</Table>
</Worksheet>

<Worksheet ss:Name="Contacts">

<WorksheetOptions
xmlns="urn:schemas-microsoft-com:office:excel">
<Selected/>
<FreezePanes/>
<FrozenNoSplit/>

<!--- Right-most column number of left pane. --->
<SplitVertical>1</SplitVertical>
<SplitVertical>2</SplitVertical>
<!---
Offset column of right frame. This is not the actual
column number of the overall Excel document, but rather
the index of the available column for this pane. This
number cannot exclude columns, it can merely set the
offset scroll of this pane. (1) scrolls to the left of
the frame (first column).
--->
<LeftColumnRightPane>1</LeftColumnRightPane>
<LeftColumnRightPane>2</LeftColumnRightPane>
</WorksheetOptions>

<Table x:FullColumns="1" x:FullRows="1">
  <Column ss:Width="170"/>
  <Column ss:Width="280"/>
  <Column ss:Width="330"/>
  <Column ss:Width="550" />
  <Row>
  <Cell ss:StyleID="s1"><Data ss:Type="String">Contact Name</Data></Cell>
   <Cell ss:StyleID="s1"><Data ss:Type="String" >Last Name</Data></Cell>
   <Cell ss:StyleID="s1"><Data ss:Type="String" >Account Name</Data></Cell>
   <Cell ss:StyleID="s1" ><Data ss:Type="String" >Created Date</Data></Cell>
  </Row>
  <apex:repeat value="{!contactList}" var="contact">
  <Row>
  <Cell ss:StyleID="s2"><Data ss:Type="String">{!contact.name}</Data></Cell>
<Cell><Data ss:Type="String">{!contact.lastName}</Data></Cell>
  <Cell><Data ss:Type="String">{!contact.account.name}</Data></Cell>
   <Cell><Data ss:Type="String"><apex:outputText value=" {0,date,M/d/yyy, h:mm a}">
    <apex:param value="{!contact.CreatedDate}" />
</apex:outputText></Data></Cell>
   </Row>
</apex:repeat>
</Table>

</Worksheet>
</Workbook>

</apex:page>



And also  i need to put color for <Worksheet ss:Name="Account"> .Please if anyone knows post the answer,It will help a lot.

Thanks.