• aam1r
  • NEWBIE
  • 25 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 21
    Replies
I have two clases:
1. a controller class to a vf page and another as
2. a helper class accessed by multple classes. 

I have a simple query running in the helper class that is failing to return any records:
...
public static void refreshOrder(Id orderId, Id accountId){

        // Retrieve the Order
        Order ord = [Select Id, Name, Status From Order Where Id = :orderId];

...
The controller class that calls the above method has the following extract:
...

Order order = new Order(
    Pricebook2Id = OrderHelper.getStandardPriceBookId(),
    Status = ORDER_STATUS_PENDING_PAYMENT, 
    AccountId = acc.Id
    EffectiveDate = System.today(),
    CurrencyIsoCode=pkgCurrencyCode
 );
        
 insert order;

OrderHelper.refreshOrder(order.Id, acc.Id);
...
Any idea why a system.debug in the helper class does show a valid Order Id being apssed but then the simple order query does not return anything, and instead throws an error:
"List has no rows for assignment to SObject" ?
 
  • January 24, 2020
  • Like
  • 0
Hi, I hope someone can point me in the right direction here.

I'm facing an issue with a SIte Guest User unable to insert a record via VF pages and Controller.  I have tracked the issue down to an insert of a custom object record - in my case Booking__c.  Its quite a large class, which i'm not going to paste here.  

The Booking object has a lookup to Contact and Order objects and also a custom Event, with the latter being a M-D relationship.  I have checked the CRUD for thsi user's profile and it has View All and Modifiy all for Booking and Event and it has as much access as can be granted for Contacts and Orders (being Standard objects).  I have granted this user's Field-Level securty (accessibility) read and edit on each of teh above mentioned objects.

However, when i get to the of..
insert booking;
in my code, i get:
Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []
And i haven't a clue what coudl be wrong.  Coincidently, this issue suddenly arose in our sandbox last weekend when Spring 20 came about, however i was also developing at the time so its a stale-mate situation right now.

Any pointers would be great.

Thanks
Aamir

 
  • January 09, 2020
  • Like
  • 0
Hi Guys,

This may be something i kick myself with (and i hope it is) but i have a simple query in my apex code and i cannot understand why it has started failing for a specific site guest user.  Here's an extract form my class that contains the query:
// Retrieve the Order
System.debug('*** Ref: orderId = ' + orderId);
System.debug('*** Current user = ' + [select name from user where id = :userinfo.getuserid()].name);

Order ord = [Select Id, Name, Status From Order Where Id = :orderId];
I'm leaving the debug steps in here so we can see the debug logs:
USER_DEBUG|[106]|DEBUG|*** Ref: orderId = 8013N000000YSUoQAO
SOQL_EXECUTE_BEGIN|[107]|Aggregations:0|SELECT name FROM user WHERE id = :tmpVar1
SOQL_EXECUTE_END|[107]|Rows:1
USER_DEBUG|[107]|DEBUG|*** Current user = Site Guest User
SOQL_EXECUTE_BEGIN|[108]|Aggregations:0|SELECT Id, Name, Status FROM Order WHERE Id = :tmpVar1
SOQL_EXECUTE_END|[108]|Rows:0
SYSTEM_MODE_EXIT|false
FATAL_ERROR|System.QueryException: List has no rows for assignment to SObject
Now, looking in Salesforce, the record id for Order 8013N000000YSUoQAO does exist.  it has created by and owner as Site Guest User.  If i change the query on the order to be without the where clause for the order id and execute the same steps then i do get a number of Order IDs returned.  if i run teh query as anonymous, it works fine.  If i run the same steps for system admin it works fine. I have checked to make sure teh Site Guest User has CRUD access to Order  object and it does.

Either i've worked on this project too long and intensivley that i cannot see the obvious or something else is missing that i'm not catching.

Can someone please make a suggestion please?

Thanks
Aamir
 
  • January 05, 2020
  • Like
  • 0
Hi everyone,

I hope you are able to help me out here.  I currently have a Visualforce page with an iframe that displays a third-party form.  Upon completion of this form i get a success message within the iframe and a button that say Finish.  The Finish button is programmed to redirect to a URL (a visualfofrce page) stored on a field on a record.  However, this redirect does not happen.

I've been told that using PostMessage, along with an event listener to trap events will help me resolve this but i'm unable to figure out how to code this.

My Visualforce page outputPanel is as follows:
<apex:outputPanel layout="block" id="aContainer" style="width: 500px; height: 1000px; margin: 0 auto;">
          <apex:outputtext escape="false" value="{!APayForm}"></apex:outputtext>
          <apex:iframe width="100%" height="1000px" src="" scrolling="true" id="paymentFrame" frameborder="false"/>
          <script>
                    document.getElementById('APayForm').submit();
          </script>
</apex:outputPanel>
The APayForm is built dynamically usinga controller and teh following is an example of what is returned and used in teh outputPanel value above;
// example: <form target="paymentFrame" action="https://test.protected.net/PMWeb1?pRef=1837&amp;pid=a233N0000008SgR" method="post" id="APayForm" >
The Cancel button on teh form returns and event 'a--cancel' and the finish button retruns and event 'a--exit'.  how can use these events to redirct to the same visualforce page called 'PostPayment', which renders a message according to the status of a parent record.  The PostPayment page renders correctly but i'm unable to redirect to it.

Can someone help me figure out the code required for the postMessage and event listener (also where this is to be coded) please?
 
  • December 06, 2019
  • Like
  • 0
Is there an easy way to count how many times some text or substring appears in an apex string variable?  So if a a varibale holds "The quick brown fox jumps over the lazy dog"  i want to find how many times fox appears in this string.
  • November 13, 2019
  • Like
  • 0
Hi, I've exported all teh notes from an Org and want to import them as ContentNotes (Enhanced Notes).  The problem i'm facing is that the export csv file contains the notes along with all other system fields as expected.  However, when i want to import into ContentNotes the Content field is expecting a directory path to an individual file (eg. txt) and does not accept a simple field mapping.  How can i work around this?  Is there a way of exporting Notes as txt files?
  • January 12, 2017
  • Like
  • 0
Hi Guys, 

I know its another one, but i've looked at similar issues to see if i can identify the cause of my code coverage failure but have not found anything.  So, i'm getting 0% code coverage for a new trigger and cannot see why.  Here is my Trigger:
 
trigger MilestoneTaskTrigger on MPM4_BASE__Milestone1_Task__c (before insert, before update) {

if ((Trigger.isBefore && Trigger.isInsert) || (Trigger.isBefore && Trigger.isUpdate)){


	// Create list to hold Milestone Components to update
	List<Milestone_Component__c> components = new List<Milestone_Component__c>();

	// Get list of all Milestone Components that are set in Prod but not in Test
	List<Milestone_Component__c> cmps = [SELECT Id FROM Milestone_Component__c WHERE PROD__c = True AND Test_Sandbox__c = False];

	for (Milestone_Component__c c : cmps){
		c.Test_Sandbox__c = True;
		components.add(c);
	}

	for (MPM4_BASE__Milestone1_Task__c task : System.Trigger.new){
		// Is Refresh Test checked
		if (task.Refresh_Test__c == True && task.MPM4_BASE__Complete__c == True){
			// update all milestone components
			update components;

			// unset Resfresh Test checkbox
			task.Refresh_Test__c = False;
		}
	}
}

}

And here's my test class:
 
@isTest
public with sharing class MilestoneTaskTriggerTest {
	static testMethod void  MilestoneTaskTriggerTest() {
		
		// Insert Project
		System.debug('Inserting Milestone Project');
        MPM4_BASE__Milestone1_Project__c project = new MPM4_BASE__Milestone1_Project__c (Name='DEVELOPMENT');
        try { insert project; } catch (exception e) {}

        // get Salesforce Project record type for Milestone? - Nah!! default record type will be used.
        
        // Insert Milestone
        System.debug('Inserting Milestone');
        MPM4_BASE__Milestone1_Milestone__c milestone = new MPM4_BASE__Milestone1_Milestone__c(Name='Milestone', MPM4_BASE__Project__c=project.id);
        try { insert milestone; } catch (exception e) {}
		
		// Insert Task
		System.debug('Inserting Task');
        MPM4_BASE__Milestone1_Task__c task = new MPM4_BASE__Milestone1_Task__c(Name='Task', MPM4_BASE__Priority__c='4 - Low');
        try { insert task; } catch (exception e) {}

		// Insert Components (x3)
		System.debug('Inserting Components');
        Component__c component1 = new Component__c(Name='Comp1');
        try { insert component1; } catch (exception e) {}

        Component__c component2 = new Component__c(Name='Comp2');
        try { insert component2; } catch (exception e) {}

        Component__c component3 = new Component__c(Name='Comp3');
        try { insert component3; } catch (exception e) {}

        Component__c component4 = new Component__c(Name='Comp4');
        try { insert component4; } catch (exception e) {}

		// Insert Milestone Components (x3) setting Prod in one of them and 2 in test
		System.debug('Inserting Milestone Components');
        Milestone_Component__c mscomponent1 = new Milestone_Component__c(SFDC_Component__c=component1.id, Test_Sandbox__c=False, PROD__c=TRUE, Milestone__c=milestone.id, Task__c=task.id, Action__c='Update');
        try { insert mscomponent1; } catch (exception e) {}

        Milestone_Component__c mscomponent2 = new Milestone_Component__c(SFDC_Component__c=component2.id, Test_Sandbox__c=TRUE, PROD__c=False, Milestone__c=milestone.id, Task__c=task.id, Action__c='Update');
        try { insert mscomponent2; } catch (exception e) {}

        Milestone_Component__c mscomponent3 = new Milestone_Component__c(SFDC_Component__c=component3.id, Test_Sandbox__c=TRUE, PROD__c=False, Milestone__c=milestone.id, Task__c=task.id, Action__c='Update');
        try { insert mscomponent3; } catch (exception e) {}

        Milestone_Component__c mscomponent4 = new Milestone_Component__c(SFDC_Component__c=component4.id, Test_Sandbox__c=False, PROD__c=False, Milestone__c=milestone.id, Task__c=task.id, Action__c='Update');
        try { insert mscomponent4; } catch (exception e) {}

		// Update Task.Refresh_Test__c to true and set task to complete
		System.debug('Updating Task');
        task.Refresh_Test__c = TRUE;
        task.MPM4_BASE__Complete__c = TRUE;
        try { update task; } catch (exception e) {}

		// Check that there are 3 Milestone Components flagged as in Test
		List<Milestone_Component__c> mscomponents = [SELECT Id FROM Milestone_Component__c WHERE Test_Sandbox__c = TRUE];
		System.assertEquals(false, mscomponents.size()==3, ' there should be only 3 milestone components with Test Sandbox set as true');

		// Check that the Refresh_Test__c flag is false now.
		MPM4_BASE__Milestone1_Task__c checktask = [SELECT Id, Refresh_Test__c FROM MPM4_BASE__Milestone1_Task__c WHERE Id = :task.id];
		System.assertEquals(false, checktask.Refresh_Test__c==False, ' Refresh Test flag should be false!');

	}
}

Any help is greatly appreciated.
Thanks
Aamir
  • June 22, 2016
  • Like
  • 0
Hi Everyone,

Requirement: Capture Find Duplicates button click event on Lead records

Current Solution: I currently have a Javascript button that checks a box on a Lead record when it is clicked and directs the page to the leadmergewizard.jsp page.  Here is the Javascript begind the button currently:
 
{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")}

var ld = new sforce.SObject("Lead");
ld.Id = '{!Lead.Id}';
ld.Duplicate_Searched__c = 1;

var result = sforce.connection.update([ld]);
if(result[0].getBoolean("success"))
{
window.location = "/lead/leadmergewizard.jsp?retURL=%2F{!Lead.Id}&id={!Lead.Id}&00Ne0000001OKhg=1";
}
else{
alert('Error : '+result);
}

New Solution needed: The above setup works fine, however i want to implement something that does this via Global Action so i can have this functionality on mobile and also Lightneing Experience.

Is this possible, and can someone guide me with any sample code if i need to implement this using triggers, classes and/or vf pages?

Many thanks for your help.
aamir
 
  • May 25, 2016
  • Like
  • 0
Hi, I am trying to use a record lookup to return a list of Accounts that are of certain record types (say 'Local' and 'National').  I can easliy do this for either 'Local' or 'National' but cannot find a way of including both except to list every type and set Record Type not equal to (all the rest of Record types). Essentially, i'm after an OR condition / logic for my setup in Flow.  Here is what i'm trying to achieve but it doesn't work:

User-added image

Any help is greatly appreciated.

Aamir
  • April 20, 2016
  • Like
  • 0
Hi, i'm trying to record the start of day date/time value for a given Business Hour as part of an Apex trigger but not sure of the way to do this.  Can someone help me try and achieve this please? The basic logc is to check what day it is today and then record the Start of Day date/time in to a field  (Start_of_Day__c) for that same day defined for the Business Hour.

Thanks
  • March 07, 2016
  • Like
  • 0
I have two clases:
1. a controller class to a vf page and another as
2. a helper class accessed by multple classes. 

I have a simple query running in the helper class that is failing to return any records:
...
public static void refreshOrder(Id orderId, Id accountId){

        // Retrieve the Order
        Order ord = [Select Id, Name, Status From Order Where Id = :orderId];

...
The controller class that calls the above method has the following extract:
...

Order order = new Order(
    Pricebook2Id = OrderHelper.getStandardPriceBookId(),
    Status = ORDER_STATUS_PENDING_PAYMENT, 
    AccountId = acc.Id
    EffectiveDate = System.today(),
    CurrencyIsoCode=pkgCurrencyCode
 );
        
 insert order;

OrderHelper.refreshOrder(order.Id, acc.Id);
...
Any idea why a system.debug in the helper class does show a valid Order Id being apssed but then the simple order query does not return anything, and instead throws an error:
"List has no rows for assignment to SObject" ?
 
  • January 24, 2020
  • Like
  • 0
Hi Guys,

This may be something i kick myself with (and i hope it is) but i have a simple query in my apex code and i cannot understand why it has started failing for a specific site guest user.  Here's an extract form my class that contains the query:
// Retrieve the Order
System.debug('*** Ref: orderId = ' + orderId);
System.debug('*** Current user = ' + [select name from user where id = :userinfo.getuserid()].name);

Order ord = [Select Id, Name, Status From Order Where Id = :orderId];
I'm leaving the debug steps in here so we can see the debug logs:
USER_DEBUG|[106]|DEBUG|*** Ref: orderId = 8013N000000YSUoQAO
SOQL_EXECUTE_BEGIN|[107]|Aggregations:0|SELECT name FROM user WHERE id = :tmpVar1
SOQL_EXECUTE_END|[107]|Rows:1
USER_DEBUG|[107]|DEBUG|*** Current user = Site Guest User
SOQL_EXECUTE_BEGIN|[108]|Aggregations:0|SELECT Id, Name, Status FROM Order WHERE Id = :tmpVar1
SOQL_EXECUTE_END|[108]|Rows:0
SYSTEM_MODE_EXIT|false
FATAL_ERROR|System.QueryException: List has no rows for assignment to SObject
Now, looking in Salesforce, the record id for Order 8013N000000YSUoQAO does exist.  it has created by and owner as Site Guest User.  If i change the query on the order to be without the where clause for the order id and execute the same steps then i do get a number of Order IDs returned.  if i run teh query as anonymous, it works fine.  If i run the same steps for system admin it works fine. I have checked to make sure teh Site Guest User has CRUD access to Order  object and it does.

Either i've worked on this project too long and intensivley that i cannot see the obvious or something else is missing that i'm not catching.

Can someone please make a suggestion please?

Thanks
Aamir
 
  • January 05, 2020
  • Like
  • 0
Hi everyone,

I hope you are able to help me out here.  I currently have a Visualforce page with an iframe that displays a third-party form.  Upon completion of this form i get a success message within the iframe and a button that say Finish.  The Finish button is programmed to redirect to a URL (a visualfofrce page) stored on a field on a record.  However, this redirect does not happen.

I've been told that using PostMessage, along with an event listener to trap events will help me resolve this but i'm unable to figure out how to code this.

My Visualforce page outputPanel is as follows:
<apex:outputPanel layout="block" id="aContainer" style="width: 500px; height: 1000px; margin: 0 auto;">
          <apex:outputtext escape="false" value="{!APayForm}"></apex:outputtext>
          <apex:iframe width="100%" height="1000px" src="" scrolling="true" id="paymentFrame" frameborder="false"/>
          <script>
                    document.getElementById('APayForm').submit();
          </script>
</apex:outputPanel>
The APayForm is built dynamically usinga controller and teh following is an example of what is returned and used in teh outputPanel value above;
// example: <form target="paymentFrame" action="https://test.protected.net/PMWeb1?pRef=1837&amp;pid=a233N0000008SgR" method="post" id="APayForm" >
The Cancel button on teh form returns and event 'a--cancel' and the finish button retruns and event 'a--exit'.  how can use these events to redirct to the same visualforce page called 'PostPayment', which renders a message according to the status of a parent record.  The PostPayment page renders correctly but i'm unable to redirect to it.

Can someone help me figure out the code required for the postMessage and event listener (also where this is to be coded) please?
 
  • December 06, 2019
  • Like
  • 0
Is there an easy way to count how many times some text or substring appears in an apex string variable?  So if a a varibale holds "The quick brown fox jumps over the lazy dog"  i want to find how many times fox appears in this string.
  • November 13, 2019
  • Like
  • 0
Hi, I've exported all teh notes from an Org and want to import them as ContentNotes (Enhanced Notes).  The problem i'm facing is that the export csv file contains the notes along with all other system fields as expected.  However, when i want to import into ContentNotes the Content field is expecting a directory path to an individual file (eg. txt) and does not accept a simple field mapping.  How can i work around this?  Is there a way of exporting Notes as txt files?
  • January 12, 2017
  • Like
  • 0
Hi Guys, 

I know its another one, but i've looked at similar issues to see if i can identify the cause of my code coverage failure but have not found anything.  So, i'm getting 0% code coverage for a new trigger and cannot see why.  Here is my Trigger:
 
trigger MilestoneTaskTrigger on MPM4_BASE__Milestone1_Task__c (before insert, before update) {

if ((Trigger.isBefore && Trigger.isInsert) || (Trigger.isBefore && Trigger.isUpdate)){


	// Create list to hold Milestone Components to update
	List<Milestone_Component__c> components = new List<Milestone_Component__c>();

	// Get list of all Milestone Components that are set in Prod but not in Test
	List<Milestone_Component__c> cmps = [SELECT Id FROM Milestone_Component__c WHERE PROD__c = True AND Test_Sandbox__c = False];

	for (Milestone_Component__c c : cmps){
		c.Test_Sandbox__c = True;
		components.add(c);
	}

	for (MPM4_BASE__Milestone1_Task__c task : System.Trigger.new){
		// Is Refresh Test checked
		if (task.Refresh_Test__c == True && task.MPM4_BASE__Complete__c == True){
			// update all milestone components
			update components;

			// unset Resfresh Test checkbox
			task.Refresh_Test__c = False;
		}
	}
}

}

And here's my test class:
 
@isTest
public with sharing class MilestoneTaskTriggerTest {
	static testMethod void  MilestoneTaskTriggerTest() {
		
		// Insert Project
		System.debug('Inserting Milestone Project');
        MPM4_BASE__Milestone1_Project__c project = new MPM4_BASE__Milestone1_Project__c (Name='DEVELOPMENT');
        try { insert project; } catch (exception e) {}

        // get Salesforce Project record type for Milestone? - Nah!! default record type will be used.
        
        // Insert Milestone
        System.debug('Inserting Milestone');
        MPM4_BASE__Milestone1_Milestone__c milestone = new MPM4_BASE__Milestone1_Milestone__c(Name='Milestone', MPM4_BASE__Project__c=project.id);
        try { insert milestone; } catch (exception e) {}
		
		// Insert Task
		System.debug('Inserting Task');
        MPM4_BASE__Milestone1_Task__c task = new MPM4_BASE__Milestone1_Task__c(Name='Task', MPM4_BASE__Priority__c='4 - Low');
        try { insert task; } catch (exception e) {}

		// Insert Components (x3)
		System.debug('Inserting Components');
        Component__c component1 = new Component__c(Name='Comp1');
        try { insert component1; } catch (exception e) {}

        Component__c component2 = new Component__c(Name='Comp2');
        try { insert component2; } catch (exception e) {}

        Component__c component3 = new Component__c(Name='Comp3');
        try { insert component3; } catch (exception e) {}

        Component__c component4 = new Component__c(Name='Comp4');
        try { insert component4; } catch (exception e) {}

		// Insert Milestone Components (x3) setting Prod in one of them and 2 in test
		System.debug('Inserting Milestone Components');
        Milestone_Component__c mscomponent1 = new Milestone_Component__c(SFDC_Component__c=component1.id, Test_Sandbox__c=False, PROD__c=TRUE, Milestone__c=milestone.id, Task__c=task.id, Action__c='Update');
        try { insert mscomponent1; } catch (exception e) {}

        Milestone_Component__c mscomponent2 = new Milestone_Component__c(SFDC_Component__c=component2.id, Test_Sandbox__c=TRUE, PROD__c=False, Milestone__c=milestone.id, Task__c=task.id, Action__c='Update');
        try { insert mscomponent2; } catch (exception e) {}

        Milestone_Component__c mscomponent3 = new Milestone_Component__c(SFDC_Component__c=component3.id, Test_Sandbox__c=TRUE, PROD__c=False, Milestone__c=milestone.id, Task__c=task.id, Action__c='Update');
        try { insert mscomponent3; } catch (exception e) {}

        Milestone_Component__c mscomponent4 = new Milestone_Component__c(SFDC_Component__c=component4.id, Test_Sandbox__c=False, PROD__c=False, Milestone__c=milestone.id, Task__c=task.id, Action__c='Update');
        try { insert mscomponent4; } catch (exception e) {}

		// Update Task.Refresh_Test__c to true and set task to complete
		System.debug('Updating Task');
        task.Refresh_Test__c = TRUE;
        task.MPM4_BASE__Complete__c = TRUE;
        try { update task; } catch (exception e) {}

		// Check that there are 3 Milestone Components flagged as in Test
		List<Milestone_Component__c> mscomponents = [SELECT Id FROM Milestone_Component__c WHERE Test_Sandbox__c = TRUE];
		System.assertEquals(false, mscomponents.size()==3, ' there should be only 3 milestone components with Test Sandbox set as true');

		// Check that the Refresh_Test__c flag is false now.
		MPM4_BASE__Milestone1_Task__c checktask = [SELECT Id, Refresh_Test__c FROM MPM4_BASE__Milestone1_Task__c WHERE Id = :task.id];
		System.assertEquals(false, checktask.Refresh_Test__c==False, ' Refresh Test flag should be false!');

	}
}

Any help is greatly appreciated.
Thanks
Aamir
  • June 22, 2016
  • Like
  • 0
Hi, i'm trying to record the start of day date/time value for a given Business Hour as part of an Apex trigger but not sure of the way to do this.  Can someone help me try and achieve this please? The basic logc is to check what day it is today and then record the Start of Day date/time in to a field  (Start_of_Day__c) for that same day defined for the Business Hour.

Thanks
  • March 07, 2016
  • Like
  • 0
Any idea how to move old notes to the new enhanced notes and maintain the original owner/creator and date/time?
Challenge Description:
  • Upload a specified zip file as a static resource. The zip will have directories with images and you have to display a specific image on a Visualforce page.The page must be named 'ShowImage'.
  • This file must be uploaded as a Static Resource named 'vfimagetest'.
  • The page must have a Visualforce apex:image tag that displays the 'kitten1.jpg' image from the 'cats' directory of the static resource.

Screenshot of Visualforce Page:
User-added image
Screenshot of Resource Page:
User-added image

Screenshot of page preview:
User-added image

Exact text of error:
Challenge not yet complete... here's what's wrong: 
The page does not include a reference to the specified image

Can't figure out whats wrong, everything looks like its working perfectly and I used the examples in the module as a base for the code.