• tom_patros
  • NEWBIE
  • 180 Points
  • Member since 2011

  • Chatter
    Feed
  • 7
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 39
    Replies

I have a trigger that captures the day and time a}n event was completed and then add that day/time to field on the Account Screen. I ran my tests in the Sandbox and got no errors and a 100% coverage. When I go to deploy it to production I get the following:

 

Failure Message: "System.QueryException: List has more than 1 row for assignment to SObject", Failure Stack Trace: "Class.OSC_Event_Test.myUnitTest: line 6, column 20 External entry point"

Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required

 

Here is my Trigger and Test Class

 

 

Trigger

trigger OSC_Activty_Event on Event (after update) {

for (Event updatedEvent : trigger.new) {
    for(Event olduEvent : trigger.old){
        if (updatedEvent.Sales_Call_Completed__c != olduEvent.Sales_Call_Completed__c){
            for(Account a : [SELECT id, Last_Sales_Call__c FROM Account WHERE Account.id = :updatedEvent.AccountId]){

 a.Last_Sales_Call__c = updatedEvent.Completed_Date_Time__c;
  update a;

  }}}}

 Test Class

@isTestprivate class OSC_Event_Test {
    static testMethod void myUnitTest() {       

 

Event ev = [Select id,Sales_Call_Completed__c from Event where Sales_Call_Completed__c = 'No'];       

ev.Sales_Call_Completed__c = 'Yes'; ev.All_Communities_Objective__c = 'Sell a Paid Model';       

try{       

update ev;         

//System.assertEquals('This is a test');        }       

catch(System.DmlException e){           

 System.debug('we caught a dml exception: ' + e.getDmlMessage(0));        

}    }}

  • August 14, 2011
  • Like
  • 0

Hi All,

 

I have a inputText field in a VF page and I need to disable paste function(Ctrl+v and paste using mouse button) so that we need to compulsorily type in the text box instead of just copy pasting.

 

I have tried the following script:

<script>

function DisableCtrlKey(e)
{
    var code = (document.all) ? event.keyCode:e.which;
    // look for CTRL key press
    if (parseInt(code)==17)
    {
        alert("Please re-type your email address");
        window.event.returnValue = false;
    }
}

function DisableRightClick(event)
{
    //For mouse right click
    if (event.button==2)
    {
        alert("Please re-type your email address");       
    }
}

</script>

 and under the VF page:

<apex:inputText id="confirmemail" value="{!email}" onKeyDown="return DisableCtrlKey(event)" onMouseDown="DisableRightClick(event)" </apex:inputText>

 It works fine but I want to implement the same functionality without using alert function.

 

Can anyone please let me know any work around to accomplish the above scenario.

Any help on this will be highly appreciated.

 

 

 

I am getting the following error when i tried to make a callout to SAP webservice.

 

I have registered my endpoint in sfdc. I amusing WSDL1.1 for my wsdl to create WSDL2Apex.

 

System.LimitException: @future call currently not allowed 

 

Any help is appreciated.

  • August 14, 2011
  • Like
  • 0

I am trying to display the data returned by the below query but not successfull, 

 

SELECT ID,Name, (SELECT Opportunity.amount FROM OpportunityContactRoles Order BY Opportunity.CloseDate DESC Limit 1 ) FROM Contact Where Lead_Source_Contact__c ='abc'

 

How can I display opportunity.amount using visualforce ?

 

<apex:pageBlockTable value="{!searchResults}" var="o" rendered="{!NOT(ISNULL(searchResults))}">                    <apex:column headerValue="Name">               

        <apex:outputLink value="/{!o.Id}">{!o.Name}</apex:outputLink>      

         </apex:column>                   

  <apex:column value="{!OpportunityContactRoles.Opportunity.amount}"/> I am getting error message  Error: Unknown property 'VisualforceArrayList.Opportunity'

 

 

</apex:pageBlockTable>

 

TIA!!!!

 

Hi,

 

I have deleted 2 classes in my sandbox instance that where from a package. I didn´t need these classes so I deleted both.

 

Is there any way to do the same via eclipse for my production org?

 

I have tried to deactivate these classes but I am getting an error message and the debug log gives me no explanation for this.

Class cannot be saved inactive Salesforce

 

Is there any other way around?  I need to delete those classes in production as I am getting compile errors and many apex test errors that I no longer get in Sandbox after deletion

 

Thanks!!!

  • August 09, 2011
  • Like
  • 0

I am trying to write a trigger that will create a new opportunity when one is closed.

The code that I use is as follows:

 

trigger Recurring on Opportunity (after update)
{
    if (Opportunity.StageName == 'Closed Won')
    {
        Opportunity newOpp = new Opportunity (
                                    Account = 'TEST',
                                    StageName = 'Prospecting',
                                    Type = 'Existing Business');
        insert newOpp;
    }
}

I get two errors, one related to the IF statement and the other

related to setting the account.

 

Can someone suggest what are my mistakes and how I can correct them?

 

       Thx

trigger enrollcandidatetrigger on Enroll_Candidate__c(after delete, after insert, after update,after undelete)
{

Set<ID> enrollIds= new Set<ID>();
Boolean setError=false;
Enroll_Candidate__c[] coursedetails;
if(Trigger.IsDelete)
coursedetails=Trigger.old;

else
coursedetails=Trigger.new;

Set<ID> CourseId= new set<ID>();

for(Enroll_Candidate__c candidates:coursedetails)
{
CourseId.add(candidates.Course_Details__c);
}

Map<ID,Course_Details__c> coursedetailsforcandidates=new Map<ID,Course_Details__c>([Select Id, Booked_Slots__c, Total_Slots__c, (Select Id from Enroll_Candidates__r ) from Course_Details__c where Id in:CourseId]);

for(Enroll_Candidate__c candidates:[Select Id , Course_Details__c FROM Enroll_Candidate__c where  Course_Details__c in:coursedetailsforcandidates.keyset()])
enrollIds.add(candidates.ID);

for(Course_Details__c courses :coursedetailsforcandidates.values())
{
System.debug('The total seats in the map is :' + courses.Total_Slots__c + ' the ids populated is : ' + enrollIds.size());
if(courses.Total_Slots__c >= enrollIds.size())
    courses.Booked_Slots__c=enrollIds.size();
else
    setError = true;
}

if(setError)
     Trigger.new[0].addError('Booked seats should not be the same as the Total seats!!');
    
update coursedetailsforcandidates.values();
}

I have an Apex method that is marked as a remoteAction which is attempting to take two parameters: a Lead and a List of custom objects ("Custom_Object__c" isn't the real object's name, just changed to protect the innocent);

 

@RemoteAction
public static Boolean insertData(Lead l, List<Custom_Object__c> customObjects) {
   // insert the Lead
   insert l;
   // assign the lead Id to each custom object in the list
   for(Custom_Object__c c : customObjects) {
      c.Lead__c = l.Id
   }
   // insert the custom objects
   insert customObjects;
   // return true (just for example)
   return true;
}

 Over in Javascript, I'm calling this remoteAction with the following data:

// sample data
var lead = {
   FirstName = 'Test',
   LastName = 'Test',
   Company = 'Test',
   Email = 'test@test.com',
   Phone = '555 555 1212'
};
var customObjects = [
   {
      Custom_Field1__c = 'A',
      Custom_Field2__c = 'B'
   },
   {
      Custom_Field1__c = 'A',
      Custom_Field2__c = 'B'
   }
];
MyApexClass.insertData(lead, customObjects, function(result, event) {
   // this would be the callback mojo
});

This code will make it as far as the insertData method, but I get the following error:

 

Visualforce Remoting Exception: undefined

 

I tried changing the insertData method to take the second parameters as List<sObject> instead of List<Custom_Object__c> (and modded the code to use dynamic DML to support this), but then I get this error:

 

Visualforce Remoting Exception: Unable to determine SObject type: SObject.  Please provide an 'id' or 'sobjectType' value.

 

I interpret this error as needing to supply a 'sobjectType' property to either a) the elements in my "customObjects" array or b) the array itself. I've tried all of the following permutations but still get the same error:

 

// ... add the property to the element doesn't work
var customObjects = [
   {
      Custom_Field1__c = 'A',
      Custom_Field2__c = 'B',
      sobjectType = 'Custom_Object__c'
   },
   {
      Custom_Field1__c = 'A',
      Custom_Field2__c = 'B',
      sobjectType = 'Custom_Object__c'
   }
];

// add the property to the array doesn't work customObjects.sobjectType = 'Custom_Object__c'; // for fun, tried to indicate that it's a list, these don't work either customObjects.sobjectType = 'List<Custom_Object__c>'; customObjects.sobjectType = 'Custom_Object__c[]';

 

Can someone point me in the right direction here? Is there another way to specify the sobjectType property? Are there issues with multiple params on a remoteaction, or issues with collection-based params? 

I have an Apex method that is marked as a remoteAction which is attempting to take two parameters: a Lead and a List of custom objects ("Custom_Object__c" isn't the real object's name, just changed to protect the innocent);

 

@RemoteAction
public static Boolean insertData(Lead l, List<Custom_Object__c> customObjects) {
   // insert the Lead
   insert l;
   // assign the lead Id to each custom object in the list
   for(Custom_Object__c c : customObjects) {
      c.Lead__c = l.Id
   }
   // insert the custom objects
   insert customObjects;
   // return true (just for example)
   return true;
}

 Over in Javascript, I'm calling this remoteAction with the following data:

// sample data
var lead = {
   FirstName = 'Test',
   LastName = 'Test',
   Company = 'Test',
   Email = 'test@test.com',
   Phone = '555 555 1212'
};
var customObjects = [
   {
      Custom_Field1__c = 'A',
      Custom_Field2__c = 'B'
   },
   {
      Custom_Field1__c = 'A',
      Custom_Field2__c = 'B'
   }
];
MyApexClass.insertData(lead, customObjects, function(result, event) {
   // this would be the callback mojo
});

This code will make it as far as the insertData method, but I get the following error:

 

Visualforce Remoting Exception: undefined

 

I tried changing the insertData method to take the second parameters as List<sObject> instead of List<Custom_Object__c> (and modded the code to use dynamic DML to support this), but then I get this error:

 

Visualforce Remoting Exception: Unable to determine SObject type: SObject.  Please provide an 'id' or 'sobjectType' value.

 

I interpret this error as needing to supply a 'sobjectType' property to either a) the elements in my "customObjects" array or b) the array itself. I've tried all of the following permutations but still get the same error:

 

// ... add the property to the element doesn't work
var customObjects = [
   {
      Custom_Field1__c = 'A',
      Custom_Field2__c = 'B',
      sobjectType = 'Custom_Object__c'
   },
   {
      Custom_Field1__c = 'A',
      Custom_Field2__c = 'B',
      sobjectType = 'Custom_Object__c'
   }
];

// add the property to the array doesn't work customObjects.sobjectType = 'Custom_Object__c'; // for fun, tried to indicate that it's a list, these don't work either customObjects.sobjectType = 'List<Custom_Object__c>'; customObjects.sobjectType = 'Custom_Object__c[]';

 

Can someone point me in the right direction here? Is there another way to specify the sobjectType property? Are there issues with multiple params on a remoteaction, or issues with collection-based params? 

When JSON support was added in APEX, I was one of those guys who jumped up and down. Started using heavily for one of my integration project and everything was fine and dandy for couple week. Since yesterday, I have been noticing some weired behavior. The first time I noticed it, I thought it was one of those APEX issues I love to call "APEX weirdness" and hoped that it will fix itself (READ: getting fixed without us knowing). That hasn't happened. :(

 

Here is the issue. 

 

My JSON parsing code looks like this:

class SomeApexWrapper {

public static SomeApexWrapper getInstance(String jsonString)

JSONParser parser = JSON.createParser(jsonString);       

SomeApexWrapper w = (SomeApexWrapper) parser.readValueAs(SomeApexWrapper.class);

}

}

 

This code was working fine until two days ago. It stops working If I change any class that uses this class to parse json string. The error I get is "[Source: java.io.StringReader@21363a13; line: 1, column: 1] Don't know the type of the Apex object to deserialize"

 

Just saving the SomeApexWrapper  class again fixes the issue. 

 

Has anyone had/having this issue? Is there a permanent solution for this?

  • November 07, 2011
  • Like
  • 0

hi,

 

How to add of javascript into visualforcepage(opportunity)

 

thanks.

When a user clicks the new button the case tab I would like my visuaforce page to display the "default" layout for a one record type and display another layout (VF) for the other type.

 

Is there a way within VF to "bypass" the VF and display the default view of a record (based on record type/page layouts)?

I am using a Visualforce form page to gether information needed to quote our various types of products. Considering all of our various products, I only need to gather about 20 fields of information to define the required attributes to accurately quote any of them (limited example below). My challenge is that on a handful of attributes (fields) apply to any one product, and I do not want to be asking the user questions that do not apply to the product they want quoted.

 

How can I educate my one form to show or not show form fields based on a product code that is passed to the Visualforce form when it is generated?

 

I have looked at many Visualforce and apex samples, gone through the Componenet Reference, and attempted a number of approaches, but feel that I'm running in circles.

 

Record Type is not an appropriate choice, and dependint picklists would involve too many variables. I am hoping for some type of 'IF' or 'CASE' logic that is based on a table of include/exclude values for each product, but I am not sure how to make the IF or CASE piece work.

 

Thanks for your assistance.

 

<apex:page setup="false" showHeader="true" sidebar="true" standardController="Opportunity">
  <!-- Begin Default Content REMOVE THIS -->
    <apex:sectionHeader title="Request for Quote Questionnaire" subtitle="Complete **the following for a prompt and accurate quote for {!opportunity.Product_Code_List__c}"/>
    <!-- <apex:detail subject="{!opportunity.ownerId}" relatedList="false" title="false"/> -->
        <apex:form id="quoteRequestInfoForm">
            <apex:pageBlock title="quoteRequestInfo" mode="edit">
                <apex:pageBlockButtons >
                    <apex:commandButton action="{!save}" value="Save"/>
                    <apex:commandButton action="{!delete}" value="Delete"/>
                    <apex:commandButton action="{!cancel}" value="Cancel"/>
                    <apex:commandButton action="{!save}" value="Save and Request PM Assistance"/>
                    <apex:commandButton action="{!save}" value="Save and Submit Quote Request"/>
                </apex:pageBlockButtons>
                <apex:pageBlockSection columns="1">
                    <apex:inputField value="{!opportunity.Product_Code_List__c}"/>
                    <apex:inputField value="{!opportunity.Quote_Sub_Products__c}" />
                    <apex:inputField value="{!opportunity.QSmallest_Panel_Size__c}"/>
                    <apex:inputField value="{!opportunity.QHighest_Hole_Count__c}"/>
                    <apex:inputField value="{!opportunity.Q_Construction__c}" />
                    <apex:inputField value="{!opportunity.QCoppers__c}" />
                    <apex:inputField value="{!opportunity.QRequested_MCM__c}" />
                    <p>Additional Quote Instructions:</p>
                    <apex:inputTextarea cols="120" value="{!opportunity.Quote_Instructions__c}"/>
                </apex:pageBlockSection>
            </apex:pageBlock>
        </apex:form>
  <!-- End Default Content REMOVE THIS -->
</apex:page>

Hi buddy,

 

Could anyone tell me how to delete apex code on production? we are using UE. and i am admin. thanks.

 

 

Cheers

Atlantis

I have a trigger that captures the day and time a}n event was completed and then add that day/time to field on the Account Screen. I ran my tests in the Sandbox and got no errors and a 100% coverage. When I go to deploy it to production I get the following:

 

Failure Message: "System.QueryException: List has more than 1 row for assignment to SObject", Failure Stack Trace: "Class.OSC_Event_Test.myUnitTest: line 6, column 20 External entry point"

Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required

 

Here is my Trigger and Test Class

 

 

Trigger

trigger OSC_Activty_Event on Event (after update) {

for (Event updatedEvent : trigger.new) {
    for(Event olduEvent : trigger.old){
        if (updatedEvent.Sales_Call_Completed__c != olduEvent.Sales_Call_Completed__c){
            for(Account a : [SELECT id, Last_Sales_Call__c FROM Account WHERE Account.id = :updatedEvent.AccountId]){

 a.Last_Sales_Call__c = updatedEvent.Completed_Date_Time__c;
  update a;

  }}}}

 Test Class

@isTestprivate class OSC_Event_Test {
    static testMethod void myUnitTest() {       

 

Event ev = [Select id,Sales_Call_Completed__c from Event where Sales_Call_Completed__c = 'No'];       

ev.Sales_Call_Completed__c = 'Yes'; ev.All_Communities_Objective__c = 'Sell a Paid Model';       

try{       

update ev;         

//System.assertEquals('This is a test');        }       

catch(System.DmlException e){           

 System.debug('we caught a dml exception: ' + e.getDmlMessage(0));        

}    }}

  • August 14, 2011
  • Like
  • 0

Hi All,

 

I have a inputText field in a VF page and I need to disable paste function(Ctrl+v and paste using mouse button) so that we need to compulsorily type in the text box instead of just copy pasting.

 

I have tried the following script:

<script>

function DisableCtrlKey(e)
{
    var code = (document.all) ? event.keyCode:e.which;
    // look for CTRL key press
    if (parseInt(code)==17)
    {
        alert("Please re-type your email address");
        window.event.returnValue = false;
    }
}

function DisableRightClick(event)
{
    //For mouse right click
    if (event.button==2)
    {
        alert("Please re-type your email address");       
    }
}

</script>

 and under the VF page:

<apex:inputText id="confirmemail" value="{!email}" onKeyDown="return DisableCtrlKey(event)" onMouseDown="DisableRightClick(event)" </apex:inputText>

 It works fine but I want to implement the same functionality without using alert function.

 

Can anyone please let me know any work around to accomplish the above scenario.

Any help on this will be highly appreciated.

 

 

 

Can I have an Workflow rule Email Notification on Opportunity Line Item.

 

I tried to create one , but I didnt able to find the Line Item fields in the Field Type values.

 

Can any one let me know.

  • August 14, 2011
  • Like
  • 0

I am getting the following error when i tried to make a callout to SAP webservice.

 

I have registered my endpoint in sfdc. I amusing WSDL1.1 for my wsdl to create WSDL2Apex.

 

System.LimitException: @future call currently not allowed 

 

Any help is appreciated.

  • August 14, 2011
  • Like
  • 0

I am trying to display the data returned by the below query but not successfull, 

 

SELECT ID,Name, (SELECT Opportunity.amount FROM OpportunityContactRoles Order BY Opportunity.CloseDate DESC Limit 1 ) FROM Contact Where Lead_Source_Contact__c ='abc'

 

How can I display opportunity.amount using visualforce ?

 

<apex:pageBlockTable value="{!searchResults}" var="o" rendered="{!NOT(ISNULL(searchResults))}">                    <apex:column headerValue="Name">               

        <apex:outputLink value="/{!o.Id}">{!o.Name}</apex:outputLink>      

         </apex:column>                   

  <apex:column value="{!OpportunityContactRoles.Opportunity.amount}"/> I am getting error message  Error: Unknown property 'VisualforceArrayList.Opportunity'

 

 

</apex:pageBlockTable>

 

TIA!!!!

 

I am trying to write a trigger that will create a new opportunity when one is closed.

The code that I use is as follows:

 

trigger Recurring on Opportunity (after update)
{
    if (Opportunity.StageName == 'Closed Won')
    {
        Opportunity newOpp = new Opportunity (
                                    Account = 'TEST',
                                    StageName = 'Prospecting',
                                    Type = 'Existing Business');
        insert newOpp;
    }
}

I get two errors, one related to the IF statement and the other

related to setting the account.

 

Can someone suggest what are my mistakes and how I can correct them?

 

       Thx

trigger enrollcandidatetrigger on Enroll_Candidate__c(after delete, after insert, after update,after undelete)
{

Set<ID> enrollIds= new Set<ID>();
Boolean setError=false;
Enroll_Candidate__c[] coursedetails;
if(Trigger.IsDelete)
coursedetails=Trigger.old;

else
coursedetails=Trigger.new;

Set<ID> CourseId= new set<ID>();

for(Enroll_Candidate__c candidates:coursedetails)
{
CourseId.add(candidates.Course_Details__c);
}

Map<ID,Course_Details__c> coursedetailsforcandidates=new Map<ID,Course_Details__c>([Select Id, Booked_Slots__c, Total_Slots__c, (Select Id from Enroll_Candidates__r ) from Course_Details__c where Id in:CourseId]);

for(Enroll_Candidate__c candidates:[Select Id , Course_Details__c FROM Enroll_Candidate__c where  Course_Details__c in:coursedetailsforcandidates.keyset()])
enrollIds.add(candidates.ID);

for(Course_Details__c courses :coursedetailsforcandidates.values())
{
System.debug('The total seats in the map is :' + courses.Total_Slots__c + ' the ids populated is : ' + enrollIds.size());
if(courses.Total_Slots__c >= enrollIds.size())
    courses.Booked_Slots__c=enrollIds.size();
else
    setError = true;
}

if(setError)
     Trigger.new[0].addError('Booked seats should not be the same as the Total seats!!');
    
update coursedetailsforcandidates.values();
}