• Janet Epebinu
  • NEWBIE
  • 75 Points
  • Member since 2016

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 12
    Replies
Hi all. I v\have a problem with my component.
I'm using lightning datatable with enabled in line editing to edit prices for products. Datatable definition looks like this:
<lightning:datatable
keyField="Id"
aura:id="table"
data="{!v.discountCodeItems}"
columns="{!v.columns}"
hideCheckboxColumn="true"
defaultSortDirection="asc"
draftValues="{!v.draftValues}"
oncellchange="{!c.handleCellChange}"
showRowNumberColumn="false"
isLoading="{!v.isLoading}"
wrapTextMaxLines="10"
onsave="{!c.handleSave}"/>
Columns definition:
component.set("v.columns",[
            {label : 'Product Name', fieldName : 'linkName', type : 'url',typeAttributes : {label : {fieldName : 'Name'}}},
            {label : 'Sales Price', fieldName : 'Sales_Price__c', type : 'currency', typeAttributes: { currencyCode: 'NOK'}, editable: true},
            {label : 'List Price', fieldName : 'List_Price__c',type : 'currency'},
            {label : 'Discount', fieldName : 'Discount', type : 'text'}
        ]);
I read changed value using:
var draftValues = event.getParam('draftValues');
and send it from component to Apex.
Te problem is when I change price from 24.00 to 24.89 JS controller sends:
[{"Sales_Price__c":"24.89","Id":"a699E000000Mc0JQAS"}]
but Apex receives
{Id=a699E000000Mc0JQAS, Sales_Price__c=2489.00}
If I change price back to 24 (without decimal part), Apex receives 24.
Do you know why it happens?
Hi All,
          I have a controller and I wrote its test class. it's not covering some part.
My controller is given below:-
 
public without sharing class MatchMakingController {
    private ApexPages.StandardController sctrl;
    rie__Registration__c regObj;
    public Map<String, List<SelectOption>> questionsMap {get;set;}
    private Map<String, String> questionAnswerMap;
    public Map<String, rie__Question__c> questionsSet {get;set;}
    public String Selectedvalues {get;set;}
    public String answeredQuestion{get; set;}
    
    public MatchMakingController(ApexPages.StandardController st){
        this.sctrl = st;
        this.regObj = (rie__Registration__c) st.getRecord();
        questionAnswerMap = new Map<String, String>();
        
    }
  
     public void populateAnswers()
    {
        questionAnswerMap.put(answeredQuestion.trim(), Selectedvalues.trim());
        System.debug('***'+questionAnswerMap);
        Selectedvalues=Null;
    }
    
    public pageReference submitAnswers(){
        List<rie__Registrant_Answer__c> existingRegAnswersList = new List<rie__Registrant_Answer__c>([Select id, rie__Question__c,
                                                                                                     rie__Answer__c, rie__Registration__c
                                                                                                     from rie__Registrant_Answer__c
                                                                                                     where rie__Registration__c =: regObj.Id]);
        Map<String, rie__Registrant_Answer__c> existingRegAnswersMap = new Map<String, rie__Registrant_Answer__c>();
        if(existingRegAnswersList != Null && existingRegAnswersList.size() > 0){
            for(rie__Registrant_Answer__c regAnswers : existingRegAnswersList){
                existingRegAnswersMap.put(regAnswers.rie__Question__c, regAnswers);
            }
        }
        system.debug('questionAnswerMap---->'+questionAnswerMap);
        List<rie__Registrant_Answer__c> regAnswerList = new List<rie__Registrant_Answer__c>();
        if(questionAnswerMap != Null && questionAnswerMap.size() > 0){
            for(String question : questionAnswerMap.keySet()){
                if(question != Null && question != 'None' &&
                   questionAnswerMap.get(question) != Null && 
                   questionAnswerMap.get(question) != 'None'){
                       if(existingRegAnswersMap != Null && 
                          existingRegAnswersMap.size() > 0 && 
                          existingRegAnswersMap.containsKey(question)){
                              rie__Registrant_Answer__c regAnswer = new rie__Registrant_Answer__c(Id = existingRegAnswersMap.get(question).Id);
                              regAnswer.rie__Question__c = questionsSet.get(question).Id;
                              regAnswer.rie__Answer__c = questionAnswerMap.get(question);
                              regAnswer.rie__Registration__c = regObj.Id;
                              regAnswerList.add(regAnswer); 
                          }else{
                              rie__Registrant_Answer__c regAnswer = new rie__Registrant_Answer__c();
                              regAnswer.rie__Question__c = questionsSet.get(question).Id;
                              regAnswer.rie__Answer__c = questionAnswerMap.get(question);
                              regAnswer.rie__Registration__c = regObj.Id;
                              regAnswerList.add(regAnswer);  
                          }
                       
                       
                   }
            }
        }
        if(regAnswerList != Null && regAnswerList.size() > 0){
            insert regAnswerList;
        }
        Selectedvalues=Null;
        PageReference cancel = sctrl.cancel(); 
        return cancel;
    }
    
    public pageReference cancel(){
       PageReference cancel = sctrl.cancel(); 
       return cancel; 
    }
}

Test class is given below:-
@istest
private class MatchMakingControllerTest {
   
    Static testmethod void MatchMakingMethod(){
           String txt = 'THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG';
         rie__Event__c evt = new rie__Event__c();
        evt.rie__Event_Time_Zone__c = '(GMT-07:00) Pacific Daylight Time (America/Los_Angeles)';
        insert evt;
        
        rie__Registration__c attendee = new rie__Registration__c();
        attendee.rie__BatchProcessedForMatchMaking__c = false;
        attendee.rie__Event__c = evt.id;
        insert attendee;
        
        rie__Question__c qus = new rie__Question__c();
        qus.rie__Question__c  = 'Are you looking for a Solution?';
        qus.rie__Answers__c = 'ans,yes';
        insert qus;
        
        rie__Registrant_Answer__c regAns =  new rie__Registrant_Answer__c();
        regAns.rie__Question__c = qus.id;
        regAns.rie__Registration__c =  attendee.id;
        regAns.rie__Answer__c = 'yes';
        insert regAns;
        
        test.startTest();
        PageReference pageRef  = Page.MatchMakingQuestions; 
        pageRef.getParameters().put('Id', regAns.id);
        Test.setCurrentPage(pageRef);
        Registration__c reg = new Registration__c();
        Apexpages.StandardController sc = new Apexpages.standardController(reg);
        
        // Instantiate the extension
        MatchMakingController ext = new MatchMakingController(sc);
        ext.answeredQuestion = txt;
        //ext.populateAnswers();
        PageReference testPageResults = ext.cancel();
        PageReference testPageResult = ext.getQuestionsList();
        PageReference testPageRe = ext.submitAnswers();
        test.stoptest();
        
    }
}
how can I cover bold lines in my test class?
Can anyone help me with this?
​​​​​​​
Hi,

I have below values in a string

String s1 = ' __valuesE-123456yes__'
String s2 = '__values2E-234567fail__'

I need to fetch only the values starting from 'E- to the next 6 digit values from the strings
Ouptut should be like : E-123456
E-234567

Can you please let me know how to achieve this?

Thanks
Hi all. I v\have a problem with my component.
I'm using lightning datatable with enabled in line editing to edit prices for products. Datatable definition looks like this:
<lightning:datatable
keyField="Id"
aura:id="table"
data="{!v.discountCodeItems}"
columns="{!v.columns}"
hideCheckboxColumn="true"
defaultSortDirection="asc"
draftValues="{!v.draftValues}"
oncellchange="{!c.handleCellChange}"
showRowNumberColumn="false"
isLoading="{!v.isLoading}"
wrapTextMaxLines="10"
onsave="{!c.handleSave}"/>
Columns definition:
component.set("v.columns",[
            {label : 'Product Name', fieldName : 'linkName', type : 'url',typeAttributes : {label : {fieldName : 'Name'}}},
            {label : 'Sales Price', fieldName : 'Sales_Price__c', type : 'currency', typeAttributes: { currencyCode: 'NOK'}, editable: true},
            {label : 'List Price', fieldName : 'List_Price__c',type : 'currency'},
            {label : 'Discount', fieldName : 'Discount', type : 'text'}
        ]);
I read changed value using:
var draftValues = event.getParam('draftValues');
and send it from component to Apex.
Te problem is when I change price from 24.00 to 24.89 JS controller sends:
[{"Sales_Price__c":"24.89","Id":"a699E000000Mc0JQAS"}]
but Apex receives
{Id=a699E000000Mc0JQAS, Sales_Price__c=2489.00}
If I change price back to 24 (without decimal part), Apex receives 24.
Do you know why it happens?
Hi, I am new to Apex

I have copied an example trigger code, however I get the error message 'Variable does not exist: addError'.
All it does is prevent deletion of an orphan contact with a custom error msg.
Can you tell me what I am doing wrong?

trigger ContactBeforeDelete on Contact (before delete)
{
    for(Contact c:trigger.old)
    {
        if(c.accountId==null)
        {
            c.addError=('You are not authorised to delete this contact.');
        }
    }
}

public class ShareholderCompanyTriggerHandler {
    
    public static final Integer MAXIMUM_PERCENTAGE_OF_OWNERSHIP = 100;
    
    public static final String ERROR_MESSAGE_FOR_PERCENTAGE = 'Total Shareholding Percentage cannot be greater than 100% for this application.';
    
    public static ID ShareholderCompanyRecTypeId = RecordTypeHelper.getIdByDeveloperName(
                                                   Consts.Shareholder.getDevName(),
                                                   Consts.Shareholder.RecordTypes.Shareholder_Company);    
    
    //methods invocation for after event on Insert operation
    public static void onAfterInsert(List<Shareholder_Company__c> shareholderList) {
        validatePercentageOfOwnershipField(shareholderList);
    }
    
    //methods invocation for after event on Update operation
    public static void onAfterUpdate(Map<Id,Shareholder_Company__c> oldShareHolderMap, Map<Id,Shareholder_Company__c> newShareHolderMap) {
        validatePercentageOfOwnershipField(oldShareHolderMap,newShareHolderMap);
    }
    

    //method for checking overall percentage of ownership on application object
    //related to it's child object contact and shareholdercompany
    //count all contact records and shareholder company records of shareholder recordtype
    //on insertion of shareholder company object record
    //display error if overall percentage beyond 100%
    private static void validatePercentageOfOwnershipField(List<Shareholder_Company__c> shareholderList) {
                
        Set<ID> applicationIDSet = new Set<ID>();
        for(Shareholder_Company__c company : shareholderList) {
            if(company.RecordTypeId == ShareholderCompanyRecTypeId && company.Percentage_of_Ownership__c != null) {
                applicationIDSet.add(company.Application__c);
            }
        }
        
        Decimal AggregatePercentageOfOwnerShip;
        AggregatePercentageOfOwnerShip = TriggerHandlerUtil.getAllContactsAndShareHolderCompanyRecordsFromApplicationRecord(ApplicationIdSet);
        for(Shareholder_Company__c company : shareholderList) {
            if(AggregatePercentageOfOwnerShip > MAXIMUM_PERCENTAGE_OF_OWNERSHIP) {
                try {
                      company.Percentage_of_Ownership__c.addError(ERROR_MESSAGE_FOR_PERCENTAGE);
                    }
                catch(Exception e) {}
            }
        }
    }
    

    //method for checking overall percentage of ownership on application object
    //related to it's child object contact and shareholdercompany
    //count all contact records and shareholder company records of shareholder recordtype
    //on updation of shareholder company object record
    //display error if overall percentage beyond 100%
    private static void validatePercentageOfOwnershipField(Map<Id,Shareholder_Company__c> oldShareHolderMap, Map<Id,Shareholder_Company__c> newShareHolderMap) {      
        List<Shareholder_Company__c> shareholderList = newShareHolderMap.values();
        Set<ID> ApplicationIDSet = new Set<ID>();
        for(Shareholder_Company__c company : shareholderList) {
            if(
                (company.RecordTypeId == ShareholderCompanyRecTypeId && company.Percentage_of_Ownership__c != null) &&
                (
                    (company.Percentage_of_Ownership__c != oldShareHolderMap.get(company.Id).Percentage_of_Ownership__c) || 
                    (company.Application__c != oldShareHolderMap.get(company.Id).Application__c)
                )
            ) {
                ApplicationIDSet.add(company.Application__c);
              }
        }
        
        Decimal AggregatePercentageOfOwnerShip;
        AggregatePercentageOfOwnerShip = TriggerHandlerUtil.getAllContactsAndShareHolderCompanyRecordsFromApplicationRecord(ApplicationIdSet);
        for(Shareholder_Company__c company : shareholderList) {
            if(AggregatePercentageOfOwnerShip > MAXIMUM_PERCENTAGE_OF_OWNERSHIP) {
                try {
                      company.Percentage_of_Ownership__c.addError(ERROR_MESSAGE_FOR_PERCENTAGE);
                    }
                catch(Exception e) {}
            }
        }
    }
}
=====================================================

//test class for shareholdercompanytriggerhandler class

@IsTest
public class ShareholderCompanyTriggerHandler_Test {
    
    @IsTest
    private static void test_shareholdercompanyPercentage() {
        Consts.Contact_RecordTypes contactRTs = new Consts.Contact_RecordTypes();
        String contactRT = RecordTypeHelper.getIdByDeveloperName('Contact', contactRTs.Acquiring);
        
        Application__c application = TestUtil.createTestApp2();
        if(Application!= null){
            insert application;///////Error in this line 
        }
        system.debug('Application:::::::::'+application);
        //Creating Contact records
        List<Contact> contactsToInsert = new List<Contact>();
        for(Integer i=0; i<10; i++){
            Contact contact1 = new Contact(
                accountcontact__c = true,
                PassportNumber__c = '12345678qwertyuiop',
                PassportExpirationDate__c = Date.today() + 100,
                LastName = 'Test1',
                Nationality__c = 'Indian',
                MobilePhone = '97121333131',
                RecordTypeId = contactRT);            
            Integer randomNumber = Integer.valueof((math.random() * 10));
            if(randomNumber<3)
                Contact1.PercentageOfOwnership__c = 10;
            else if(randomNumber > 3 && randomNumber <=5)
                Contact1.PercentageOfOwnership__c = 30;
            else if(randomNumber > 5 && randomNumber <=8)
                Contact1.PercentageOfOwnership__c = 20;
            else 
                Contact1.PercentageOfOwnership__c = 130;
            contactsToInsert.add(contact1);            
        }  
        Database.insert (contactsToInsert,false);
        for(Contact contact: [Select id,PercentageOfOwnership__c From Contact WHERE PercentageOfOwnership__c!= null ]){
            system.debug('Percentage:::::::::'+contact.PercentageOfOwnership__c);
            System.AssertEquals(true,contact.PercentageOfOwnership__c<100);
        }
        //Creating Shareholder records
        List<Shareholder_Company__c> shareholderCompanyToInsert = new List<Shareholder_Company__c>();        
        Id ShareHolderComRecordTypeId = RecordTypeHelper.getIdByDeveloperName(Consts.Shareholder.getDevName(), Consts.Shareholder.RecordTypes.Shareholder_Company);
        for(Integer j=0; j<10;j++){
            Shareholder_Company__c shareholder1 = new Shareholder_Company__c();
            shareholder1.RecordTypeId = ShareHolderComRecordTypeId;
            Integer randomNumber = Integer.valueof((math.random() * 10));
            if(randomNumber<3)
                shareholder1.Percentage_of_Ownership__c = 10;
            else if(randomNumber > 3 && randomNumber <=5)
                shareholder1.Percentage_of_Ownership__c = 30;
            else if(randomNumber > 5 && randomNumber <=8)
                shareholder1.Percentage_of_Ownership__c = 20;
            else 
                shareholder1.Percentage_of_Ownership__c = 130;
            shareholder1.Trade_License_number__c = '4824';
            shareholder1.Name = 'test shareholder company';
            shareholder1.Date_of_Establishment__c = Date.today() - 20;
            shareholder1.Country_of_Establishment__c = 'United Arab Emirates';
            shareholderCompanyToInsert.add(shareholder1);
        }         
        Database.insert (shareholderCompanyToInsert,false);
        for(Shareholder_Company__c shareholder: [Select id,Percentage_of_Ownership__c From Shareholder_Company__c WHERE Percentage_of_Ownership__c!= null ]){
            System.AssertEquals(true,shareholder.Percentage_of_Ownership__c<100);
        }
    }
    
}
 
Hi All,
          I have a controller and I wrote its test class. it's not covering some part.
My controller is given below:-
 
public without sharing class MatchMakingController {
    private ApexPages.StandardController sctrl;
    rie__Registration__c regObj;
    public Map<String, List<SelectOption>> questionsMap {get;set;}
    private Map<String, String> questionAnswerMap;
    public Map<String, rie__Question__c> questionsSet {get;set;}
    public String Selectedvalues {get;set;}
    public String answeredQuestion{get; set;}
    
    public MatchMakingController(ApexPages.StandardController st){
        this.sctrl = st;
        this.regObj = (rie__Registration__c) st.getRecord();
        questionAnswerMap = new Map<String, String>();
        
    }
  
     public void populateAnswers()
    {
        questionAnswerMap.put(answeredQuestion.trim(), Selectedvalues.trim());
        System.debug('***'+questionAnswerMap);
        Selectedvalues=Null;
    }
    
    public pageReference submitAnswers(){
        List<rie__Registrant_Answer__c> existingRegAnswersList = new List<rie__Registrant_Answer__c>([Select id, rie__Question__c,
                                                                                                     rie__Answer__c, rie__Registration__c
                                                                                                     from rie__Registrant_Answer__c
                                                                                                     where rie__Registration__c =: regObj.Id]);
        Map<String, rie__Registrant_Answer__c> existingRegAnswersMap = new Map<String, rie__Registrant_Answer__c>();
        if(existingRegAnswersList != Null && existingRegAnswersList.size() > 0){
            for(rie__Registrant_Answer__c regAnswers : existingRegAnswersList){
                existingRegAnswersMap.put(regAnswers.rie__Question__c, regAnswers);
            }
        }
        system.debug('questionAnswerMap---->'+questionAnswerMap);
        List<rie__Registrant_Answer__c> regAnswerList = new List<rie__Registrant_Answer__c>();
        if(questionAnswerMap != Null && questionAnswerMap.size() > 0){
            for(String question : questionAnswerMap.keySet()){
                if(question != Null && question != 'None' &&
                   questionAnswerMap.get(question) != Null && 
                   questionAnswerMap.get(question) != 'None'){
                       if(existingRegAnswersMap != Null && 
                          existingRegAnswersMap.size() > 0 && 
                          existingRegAnswersMap.containsKey(question)){
                              rie__Registrant_Answer__c regAnswer = new rie__Registrant_Answer__c(Id = existingRegAnswersMap.get(question).Id);
                              regAnswer.rie__Question__c = questionsSet.get(question).Id;
                              regAnswer.rie__Answer__c = questionAnswerMap.get(question);
                              regAnswer.rie__Registration__c = regObj.Id;
                              regAnswerList.add(regAnswer); 
                          }else{
                              rie__Registrant_Answer__c regAnswer = new rie__Registrant_Answer__c();
                              regAnswer.rie__Question__c = questionsSet.get(question).Id;
                              regAnswer.rie__Answer__c = questionAnswerMap.get(question);
                              regAnswer.rie__Registration__c = regObj.Id;
                              regAnswerList.add(regAnswer);  
                          }
                       
                       
                   }
            }
        }
        if(regAnswerList != Null && regAnswerList.size() > 0){
            insert regAnswerList;
        }
        Selectedvalues=Null;
        PageReference cancel = sctrl.cancel(); 
        return cancel;
    }
    
    public pageReference cancel(){
       PageReference cancel = sctrl.cancel(); 
       return cancel; 
    }
}

Test class is given below:-
@istest
private class MatchMakingControllerTest {
   
    Static testmethod void MatchMakingMethod(){
           String txt = 'THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG';
         rie__Event__c evt = new rie__Event__c();
        evt.rie__Event_Time_Zone__c = '(GMT-07:00) Pacific Daylight Time (America/Los_Angeles)';
        insert evt;
        
        rie__Registration__c attendee = new rie__Registration__c();
        attendee.rie__BatchProcessedForMatchMaking__c = false;
        attendee.rie__Event__c = evt.id;
        insert attendee;
        
        rie__Question__c qus = new rie__Question__c();
        qus.rie__Question__c  = 'Are you looking for a Solution?';
        qus.rie__Answers__c = 'ans,yes';
        insert qus;
        
        rie__Registrant_Answer__c regAns =  new rie__Registrant_Answer__c();
        regAns.rie__Question__c = qus.id;
        regAns.rie__Registration__c =  attendee.id;
        regAns.rie__Answer__c = 'yes';
        insert regAns;
        
        test.startTest();
        PageReference pageRef  = Page.MatchMakingQuestions; 
        pageRef.getParameters().put('Id', regAns.id);
        Test.setCurrentPage(pageRef);
        Registration__c reg = new Registration__c();
        Apexpages.StandardController sc = new Apexpages.standardController(reg);
        
        // Instantiate the extension
        MatchMakingController ext = new MatchMakingController(sc);
        ext.answeredQuestion = txt;
        //ext.populateAnswers();
        PageReference testPageResults = ext.cancel();
        PageReference testPageResult = ext.getQuestionsList();
        PageReference testPageRe = ext.submitAnswers();
        test.stoptest();
        
    }
}
how can I cover bold lines in my test class?
Can anyone help me with this?
​​​​​​​
My code is trigger duplicateaccount on Account (before insert, after insert) {
  
    List<Account> st = new List<Account>();
    st = [SELECT CreatedDate FROM Account ORDER BY CreatedDate DESC NULLS LAST LIMIT 1];
    for(Account a: Trigger.new){
        
    for(Account acc:st){
        System.debug('createddate' + acc.CreatedDate);
        Datetime firsttime = System.now();
        System.debug('first time' + firsttime);
        Datetime secondtime = Datetime.valueOf(acc.CreatedDate);
        System.debug('Secondtime' + secondtime);
        Decimal millisecondsBetween = firstTime.getTime() - secondTime.getTime();
        System.debug(millisecondsBetween);
        Decimal timeBetween = millisecondsBetween / 3600000; 
        decimal timediff = timeBetween.setscale(0);
        System.debug('diif'+timediff);
        
        if(timediff > 1) {    
            for(Account temp: st){
                Account objAccount = Trigger.newMap.get(temp.id);
                objAccount.addError('one hour');            
            }
            
        }
    }
    }

}

Can anyone help me how to resolve this.
I am getting the following error even though I have the application:

Challenge Not yet complete... here's what's wrong: 
We can't find a Lightning application named "Friends with Boats". Make sure you've created the Lightning application and named it correctly

I am able to invoke the application using:  https://brave-badger-292426-dev-ed.lightning.force.com/one/one.app#/n/Friends_with_Boats

I tried both the names of Friends_with_Boats and FriendswithBoats.

Please let me know what I am missing.

Thanks
Hi,

I'm used to work with Eclipse/Visual Code/Sublime/Atom and so far I can't get Trailhead Playgrounds to work with any of these.

How can I develop for Trailhead Playgrounds using any IDE and not the Developer Console?

I believe I already configured Force.com IDE to work with my DE org but my TP projects don't show.
  • October 16, 2017
  • Like
  • 0
I am completely lost and confused on this challenge and I dont know how to fix it. Every time I try to add Edna Frank as an external user it says "An account owner must be associated with a role to enable portal users or transfer portal users to his or her account." Anyone know what I'm doing wrong?

In this challenge, you set up the external sharing model, create a sharing set, and create a customer community user. First, set up the external sharing model with Case set to private. Then, enable Customer Portal settings, and create a sharing set titled Share cases with customers for the Customer Community User Profile. In this sharing set, grant customer community users read and write access to the case object for all cases associated with their account.
Ensure that your DE org user has a role assigned.
Create a customer community user from Edna Frank's contact record. (Your DE org should already have a contact record for Edna Frank. If it doesn't, create a new contact with first name Edna and last name Frank.)
Ensure that the account associated with Edna Frank has cases associated with it.
Ensure that sharing set mapping is set to User:Account = Case:Account.
 
  • September 14, 2016
  • Like
  • 1
Hi all,

I have four record types on order object. I have overridden them with the visualforce pages,but i am not able to see the picklist values based on the selected record types. Can you please guide me?
--This is my controller--
public class OrderRedirectExtensionController{
public String strRecordTypeId{get;set;}
public Order orderObj{get;set;}
public RecordType recordType{get;set;}
List<RecordType> lstred{get;set;}
public OrderRedirectExtensionController(ApexPages.StandardController controller ){
strRecordTypeId= apexpages.currentpage().getparameters().get('RecordType');

Order orderObj = new Order();
orderObj.RecordTypeId = strRecordTypeId;

system.debug('****strRecordTypeId*********'+strRecordTypeId);
lstred=[select id,Name from RecordType where id=:strRecordTypeId];
system.debug('****lstred*********'+lstred);
if(lstred.size()>0){

recordType=lstred[0];
  }
}
public PageReference saveOrder(){
 insert orderObj ;
 PageReference pageRef = new PageReference('/'+orderObj.id);
 pageRef.setRedirect(true); 
 return pageRef ;

}
}


--This is my page---
<apex:page standardController="Order" showHeader="true">
<apex:form >
<apex:messages />
 <style>
 .activeTab {background-color: #236FBD; color:white;
 background-image:none}
 .inactiveTab { background-color: lightgrey; color:black;
  background-image:none}
</style>

<!-- <script type="text/javascript">
function displaymessage()
{

alert("Your order has been created successfully!");

}
</script>-->

<apex:pageBlock title="Order edit" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>

</apex:pageBlockButtons>
<apex:pageBlockSection title="Order Information" columns="2">
<apex:variable var="c" value="{!RT}" />


<apex:inputfield value="{!$CurrentPage.parameters.RT}"/>
<apex:inputField value="{!order.AccountId}" required="true"/>
<apex:inputField value="{!order.OpportunityId}"/>
<apex:inputField value="{!order.Equipment_Name__c}" required="true"/>
<apex:inputField value="{!order.PoDate}"/>
<apex:inputField value="{!order.PoNumber}"/>
<!-- <apex:inputField value="{!order.OrderNumber}"/> -->
<apex:inputField value="{!order.Type}"/>
<apex:inputField value="{!order.Order_Reason__c}"/>
<apex:inputField value="{!order.Order_Start_Date__c}" required="true"/>
<apex:inputField value="{!order.EffectiveDate}" label="Order End Date"/>
<apex:inputField value="{!order.Status}"/>
<apex:inputField value="{!order.Case__c}" required="true"/>
<apex:inputField value="{!order.Payment_Options__c}"/>
<apex:inputField value="{!order.Signature_Required__c}"/>
<apex:inputField value="{!order.Delivery_Block_Status__c}"/>
<apex:inputField value="{!order.TotalAmount}"/> 
</apex:pageblockSection>

<apex:pageblockSection title="Other Information" columns="2">
<apex:inputField value="{!order.ContractId}"/>
<apex:inputField value="{!order.CustomerAuthorizedById}"/>
<apex:inputField value="{!order.CustomerAuthorizedDate}"/>
<apex:inputfield value="{!order.Ship_To_Name__c}"/>
<apex:inputfield value="{!order.Shipping_Method__c}"/>
<apex:inputfield value="{!order.Shipping_Account_Number__c}"/>
<apex:inputField value="{!order.Description}"/>
</apex:pageblockSection>




</apex:pageBlock>

</apex:form>
</apex:page>


Regards,
Amita
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!