• jaanvivek
  • NEWBIE
  • 30 Points
  • Member since 2012

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 25
    Questions
  • 42
    Replies

I am trying to implement online exam functionality.

 

In it I have folllowing objects

 

Courses

Assesments

Questions

Options ====> In Option object I have one checkbox for correct answer

 

Here is my VF page snippet-

 

<apex:page standardController="Assesment__c" extensions="surveyController" sidebar="false" showHeader="false">
<apex:sectionHeader title="{!Assesment__c.AssesmentName__c} For {!Assesment__c.Course__r.CourseName__c}" />
   <!-- timer script for this page on page load  -->
  <output name="x" id="txt"/>
<script>
var num=0.100;
var c=num.toFixed(2);
var t;
var myVar;
var myVarOne;
function myFunction()
{
t=setInterval(function(){myTimer()},60000);
}

function myTimer()
{
  document.getElementById('txt').value=c;
   var z= 0.010;
   var m=z.toFixed(2);
   c=(c-m).toFixed(2);

   if(c==0.05)
   {
     
     myVar=setTimeout(function(){alert("Only 5 minutes are left")},1000);  

   }
   else if(c==0.00)
    {
       myVarOne=setTimeout(function(){alert("Please submit your answers ")},1000);  
    
    }
   
    else if(c==-0.01)
    {
       clearInterval(t);
    }
    
        
    }
    
    
    </script>
    <body onload="myFunction()"></body> 
  
        <apex:form >
          <apex:pageBlock >
            <apex:repeat value="{!wrapperList}" var="wrapper" id="theRepeat" >
        <h1> Question{!wrapper.questionNumber}-</h1> <apex:outputText value="{!wrapper.question.QuestionName__c}" /><br/><br/>
          <h1>Options-</h1> <apex:selectCheckboxes value="{!wrapper.selectedOptions}" layout="pageDirection">
               <apex:selectOptions value="{!wrapper.options}"/> 
                </apex:selectCheckboxes>
                <br />  
            </apex:repeat>
           
          
            <apex:pageBlockButtons location="bottom">
            <apex:commandButton value="Submit" action="{!submit}" onclick="mySubmit();"/>
            </apex:pageBlockButtons>
     </apex:pageBlock>
      </apex:form>
      
   </apex:page>

 

 

Here is My Apex controller-

 

public class surveyController
{
     
     public List<Wrapper> wrapperList{get; set;}
     
     
 
 

    public surveyController(ApexPages.StandardController controller)
    {
        //here you'll have to have a way to retrieve a list of Questions and their related Option based on a criteria; you need to group them using something...
            List<Question__c> questionList = [SELECT Id, QuestionName__c,(SELECT Id, Option_Name__c,CorrectAnswer__c FROM Options__r) FROM Question__c where Assesment__c=:ApexPages.currentPage().getParameters().get('id')];//WHERE clause probably needed
                            
            wrapperList = new List<Wrapper>();  
             Integer i = 1; 
               for (Question__c question: questionList)
                {
                    Wrapper wrapper = new Wrapper(question, question.Options__r,i++);
                    wrapperList.add(wrapper);
                }
    
    
    }
    
    
    // wrapper class
    public class Wrapper
  {
        public List<String> selectedOptions{get; set;}//this will be a List of the Ids of the selected Options
        public List<SelectOption> options{get; set;}//a list of SelectOption that maps Option id(value) to Option name(label)     

        public Question__c question{get; set;}
        
         public Integer questionNumber {get; set;}  // to get question number prefixed with questions
         
         public String ansobj{get;set;} //to store answers on page
         public String SingleSelectedValue{get;set;}  // for single choice answer.
         
       

        public Wrapper(Question__c question, List<Option__c> optionsList,Integer qn)
       {
            String alphabet ='abcdefgh';
            this.questionNumber=qn; 
            this.question = question;
            this.selectedOptions = new List<String>();
            this.options = new List<SelectOption>();
            if ((optionsList == null) || (optionsList.size() == 0))
            {
                options.add(new SelectOption('none','-- none --'));
            } 
            else
             {
                Integer i=0;
                for (Option__c option: optionsList)
                {
                    options.add(new SelectOption(option.Id,alphabet.substring(i, i + 1) + '- ' +option.Option_Name__c));
                    i++;
                   
                    
                }
            }
        }
    }
    
    
    // submit method
    
    public void submit()
    {
       
        for(Wrapper wrap:wrapperList)
        {
             for(Option__c option:wrap.Question.Options__r)
             {
                  
                    if(option.CorrectAnswer__c==true)
                    {
                        
                        system.debug('Your correct option is=============>'+option.Option_Name__c);
                        wrap.ansobj=option.Option_Name__c;
                        system.debug('option name----'+wrap.ansobj);
                   
                    
                    }
                    
                    
               
             }
             
                 System.debug('My Selected Option=======>'+wrap.SingleSelectedValue);  // this values is coming null
                 System.debug('answerobj=======>'+wrap.ansobj);
                
              
                if(wrap.ansobj==wrap.SingleSelectedValue)
                      {
                       System.debug('Correct Answer');
                                         
                      }    
             
            
            
        
        }    
        
        
         
         
         
          
    
    
    }
    

}

In above Apex code I am facing some problems  while submitting the answers.

 

Here are my queries-

 

1- How to compare "user selected options" to "CorrectAnswer Options"

     In above code i tried

  
                 System.debug('My Selected Option=======>'+wrap.SingleSelectedValue);  // It's coming "null"
                 System.debug('answerobj=======>'+wrap.ansobj);
                
              
                if(wrap.ansobj==wrap.SingleSelectedValue)
                      {
                       System.debug('Correct Answer');
                                         
                      }   

 

2- I need to show custom message with score i.e. if out of 5 questions  3 are correct so  It should come as

"Hi your score is 3."

 

3- After submitting answers that page should hide  and custom message should come on whole screen in place of

  that page which were having questions

 

 

Could  anyone help me to makemy self correct in logic.

 

Thanks,

JaanVivek

 

 

 

 

I am trying to implement online exam functionality in which I would like to restrict user to submit answers till time assigned for that page i.e. 10 minutes.

 

I tried like this in VF page.

<script>
function  myfunction()
    {
     if(c!=0.00)
     {
      var temp;
      temp=setTimeout(function(){alert("You can not submit your answers now ")},1000); 
     
     }
     
     
    
    }
</script>

 This is the syntax for commandButton.

 

<apex:commandButton value="Submit" action="{!submit}" onclick="myfunction();"/>

   But every time when user tries to click on "Submit" button before time end it's allowng to click.

 

I would like to show an alert if user is cliclking on Submit before time end.

 

Could anyone suggest in this case.

 

Thanks,

JaanVivek

 

 

I need to show custom timer on a VF page.

 

I have 6 questions to be answered on VF page so i want to show timer in form "0:00".

 

I want to give only 10 minutes for a page after 10 minutesthe timer should stop and it should be in "0:10" form

 

I have tried some java script but not successed.

 

 

could any one suggest something.

 

 

Thanks

JaanVivek

 

Hi Everyone,

 

I am facing below mentioned error while running data loader through command line.

 

258 [main] ERROR com.salesforce.dataloader.process.ProcessConfig  - Error loading process: insertQuestion configuration from config file: C:\Program Files\sales
force.com\Apex Data Loader 23.0\QuestionInsert\process-conf.xmlorg.springframework.beans.factory.BeanDefinitionStoreException: Line 25 in XML document from file [C:\Program Files\salesforce.com\Apex Data Loader 23.0\Questio
nInsert\process-conf.xml] is invalid; nested exception is org.xml.sax.SAXParseException: The content of element type "bean" must match "(description?,(construct
or-arg|property|lookup-method|replaced-method)*)".org.xml.sax.SAXParseException: The content of element type "bean" must match "(d
escription?,(constructor-arg|property|lookup-method|replaced-method)*)".

 


below in process-conf file code

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="insertQuestion">
class="com.salesforce.dataloader.process.ProcessRunner"
singleton="false">
<description>Accounts Extraction practise on 8 june 2012</description>
<property name="name" value="insertQuestion"/>
<property name="configOverrideMap">
<map>
<entry key="sfdc.debugMessages" value="false"/>
<entry key="sfdc.endpoint" value="https://login.salesforce.com"/>
<entry key="sfdc.username" value="vivek.pandey@sfdc.com"/>
<entry key="sfdc.password" value="ae6c33e4ccb8f2d8f5cd55ad1b3f9d0fd493b81bd454b6aa571601f85d8b1c0bae730de9d5a3f7b8"/>
<entry key="process.encryptionKeyFile" value="C:\Program Files\salesforce.com\Apex Data Loader 23.0\QuestionInsert\key.txt"/>
<entry key="sfdc.timeoutSecs" value="600"/>
<entry key="sfdc.loadBatchSize" value="200"/>
<entry key="sfdc.entity" value="Question__c"/>
<entry key="process.operation" value="insert"/>
<entry key="process.mappingFile" value="C:\Program Files\salesforce.com\Apex Data Loader 23.0\QuestionInsert\questionInsertMap.sdl" /> 
<entry key="dataAccess.name" value="C:\Program Files\salesforce.com\Apex Data Loader 23.0\QuestionInsert\Question.csv"/>
<entry key="dataAccess.type" value="csvRead"/>
</map>
</property>
</bean>
</beans>

  I have made available all necessary files also like-

 

1- question.bat

2- questionInsertMap.sdl

3-key.txt

4-Question.csv

 

 

Could anyone help to solve it.

 

 

Thanks,

JaanVivek

I am new to this tech, So i am doing practise by myself by taking help from bloga and community.

 

I am trying to develop a Vf page having questions with it's answers having checkbox as prefirx.

 

e.g.

 

Question1- who is prime minister of india.

                       a- dr. Man Mohan Singh

                        b- Narendra Modi

                        c- Nitessh Kumar

                        d- lalu Yadav

 

Same Questin 2

 

 

I have created Questions and options as custom bjects in my org.

 

Could you please provide some help how to start working on it.

 

 

 

Thanks,

JaanVivek

                 

Could anyone explian about "Custom Setting".

 

I have gone through the materials available over www but did not get exact information.

 

If anyone has worked on it, Pls explain following queries.

 

1- what is the Custom setting?

 

2- why we use it?

 

3- we have concept of custom objects and standard objects then why we need it?

 

4- what does it mean that " custom setting data will reside in "application cache"?

 

 

Thanks for your all help.

 

 

 

Thanks,

JaanVivek

 

Could you please explain about the usage of apexpages.currentpage.getparameter().get('id'). with an example.

 

1- in which situations we need to use this..

 

 

 

Thanks,

JaanVivek

 

 

 

 

Could you please brief me about <apex:outputText>, <apex:ouputField> and <apex:outputPanel>.

 

I have following queries.

 

1- When to use these individually.

 

2- How we can guess about the usage of these all.

 

 

If anyone can explain with realtime exmaple. It would be good for me to digest it.

 

 

Thanks for your all help and time.

 

 

Thanks,

JaanVivek

Could anyone please explain about "setRedirect" and "getRedirect" in salseforce with real time explanation.

 

Here are some of mine queries.

 

1- When we need to use the.

2- what will be effect if we set it as "true" or "false".

 

3- At one place i used setredirct(true) and setredirect(false) but result was same.

   could you explain about it.

 

Thanks for your time and suggestions.

 

Thanks,

JaanVivek

 

 

Hello All,

 

I need youe help.

 

I am writing an VF page which does need to diplay " Account and Contact "   Name in seperate columns in the same pageBlockTable.

 

I am geeting error 

 

Error: Could not resolve the entity from <apex:outputField> value binding '{!showData.catchAcc.name}'. <apex:outputField> can only be used with SObject fields.

 

 

Here is the below code snippet.

 

<apex:page controller="AllData" sidebar="false" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!passingData}" var="showData">
<apex:column headerValue="AccountName">
<apex:outputField value="{!showData.catchAcc.name}"/>
</apex:column>
<apex:column headerValue="ContactName">
<apex:outputField value="{!showData.catchCon.name}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Apex Controller-

 

public class AllData
{
    public List<innerClass> passingData { get; set; }
    public List<Account> allAcc {get;set;}
    public List<Contact> allCon{get;set;}
    
    
    public AllData()
    {
       passingData=new List<innerClass>();
       allAcc=[select id,name from Account limit 10];
       allCon=[select id,name from Contact limit 10];
       innerClass allAddData=new innerClass(allAcc ,allCon);
       passingData.add(allAddData);
    
    
    }
    
    public class innerClass
    {
         
        public List<Account> catchAcc {get;set;}
        public List<Contact> catchCon {get;set;}
        public innerClass(list<Account> gettingaccs,list<Contact> gettingcons)
        {    
            catchAcc = gettingaccs;
            catchCon = gettingcons;
        }
    
    }
    
    
    
    
    
    
    
    
}

 

 

Thanks for your all valuable suggestions.

 

it will help me to improve the way of coding .

 

 

Thanks,

JaanVivek

 

Could anyone please explain about "rendered", "reRender" and "renderAs" in real time environment.

 

I have gone through pdfs and did not get it very clearly with these significance.

 

Like-

1- why we use these.

2- when we use these.

3-how ro use these.

 

thanks for sharing your experience regarding all these.

 

 

Thanks,

JaanVivek

Hello All,

 

I am new to SFDC tech. I do not work on this tech but i learnt it through docs and blogs.

 

I have gone through  all satndard documents but I did not get practical knowledge regarding my queries for Triggers.

 

I  have following queries regarding Triggers-

 

1- In real time what is "before" and  "after" trigger.

 

2- In which scenarios we should go for "before" and "after".

 

3-In reference of salesforce.com database what is significance of "before" and "after".

 

4- practical difference between "Trigger.new" and "Trigger.old"

 

5- Are there any best practices where we do use "Trigger.new" and "Trigger.old".

 

I would like to say thanks in advance for your valuable suggestions.

 

I learnt a lot from this community.

 

I would appreciate if anyone please provide some real time(practical) explanation. It will help me to digest it.

 

 

Thanks again for your time and knowledge sharing.

 

Thanks,

jaanVivek

I need to implement the following scenarios in Lookup Relationship.

 

Scenario1-

 

We have one Object say like "A" it has three child objects say "B1", "B2", "B3" associated with Lookup Relationship.

There is a field named "Grand Revenue" on object  "A" and all three fields named "Revenue" on objects "B1" , "B2", "B3".

 

We need to implement

"Grand Revenue"= "Revenue"+"Revenue"+"Revenue" on A(Parent).

 

Scenario2-

 

If we delete one records on "A" all associated records should be deleted from childs "B1", "B2", "B3".

 

Could anyone please suggest how to achieve it.

 

Thanks for your suggestions.

 

Thanks,

JaanVivek

 

 

I need to implement one functionality in opportunity object. Please find below mentioned functionality.

 

Scenario-

 

If "Stage" for opportunity is "propecting" i need to display  "1 Green Flag" ,

If  "Stage" for opportunity is "Closed-Won" I need to display  "2 Red Flags",

if "Stage"  for opportunity is "Closed-Lost"  I need to display "3 yellow Flags"

 

And

 

if  "Stage for ooportunity is " Closed-Won" the Opportunity must be "non-editable".

 

Could anyone please help me how to implement it.

 

Thanks for your all valuable help.

 

Thanks,

JaanVivek

Hello All,

 

Good Evening, Can anyone suggest me how to do self study and some hands-on on salesforce integration.

 

Like

Salesforce-To-Java

Salesforce-To-.NET

and vice-versa.

 

I am new to this, so I am not sure how to start the study and from where to start.

 

Thanks for your valuable suggestions.

 

Thanks,

JaanVivek

hello All,

 

Here I'm again with some un-coverage issue for Apex In-BoundEmailService class in sfdc.

 

Here is myInbound emailservice class-

 

global class inBoundEmail implements Messaging.InboundEmailHandler
{
   global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope)
   {
        Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
        String subToCompare = 'Create Contact';

        if(email.subject.equalsIgnoreCase(subToCompare))
        {
            Contact c = new Contact();
            c.Email=email.fromAddress;
            
            // capture phone number and city also from incoming email.
            // Splits each line by the terminating newline character  
            // and looks for the position of the phone number and city 
            String[] emailBody = email.plainTextBody.split('\n', 0);
            c.LastName=emailBody[0].substring(0);
            c.Phone = emailBody[1].substring(0);
            c.Title = emailBody[2].substring(0);
                       
            insert c;
            
            // Save attachments, if any
            if (email.textAttachments != null)
            {
            for(Messaging.Inboundemail.TextAttachment tAttachment : email.textAttachments)
            {
            Attachment attachment = new Attachment();

            attachment.Name = tAttachment.fileName;
            attachment.Body = Blob.valueOf(tAttachment.body);
            attachment.ParentId = c.Id;
            insert attachment;
            }
            
            }

            //Save any Binary Attachment
            
            if (email.binaryAttachments != null)
            {
            for(Messaging.Inboundemail.BinaryAttachment bAttachment : email.binaryAttachments) {
            Attachment attachment = new Attachment();

            attachment.Name = bAttachment.fileName;
            attachment.Body = bAttachment.body;
            attachment.ParentId = c.Id;
            insert attachment;
            }
           } 
        }

        result.success = true;
        return result;
             
   }
   }

Thisis the Test Class which is creating no error but it's not covering all test conditions.

 

//Test Method for main class
   
   static testMethod void TestinBoundEmail()
   {
     // create a new email and envelope object
     
   Messaging.InboundEmail email = new Messaging.InboundEmail() ;
   Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();
   
   // setup the data for the email
   
  email.subject = 'Test Job Applicant';
  email.fromAddress = 'someaddress@email.com';
  
  // add an Binary attachment
  
  Messaging.InboundEmail.BinaryAttachment attachment = new Messaging.InboundEmail.BinaryAttachment();
  attachment.body = blob.valueOf('my attachment text');
  attachment.fileName = 'textfileone.txt';
  attachment.mimeTypeSubType = 'text/plain';
  email.binaryAttachments = new Messaging.inboundEmail.BinaryAttachment[] { attachment };
 
  // add an Text atatchment
  
  Messaging.InboundEmail.TextAttachment attachmenttext = new Messaging.InboundEmail.TextAttachment();
  attachment.body = blob.valueOf('my attachment text');
  attachment.fileName = 'textfiletwo.txt';
  attachment.mimeTypeSubType = 'texttwo/plain';
  email.textAttachments =   new Messaging.inboundEmail.TextAttachment[] { attachmenttext };
 
  // call the email service class and test it with the data in the testMethod
  inBoundEmail  testInbound=new inBoundEmail ();
  testInbound.handleInboundEmail(email, env);
    
   // create a contact data
   
    Contact testContact= new Contact();
    testContact.Email='someaddress@email.com';
    testContact.LastName='lastname';
    testContact.Phone='1234567234';
    testContact.Title='hello';
    insert testContact;
    
    system.debug('insertedcontact id===>' +testContact.Id);
   
   // Create Attachmenat data
   
  Attachment attachmnt =new Attachment();
  attachmnt.name='textfileone.txt';
  attachmnt.body =blob.valueOf('my attachment text');
  attachmnt.ParentId =testContact.Id;
  insert  attachmnt ;
   
   
   }
   

 

Could any one please make me correct in this case.

 

I tried to put all conditions and test data still it's creating problem.

 

Thanks for your valuable suggestions.

 

Thanks & regards,

jaanVivek

Please make me correct for writing unit test class for the following Apex class-

 

public class practiseOneController
 {
    public Account getAccount()
    {
        Account[] acc= [select id,Name,(select id,firstname,lastname from Contacts limit 5) from Account where id=
                 :System.currentPageReference().getParameters().get('id')];
                 
                 if(acc.size()>0)
                 {
                    return acc[0];
                 
                 }
                  else
                  {
                    return null;
                  
                  }
                 
                 
    }
    
    
    // Test Method for this main class
    
     static testMethod void TestpractiseOneController()
     {
       practiseOneController testObj= new practiseOneController();
       
       Account testAcc=new Account();
       testAcc.Name='testaccount';
       insert testAcc;
       testObj.getAccount();
     
     
     
     }
    
    
    

}

 I tried but not getting to cover

 :System.currentPageReference().getParameters().get('id')];
                 
                 if(acc.size()>0)
                 {
                    return acc[0];
                 
                 }

 In this apex class i am trying to show the accociated contacts with the Account.

 

Thanks & regards,

JaanVivek

Hello,

 

I am trying to write a VF Component, in which it has two arrows up-Down to increase and decrease some values.

 

But in VF Page these two arrows are not clickable.

 

Could you pls help, where is the fault.

 

Here is VF Component-

<apex:component >

<!--Attribute Definition-->


<apex:attribute name="myvalue" description="Default value for the component." type="Integer" required="true"/> 
<apex:attribute name="max" description="Maximum Value" type="Integer" required="true"/> 
<apex:attribute name="min" description="Minimum value" type="Integer" required="true"/>

<!--java script description-->

<script>
function increment(valueId)
{
   if(document.getElementById(valueId).value<{!max})
   {
    documnet.getElementById(valueId).value++;
    
   }
   else
   {
     alert("You can not increase the number above" +{!max});
   
   }
   
 }
 
 function decrement(valueId)
 {
   if(document.getElementById(valueId).value>{!min})
   {
      documnet.getElementById(valueId).value--;
   
   }
   
   else
   {
     alert("You can not decrease number below"  +{!min});
   
   }
    
 }

</script>

<!-- Custom Componet definition -->
<table cellspacing='0' cellpadding='0'>
<tr>
<td rowspan="2">
<apex:inputText value="{!myvalue}" size="4" id="theValue"/>
</td>
<td>
<div onclick="increment('{!$Component.theValue}');">&#9650;
</div>
</td>
</tr>
<tr>
<td>
<div onclick="decrement('{!$Component.theValue}');">&#9660;
</div>
</td>
</tr>
</table>
</apex:component>

  VF Page-

<apex:page >
<apex:pageBlock title="increase or decrease the displayed values">
<apex:form >
<c:addSubValue myvalue="10" min="0" max="15"/>
</apex:form>
</apex:pageBlock>
</apex:page>

 

Here is the final output, where up and down arrows are not-clickable.

 

 
These two arrows are not clickable.
 
 
Thanks for you help.
 
Thanks & regards,
jaanVivek

 

 

Hello All, I am trying to create a VFPage for Accounts and show it's related Contacts. i am getting the following error-

 

System.QueryException: List has no rows for assignment to SObject Class.practiseOneController.getAccount: line 5, column 1

  Please find below VF Page-

<apex:page controller="practiseOneController" tabStyle="Account">
<apex:pageBlock title="Hello {!$User.FirstName}!!!">
You belong to {!account.name} Account.
</apex:pageBlock>
<apex:pageBlock title="Contacts">
<apex:dataTable value="{!account.contacts}" var="contacts" cellpadding="4" border="1">
<apex:column value="{!contacts.FirstName}" headerValue="FirstName"/>
<apex:column value="{!contacts.LastName}" headerValue="LastName"/>
</apex:dataTable>
</apex:pageBlock>
 
</apex:page>

  Apex Class-

 

public class practiseOneController
 {
    public Account getAccount()
    {
        return [select id,Name,(select id,firstname,lastname from Contacts limit 5) from Account where id=
                 :System.currentPageReference().getParameters().get('id')];
    }

}

please help me in this and pls suggest how can we avoid this type of errors while creating pages and classes 

 

Thanks for your help.

 

Thanks,

JaanVivek

Hello All,

 

I am trying to use Email Service, for this  I have created an Email Service in my SFDC instance.

 

I have created one Apex class as below mentioned-

global class inBoundEmail implements Messaging.InboundEmailHandler
{
   global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope)
   {
        Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
        String subToCompare = 'Create Contact';

        if(email.subject.equalsIgnoreCase(subToCompare))
        {
            Contact c = new Contact();
            c.LastName = email.plainTextBody;
            insert c;
            // Save attachments, if any
            for(Messaging.Inboundemail.TextAttachment tAttachment : email.textAttachments) {
            Attachment attachment = new Attachment();

            attachment.Name = tAttachment.fileName;
            attachment.Body = Blob.valueOf(tAttachment.body);
            attachment.ParentId = c.Id;
            insert attachment;
            }

            //Save any Binary Attachment
            for(Messaging.Inboundemail.BinaryAttachment bAttachment : email.binaryAttachments) {
            Attachment attachment = new Attachment();

            attachment.Name = bAttachment.fileName;
            attachment.Body = bAttachment.body;
            attachment.ParentId = c.Id;
            insert attachment;
            }
        }

        result.success = true;
        return result;
             
   }
  }

  But while sending email from my email id to Create Contact , I'm getting below mentioned error

 

The attached message was sent to the Email Service address <createcontact@o-kkmoyp3dd260lsz0qd262mitw6wxvwfpozgoqdwqpr58npllg.9-ekpgea2.9.apex.salesforce.com> but could not be processed because the following error occurred:

554 System.NullPointerException: Attempt to de-reference a null object

Class.inBoundEmail.handleInboundEmail: line 14, column 1

  I'm following below steps while sending email..

 

ToAddress-  createcontact@o-kkmoyp3dd260lsz0qd262mitw6wxvwfpozgoqdwqpr58npllg.9-   ekpgea2.9.apex.salesforce.com

 

Subject- Create Contact

 

Email Body- Contact Name.

 

Could any one help me to get this ok. So that i can see  inserted contact in Contacts tab.

 

Thanks & regards,

JaanVivek

I am trying to implement online exam functionality.

 

In it I have folllowing objects

 

Courses

Assesments

Questions

Options ====> In Option object I have one checkbox for correct answer

 

Here is my VF page snippet-

 

<apex:page standardController="Assesment__c" extensions="surveyController" sidebar="false" showHeader="false">
<apex:sectionHeader title="{!Assesment__c.AssesmentName__c} For {!Assesment__c.Course__r.CourseName__c}" />
   <!-- timer script for this page on page load  -->
  <output name="x" id="txt"/>
<script>
var num=0.100;
var c=num.toFixed(2);
var t;
var myVar;
var myVarOne;
function myFunction()
{
t=setInterval(function(){myTimer()},60000);
}

function myTimer()
{
  document.getElementById('txt').value=c;
   var z= 0.010;
   var m=z.toFixed(2);
   c=(c-m).toFixed(2);

   if(c==0.05)
   {
     
     myVar=setTimeout(function(){alert("Only 5 minutes are left")},1000);  

   }
   else if(c==0.00)
    {
       myVarOne=setTimeout(function(){alert("Please submit your answers ")},1000);  
    
    }
   
    else if(c==-0.01)
    {
       clearInterval(t);
    }
    
        
    }
    
    
    </script>
    <body onload="myFunction()"></body> 
  
        <apex:form >
          <apex:pageBlock >
            <apex:repeat value="{!wrapperList}" var="wrapper" id="theRepeat" >
        <h1> Question{!wrapper.questionNumber}-</h1> <apex:outputText value="{!wrapper.question.QuestionName__c}" /><br/><br/>
          <h1>Options-</h1> <apex:selectCheckboxes value="{!wrapper.selectedOptions}" layout="pageDirection">
               <apex:selectOptions value="{!wrapper.options}"/> 
                </apex:selectCheckboxes>
                <br />  
            </apex:repeat>
           
          
            <apex:pageBlockButtons location="bottom">
            <apex:commandButton value="Submit" action="{!submit}" onclick="mySubmit();"/>
            </apex:pageBlockButtons>
     </apex:pageBlock>
      </apex:form>
      
   </apex:page>

 

 

Here is My Apex controller-

 

public class surveyController
{
     
     public List<Wrapper> wrapperList{get; set;}
     
     
 
 

    public surveyController(ApexPages.StandardController controller)
    {
        //here you'll have to have a way to retrieve a list of Questions and their related Option based on a criteria; you need to group them using something...
            List<Question__c> questionList = [SELECT Id, QuestionName__c,(SELECT Id, Option_Name__c,CorrectAnswer__c FROM Options__r) FROM Question__c where Assesment__c=:ApexPages.currentPage().getParameters().get('id')];//WHERE clause probably needed
                            
            wrapperList = new List<Wrapper>();  
             Integer i = 1; 
               for (Question__c question: questionList)
                {
                    Wrapper wrapper = new Wrapper(question, question.Options__r,i++);
                    wrapperList.add(wrapper);
                }
    
    
    }
    
    
    // wrapper class
    public class Wrapper
  {
        public List<String> selectedOptions{get; set;}//this will be a List of the Ids of the selected Options
        public List<SelectOption> options{get; set;}//a list of SelectOption that maps Option id(value) to Option name(label)     

        public Question__c question{get; set;}
        
         public Integer questionNumber {get; set;}  // to get question number prefixed with questions
         
         public String ansobj{get;set;} //to store answers on page
         public String SingleSelectedValue{get;set;}  // for single choice answer.
         
       

        public Wrapper(Question__c question, List<Option__c> optionsList,Integer qn)
       {
            String alphabet ='abcdefgh';
            this.questionNumber=qn; 
            this.question = question;
            this.selectedOptions = new List<String>();
            this.options = new List<SelectOption>();
            if ((optionsList == null) || (optionsList.size() == 0))
            {
                options.add(new SelectOption('none','-- none --'));
            } 
            else
             {
                Integer i=0;
                for (Option__c option: optionsList)
                {
                    options.add(new SelectOption(option.Id,alphabet.substring(i, i + 1) + '- ' +option.Option_Name__c));
                    i++;
                   
                    
                }
            }
        }
    }
    
    
    // submit method
    
    public void submit()
    {
       
        for(Wrapper wrap:wrapperList)
        {
             for(Option__c option:wrap.Question.Options__r)
             {
                  
                    if(option.CorrectAnswer__c==true)
                    {
                        
                        system.debug('Your correct option is=============>'+option.Option_Name__c);
                        wrap.ansobj=option.Option_Name__c;
                        system.debug('option name----'+wrap.ansobj);
                   
                    
                    }
                    
                    
               
             }
             
                 System.debug('My Selected Option=======>'+wrap.SingleSelectedValue);  // this values is coming null
                 System.debug('answerobj=======>'+wrap.ansobj);
                
              
                if(wrap.ansobj==wrap.SingleSelectedValue)
                      {
                       System.debug('Correct Answer');
                                         
                      }    
             
            
            
        
        }    
        
        
         
         
         
          
    
    
    }
    

}

In above Apex code I am facing some problems  while submitting the answers.

 

Here are my queries-

 

1- How to compare "user selected options" to "CorrectAnswer Options"

     In above code i tried

  
                 System.debug('My Selected Option=======>'+wrap.SingleSelectedValue);  // It's coming "null"
                 System.debug('answerobj=======>'+wrap.ansobj);
                
              
                if(wrap.ansobj==wrap.SingleSelectedValue)
                      {
                       System.debug('Correct Answer');
                                         
                      }   

 

2- I need to show custom message with score i.e. if out of 5 questions  3 are correct so  It should come as

"Hi your score is 3."

 

3- After submitting answers that page should hide  and custom message should come on whole screen in place of

  that page which were having questions

 

 

Could  anyone help me to makemy self correct in logic.

 

Thanks,

JaanVivek

 

 

 

 

I am trying to implement online exam functionality in which I would like to restrict user to submit answers till time assigned for that page i.e. 10 minutes.

 

I tried like this in VF page.

<script>
function  myfunction()
    {
     if(c!=0.00)
     {
      var temp;
      temp=setTimeout(function(){alert("You can not submit your answers now ")},1000); 
     
     }
     
     
    
    }
</script>

 This is the syntax for commandButton.

 

<apex:commandButton value="Submit" action="{!submit}" onclick="myfunction();"/>

   But every time when user tries to click on "Submit" button before time end it's allowng to click.

 

I would like to show an alert if user is cliclking on Submit before time end.

 

Could anyone suggest in this case.

 

Thanks,

JaanVivek

 

 

I need to show custom timer on a VF page.

 

I have 6 questions to be answered on VF page so i want to show timer in form "0:00".

 

I want to give only 10 minutes for a page after 10 minutesthe timer should stop and it should be in "0:10" form

 

I have tried some java script but not successed.

 

 

could any one suggest something.

 

 

Thanks

JaanVivek

 

Hi all

i am new to salesforce and dont have knowledge on programming but want to learn apex and visualforce so just need help to learn these things from scratch...... can anyone help me it wil be gr8 help

Hi Everyone,

 

I am facing below mentioned error while running data loader through command line.

 

258 [main] ERROR com.salesforce.dataloader.process.ProcessConfig  - Error loading process: insertQuestion configuration from config file: C:\Program Files\sales
force.com\Apex Data Loader 23.0\QuestionInsert\process-conf.xmlorg.springframework.beans.factory.BeanDefinitionStoreException: Line 25 in XML document from file [C:\Program Files\salesforce.com\Apex Data Loader 23.0\Questio
nInsert\process-conf.xml] is invalid; nested exception is org.xml.sax.SAXParseException: The content of element type "bean" must match "(description?,(construct
or-arg|property|lookup-method|replaced-method)*)".org.xml.sax.SAXParseException: The content of element type "bean" must match "(d
escription?,(constructor-arg|property|lookup-method|replaced-method)*)".

 


below in process-conf file code

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="insertQuestion">
class="com.salesforce.dataloader.process.ProcessRunner"
singleton="false">
<description>Accounts Extraction practise on 8 june 2012</description>
<property name="name" value="insertQuestion"/>
<property name="configOverrideMap">
<map>
<entry key="sfdc.debugMessages" value="false"/>
<entry key="sfdc.endpoint" value="https://login.salesforce.com"/>
<entry key="sfdc.username" value="vivek.pandey@sfdc.com"/>
<entry key="sfdc.password" value="ae6c33e4ccb8f2d8f5cd55ad1b3f9d0fd493b81bd454b6aa571601f85d8b1c0bae730de9d5a3f7b8"/>
<entry key="process.encryptionKeyFile" value="C:\Program Files\salesforce.com\Apex Data Loader 23.0\QuestionInsert\key.txt"/>
<entry key="sfdc.timeoutSecs" value="600"/>
<entry key="sfdc.loadBatchSize" value="200"/>
<entry key="sfdc.entity" value="Question__c"/>
<entry key="process.operation" value="insert"/>
<entry key="process.mappingFile" value="C:\Program Files\salesforce.com\Apex Data Loader 23.0\QuestionInsert\questionInsertMap.sdl" /> 
<entry key="dataAccess.name" value="C:\Program Files\salesforce.com\Apex Data Loader 23.0\QuestionInsert\Question.csv"/>
<entry key="dataAccess.type" value="csvRead"/>
</map>
</property>
</bean>
</beans>

  I have made available all necessary files also like-

 

1- question.bat

2- questionInsertMap.sdl

3-key.txt

4-Question.csv

 

 

Could anyone help to solve it.

 

 

Thanks,

JaanVivek

I am new to this tech, So i am doing practise by myself by taking help from bloga and community.

 

I am trying to develop a Vf page having questions with it's answers having checkbox as prefirx.

 

e.g.

 

Question1- who is prime minister of india.

                       a- dr. Man Mohan Singh

                        b- Narendra Modi

                        c- Nitessh Kumar

                        d- lalu Yadav

 

Same Questin 2

 

 

I have created Questions and options as custom bjects in my org.

 

Could you please provide some help how to start working on it.

 

 

 

Thanks,

JaanVivek

                 

Could anyone explian about "Custom Setting".

 

I have gone through the materials available over www but did not get exact information.

 

If anyone has worked on it, Pls explain following queries.

 

1- what is the Custom setting?

 

2- why we use it?

 

3- we have concept of custom objects and standard objects then why we need it?

 

4- what does it mean that " custom setting data will reside in "application cache"?

 

 

Thanks for your all help.

 

 

 

Thanks,

JaanVivek

 

Hello All,

 

I need youe help.

 

I am writing an VF page which does need to diplay " Account and Contact "   Name in seperate columns in the same pageBlockTable.

 

I am geeting error 

 

Error: Could not resolve the entity from <apex:outputField> value binding '{!showData.catchAcc.name}'. <apex:outputField> can only be used with SObject fields.

 

 

Here is the below code snippet.

 

<apex:page controller="AllData" sidebar="false" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!passingData}" var="showData">
<apex:column headerValue="AccountName">
<apex:outputField value="{!showData.catchAcc.name}"/>
</apex:column>
<apex:column headerValue="ContactName">
<apex:outputField value="{!showData.catchCon.name}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Apex Controller-

 

public class AllData
{
    public List<innerClass> passingData { get; set; }
    public List<Account> allAcc {get;set;}
    public List<Contact> allCon{get;set;}
    
    
    public AllData()
    {
       passingData=new List<innerClass>();
       allAcc=[select id,name from Account limit 10];
       allCon=[select id,name from Contact limit 10];
       innerClass allAddData=new innerClass(allAcc ,allCon);
       passingData.add(allAddData);
    
    
    }
    
    public class innerClass
    {
         
        public List<Account> catchAcc {get;set;}
        public List<Contact> catchCon {get;set;}
        public innerClass(list<Account> gettingaccs,list<Contact> gettingcons)
        {    
            catchAcc = gettingaccs;
            catchCon = gettingcons;
        }
    
    }
    
    
    
    
    
    
    
    
}

 

 

Thanks for your all valuable suggestions.

 

it will help me to improve the way of coding .

 

 

Thanks,

JaanVivek