• zachelrath
  • NEWBIE
  • 265 Points
  • Member since 2011

  • Chatter
    Feed
  • 10
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 55
    Replies

I've encountered a customers sandbox where the standard "Save" and "Save & New" buttons have been replaced by a "Save & Add Brand" button on the standard new opportunity page. They have renamed Opportunity Line Items as Brands and have renamed the Products tab as such.

 

When pressed, the button saves the Opportunity (after validation of required fields etc...) and then redirects the user to a custom Visualforce page for entering the Brand details. The Visualforce Page they arrive on is configured as the override for Opportunity Product standard button AddProduct.

 

Salesforce New Opportunity Page with custom Save Button

 

How has the "Save & Add Brand" button been added to the New Opportunity page to replace the standard buttons?

 

I need to add some additional buttons but can't find where it has been configured.

 

Under Customize > Opportunities > Buttons and Links > Standard Buttons and Links New is not showing any override. Also, if I add ?nooveride=1 to the URL I get the same page with the custom button. Edit has been overridden but that Visualforce page isn't the one being displayed to new (as expected).

 

There is no Detail Page Button on Opportunity with a label corresponding to this button.

 

The same question appears on Stack Overflow.

I'd like to add a link to a custom report that's included in our managed package to a visualforce page (also packaged) but I'm hesitant to do so because it just uses a hard-coded ID link. I've seem to recall reading something way back when that report IDs were automatically swapped out upon package installation for object links, but I'm doubtful that will be the case for visualforce pages.


It would be ideal if this idea were delivered:

https://sites.secure.force.com/success/ideaView?id=08730000000bRreAAE

 

Does anyone have any experience linking to packaged reports?

 

Thanks,

Chuck

  • February 16, 2012
  • Like
  • 0

Dear All,

 

I have Batch apex Class and Schedulable class.  I am looking for the syntax to call the Batch apex class from the trigger or calling the schedulale class from Trigger, which inturn calls the Batch apex.

 

Thanks in Advance!

  • September 21, 2011
  • Like
  • 0

I have two kinds of use cases for triggers in a timesheet system that I've developed which I don't currently know how to implement, at least in a scalable fashion that won't run into governor limits.

 

In general, I don't know what's the best way to trigger events based on the status of multiple records of the same type, all related to a master record.

 

Use Case 1:

 

I want to have a report that shows when an intern has submitted a timesheet two weeks in a row which has 0 hours recorded on it.

 

The need for this is that people can take vacations from their work, but we need to be have flagged when people are away for longer than 5 days, so we can follow up with them specifically about it. Most of the interns work off-site so without the timesheets we wouldn't know.

 

I'm presuming to do this I need some sort of trigger that sets a flag on a timesheet record when it is the second week in a row of 0 hours. The total hours on a timesheet is a formula field which totals up all the hours that they entered on the timesheet.

 

I have a custom controller extension on the Visualforce page, so potentially I could do this in the save method, by looking at the total for the previous week as well. Or would the formula not be calculated yet at that point?

 

Alternatively, I could use a trigger on insert & update, but I am concerned that I'd run into governor limits. I don't know how I'd structure the queries to run in bulk.

 

Use Case 2:

 

I want to send out emails when interns are 2 weeks behind on submitting timesheets, or their site directors are 4 weeks behind in approving them.

 

I have reports already on the Timesheet Master object which is the master for the Timesheet object, that look at a formula field that looks in turn at rollup summaries of the statuses on the timesheets.

 

However, I think formula fields are automatically calculated so I don't think I can have the triggers be on the Timesheet Master and be set to send out an email if Member Weeks Behind >= 2 or Site Director Weeks Behind >= 4.

 

I need to have these time-based, so would I have to create some sort of scheduled apex job that runs each day and looks at the Current Date vs. the Member Start Date (which is a field on their Contact record, which is linked via the Timesheet Master to the Timesheet), and sends out an email to the member or site director if the difference is too great?

 

Alternatively, is there some sort of time-based workflow I could use here? That would be simpler if it were possible.

I could give as much more detail about our setup as is necessary, if it would be helpful to you.

In this test code, how do I assign rows to the object? Here is the error?

 

	System.QueryException: List has no rows for assignment to SObject	

Class.CloneOpportunityLineItems.CloneOpportunityLineItems: line 51, column 28 

Class.TestCloneOpportunityLineItems.basicSaveTest: line 31, column 32 External entry point

 

Test Code:

@IsTest private class TestCloneOpportunityLineItems{

    /* This is a basic test which simulates the primary positive case for the 
       save method in the quoteExt class. */
    public static testmethod void basicSaveTest() {

        /* Create an account */
        Account a = new Account();
        a.name    = 'TEST';
        Database.insert(a);

        /* Get a valid stage name */
        OpportunityStage stage = [select MasterLabel from OpportunityStage limit 1];

        /* Setup a basic opportunity */
        Opportunity o  = new Opportunity();
        o.Name         = 'TEST';
        o.AccountId    = a.id;
        o.CloseDate    = Date.today();
        o.StageName    = stage.masterlabel;
        Database.insert(o);

        /* Construct the standard controller for quote. */
        ApexPages.StandardController con = new ApexPages.StandardController(o);

        /* Switch to runtime context */
        Test.startTest();

        /* Construct the CustomOpp class */
       CloneOpportunityLineItems ext = new CloneOpportunityLineItems(con);
        
        PageReference result = ext.CloneOpportunityLineItems();

        /* Switch back to test context */
        Test.stopTest();
    }

    /* This setup method will create an opportunity with line items and a primary
       contact role for use in various tests. */
    private static Opportunity setupTestOpportunity() {

        /* Create an account */
        Account a = new Account();
        a.name    = 'TEST';
        Database.insert(a);

        /* Get the FY12 Global Price Book pricebook.  */
        
        Pricebook2 pb = [select id, name from PriceBook2 
            where name ='FY12 Global Price Book'];
           

        if(!pb.isactive) {
            pb.isactive = true;
            Database.update(pb);
        }
        
        Product2 pr = [select id from product2 limit 1];
        
        Pricebookentry pbe = [select id, CurrencyIsoCode, product2id, Pricebook2id
            from PriceBookEntry where Pricebook2id =: pb.id ];

        /* Get a valid stage name */
        OpportunityStage stage = [select MasterLabel from OpportunityStage limit 1];

        /* Setup a basic opportunity */
        Opportunity o  = new Opportunity();
        o.Name         = 'TEST';
        o.AccountId    = a.id;
        o.CloseDate    = Date.today();
        o.StageName    = stage.masterlabel;
        o.Pricebook2Id = pb.id;

        /* Create the opportunity */
        Database.insert(o);


        return o;
    }
}

 

Apex Class:

 

public class CloneOpportunityLineItems{

    private ApexPages.StandardController controller {get; set;}
    private Opportunity o {get;set;}
    public ID oid {get; set;}
         
    List<OpportunitylineItem> newOliList = new List<OpportunitylineItem>();
    
    List<OpportunityLineItem> newOLI = new List<OpportunityLineItem>([select id, pricebookentryid from OpportunityLineItem]);
    
    id FY12 = [select id from Pricebook2 where name = 'FY12 Global Price Book'].id;
    
    public CloneOpportunityLineItems(ApexPages.StandardController c) {
        o = (opportunity) c.getRecord();

        oid = System.currentpageReference().getParameters().get('oppid');

    }
  
    public PageReference CloneOpportunityLineItems() {
        Savepoint sp = Database.setSavepoint();
        
        List<OpportunitylineItem> oli = [select id, PriceBookEntry.Product2Id, PricebookEntry.Name, PriceBookEntry.id, Quantity,
            OpportunityId, TotalPrice, Cost_Each__c, Quote_Item_Number__c,UnitPrice,
            PriceBookEntry.PriceBook2id from OpportunityLineItem where Opportunityid =:oid];

        Map<ID, OpportunitylineItem> PRODMap = new Map<ID, OpportunitylineItem>();
 
                
        for(OpportunitylineItem ol : oli) {

            PRODMap.put(ol.PriceBookEntry.Product2id, ol);
  
        }
       
       system.debug('##############oli list is:' + oli);
       newOliList = oli;  
       system.debug('%%%%%%%%%%%%%%%' + oli);
              
       delete oli;
       
       system.debug('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$' + newOliList);
       
       String[] pbenames = new String[]{};    // added by sfdc support; string list to store the pbe names from the old OLI's 
       
       for(OpportunityLineItem ol: newOliList){
           pbenames.add(ol.PricebookEntry.Name);    // Populating the list
           
       }
    
          Opportunity op = [select id, currencyisocode, Pricebook2.name from Opportunity where id =:oid limit 1];
      
          List<PricebookEntry> pbe = [select id, name, CurrencyIsoCode  from PriceBookEntry where
                                  Pricebook2id =: FY12 and Product2.id in: ProdMap.keySet() and
                                  currencyisocode =: op.currencyisocode];   
          
          Map<String, id> PbidAndNamesMap = new Map<String, id>();   // Added by sfdc support - Map to store pbe names and ids from the new query         
          
          for(PricebookEntry p: pbe){
              PbidAndNamesMap.put(p.Name, p.id);        // Populating the PbidAndNamesMap
          }
              
                            
      If(op.Pricebook2.name <> 'FY12 Global Price Book'){
          op.PriceBook2id = FY12;
      }
      update op;
     

    system.debug('***SFDC TEST ***************'+newOLI[0]);
    
    List<OpportunityLineItem> items = new List<OpportunityLineItem>();
    system.debug('##################### newOliList: ' + newOliList);
    
    Integer idx = 0;
    
    for(OpportunityLineItem ol : newOliList){

         OpportunityLineItem newOl = new OpportunityLineItem();
                          
           newOl.PricebookEntryId = PbidAndNamesMap.get(pbenames[idx]);    // Extracting the pbe ids based on the names from the PbidAndNamesMap and resolving the issue
           newOl.quantity = ol.quantity;
           newOl.OpportunityID = ol.OpportunityId;
           newOl.Cost_Each__c = ol.Cost_Each__c;
           newOl.UnitPrice = ol.UnitPrice;
           newOl.Quote_Item_Number__c = ol.Quote_Item_Number__c;
           items.add(newOl);
                               
           idx= idx+1;
}
 
               if(items.size() > 0)
                   system.debug('***items***************'+items);
                   insert items;
  
    PageReference pageRef = new PageReference('/' + oid);
    
     return pageref;

    }
}

 

Thank you,
ckellie

Hello

 

I need to get a list of cases where two conditions are met, hence my question, can I use the AND operator in a SOQL, such as here:

 

List<Case> c = new List<Case> ();
        c = [SELECT Id,CaseNumber,OwnerId FROM Case WHERE AccountId = :a.Id AND IsClosed = FALSE];

 

Thank you

Marc

 

  • August 17, 2011
  • Like
  • 0

Hi all,

 

I've been pouring over the boards here trying to figure out why I can't get my trigger to create a detail record on master record creation.

 

Master Record = Policy__c

Detail Record = Transaction__c

 

Error message when trying to save trigger:

Error: Compile Error: Incorrect SObject type: Policy__c should be Transaction__c at line 1 column 1

 

Trigger code:

trigger createTransaction on Policy__c (after insert) {

    List<Transaction__c> addTA = new List<Transaction__c>();
    for (Policy__c p : Trigger.new)
    {
        Transaction__c t = new Transaction__c();
        t.Related_Policy__c = p.Id;
        addTA.add(t);
    }
    insert addTA;
}

I sincerely appreciate any guidance.

  • August 17, 2011
  • Like
  • 0

Basically..

If Opporuntiy showroom is Lake Forest use the email template with the id of 123456

If Opporuntiy showroom is Hosuton use the email template with the id of 987456

If Opporuntiy Showroom is Lake Forest but created by profile Id 8520 then use email template id 4560

If Opporuntiy Showroom is Houston but created by profile Id 8520 then use email template id 4560

 

Here is what my Case statement look like now

 

template_id={!CASE( Opportunity.Showroom__c  ,
'Lake Forest','00X30000001AGI9',
 'Houston','00X30000001AGWW',
'00X300000017004')}

  • August 17, 2011
  • Like
  • 0

Ive searched around to find that reflection isnt avaible in Apex. Now Im pretty sure thats what I need to accomplish what I am going ask, but if there is another way to accomplish this, any help would be appreciated!

 

My app creates two custom fields on opportunity.

 

campaign_start_date__c

campaign_end_date__c

 

If in the case that a customer that installs my app already has two custom date fields on opportunity I would like them to be able to specify using thier custom fields.

 

Ive setup a custom setting that allows them to input the name of the custom fields.

 

I would like to pull from that custom setting and use their custom fields. So.... something like this...

 

 // Get customer Campaign start date and end date field names from Custom Setting x_conf__c 
 x_conf__c getConf = x_conf__c.getInstance('settings'); 
            
 // Get start date field name
 string campStartDateFieldName = string.valueOf(getConf.campaign_start_date_field_name__c);
 string csd = campStartDateFieldName;


// Get start date field name
 string campEndDateFieldName = string.valueOf(getConf.campaign_start_date_field_name__c);
 string esd = campEndDateFieldName;

string xCampaignStartDate = o.+csd;
string xCampaignStartDate = o.+esd;

 

Now I realize this doesnt work... But is there a way to accomplish what I am trying to do here?

 

Thanks!

  • August 17, 2011
  • Like
  • 0

I am using a dummy Opportunity object's closedate to use the datepicker functionality.  I've used this technique (as recommended by JWetzler)  many times without any problems.  However, I have a VF page where the two datepicker fields do not display in some user's screens.  When I login, the VF page displays both datepicker fields.  When I log in as another user, they don't display.  Inspecting the second user's page, it shows <td></td> (i.e. empty) where both datepickers are supposed to be displayed.  The system has a sharing model and the User has full access to the Account and read/write to the Opportunity.

VF Page:

            <tr >
                <td style="font-weight:bold;">
                    <apex:outputText >From: </apex:outputText>
                </td>
                <td >
                    <apex:inputField value="{!stDate.CloseDate}" />
                </td>
                <td style="font-weight:bold;">
                    <apex:outputText >To: </apex:outputText>
                </td>
                <td>
                    <apex:inputField value="{!enDate.CloseDate}"/>
                </td>

            </tr>

Controller:

	public Opportunity stDate			{get;set;}
	public Opportunity enDate			{get;set;}

	stDate = new Opportunity(closeDate = date.newInstance(date.today().year(),1,1));
	enDate = new Opportunity(closeDate = date.today());

 

 

  • June 06, 2011
  • Like
  • 0
I am using version 33.0 of the JavaScript AJAX Toolkit (/soap/ajax/33.0/connection.js), and am making a describeLayout() call. I am trying to retrieve a limited subset of the describeLayout metadata --- specifically, just the recordTypeMappings for a few specific Record Types. There are no examples in the AJAX Toolkit documentation of doing this, but it (mostly) works and is documented in the API docs (http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_describelayout.htm) (with different syntax, which is worrying as well).

Here's my basic call --- I get the describeLayout for the Account object, but pass in 3 Record Type Ids:
 
var result = sforce.connection.describeLayout('Account',["012G0000000jVOmIAM","012G0000000jdgIIAQ","012G0000000jVOhIAM"]);
This returns a valid payload, but what's weird is that it only returns recordTypeMappings for the last 2 Record Types I requested, not 3! If I request 2 Record Types, it returns recordTypeMappings for just the last Record Type I requested! And when I request it for just 1 Record Type, it returns ALL Record Type mappings. 

User-added image

So my question is, is this the way it is supposed to be working? Or is this a bug?

I have just created an Apex Class that implements the InstallHandler interface, and have associated it with a managed package. However, when I install my package, the SObject.put(SObjectField f, Object value) are throwing a "Field is not editable" SObjectException. I found this strange, since the error is being thrown before I even do DML --- i.e. the actual put() call is throwing the error. I thought this must be a Field-Level Security issue, so I made sure that the System Admin profile (both in my package development org, and in the org into which I am installing my package) has read/write access to the field in question. But I still get the error.

 

Digging deeper, I did some debug output  in my install script on the Schema information for the field in question and sent it to myself in an email. To my surprise, the field was not even accessible, much less editable! I then checked accessibility of the object. Again, isAccessible() returned FALSE! So I checked some other objects --- same thing. Contact, Account, Contact.LastName, Account.Name --- isAccessible() for all of these fields/objects returns FALSE. 

 

Am I missing something? Is this just a bug in the Schema information? Or do InstallHandlers really not have access to any objects/fields? This can't be possible.

 

here is the code:

 

global abstract class InstallScript implements InstallHandler {

	// The module that we will be installing
	protected String moduleName;

	// Set the name of the module associated with this package install 
	global abstract void setModule();
	
	// Any additional on install logic should be defined in this method
	global abstract void onInstallLogic(InstallContext ctx);

	global void onInstall(InstallContext ctx) {
		// Set the module that we are running in
		setModule();
		
		if (moduleName != null) {
			
			// See if a StaticResource containing new pages for this module yet exists
			StaticResource sr;
			try {
				sr = [select Id, Body, Name, NamespacePrefix from StaticResource where Name = :(moduleName + 'Pages')];
			} catch (Exception ex) {
				// No pages exist for this module
			}
			if (sr != null) {
				String username,profileId,accessible,createable,updateable,localname,name,body,debugString;
				DescribeFieldResult dfr;
				SObjectField f;
				try {
					username = UserInfo.getUserName();
					profileId = UserInfo.getProfileId();
					f = Page__c.Layout__c;
					dfr = f.getDescribe();
					accessible = dfr.isAccessible() + '';
					createable = dfr.isCreateable() + '';
					updateable = dfr.isUpdateable() + '';
					localname = dfr.getLocalName();
					name = dfr.getName();
					body = sr.Body.toString();
					
					debugString = 
						'Username: ' + ((username != null) ? username : 'null') 
						+ 'ProfileId: ' + ((profileId != null) ? profileId : 'null')
						+ ', Contact.Accessible: ' + Contact.SObjectType.getDescribe().isAccessible()
						+ ', Contact.LastName.Accessible: ' + Contact.LastName.getDescribe().isAccessible()
						+ ', Page__c.Accessible: ' + Page__c.SObjectType.getDescribe().isAccessible()
						+ ', Page__c.Name.Accessible: ' + Page__c.Name.getDescribe().isAccessible()
						+ ', Layout__c.Accessible: ' + accessible
						+ ', Layout__c.Createable: ' + createable
						+ ', Layout__c.Updateable: ' + updateable
						+ ', Layout__c.getLocalName: ' + localname
						+ ', Layout__c.getName: ' + name
						+ ', body: ' + body;
                               } catch (Exception ex) {

                                    // Send email
                               }
                         }
                   }
             }
}

The actual InstallScript is a simple implementation of the abstract class. The important thing to note is that all of the isAccessible() calls are returning FALSE.

 

I received the same results in both API versions 24 and 25.

 

Any ideas?

 

Zach McElrath

Skoodat LLC

Just to set the context, my use case is: programmatically scheduling Scheduled Apex Jobs from other pieces of Apex code.

 

I know that there is a limit on the number of Scheduled APEX Jobs (i.e. scheduled executions of Apex classes implementing the Schedulable interface), but I'm having trouble figuring out a way to distinguish between APEX Scheduled Jobs and all other Scheduled Jobs (i.e. Scheduled Report/Dashboard Refreshes) using a query on the CronTrigger object. Right now I have the following:

 

public static final Integer MAX_SCHEDULED_APEX_JOBS = 10; 
	
// Determine whether the maximum number of Scheduled APEX Jobs has been reached
public static Boolean MaxScheduledJobsReached() {
   return (GetScheduledJobs().size() >= MAX_SCHEDULED_APEX_JOBS) ;
}
	
// Returns all Scheduled Apex jobs that have not been started yet 
public static List<CronTrigger> GetScheduledJobs() {
   return [select Id, NextFireTime 
	   from CronTrigger 
           where State in ('WAITING','ACQUIRED','EXECUTING')
            or NextFireTime != NULL];
}	

The problem is that this returns Dashboard and Report Refreshes as well. How do I weed-out Report and Dashboard Refresh Jobs from this query?

 

I thought of adopting a naming convention for Jobs, i.e. whenever I programmatically Schedule an Apex Job, I name it something like 'ApexJob__' etc, but if there were other Scheduled Apex Jobs scheduled that I didn't create, this wouldn't work.

 

Looking at the Scheduled Jobs page in the UI (i.e. Administration Setup > Monitoring > Scheduled Jobs), there's a Type field displayed that is not accessible through the CronTrigger API object. If only it was!!! This would be super helpful.

 

Any suggestions???

 

Thanks!

Zach McElrath

Skoodat LLC

 

 

 

We are trying to load in SObject data from Visualforce EXCLUSIVELY using JavaScript remoting. Which means, of course, that we are NOT leveraging the apex:outputField component at all. Which means, according to the Salesforce Help Docs, that Encrypted Fields cannot be used, because the only Visualforce component that supports them (i.e. that returns the value of an Encrypted Field in Masked Form) is apex:outputField.

 

Any ideas on how to circumvent this?

 

I tested this out using a simple VF page:

 

<apex:page standardController="Contact">
    <apex:outputField value="{!Contact.SSN__c}"/><br/>
    <apex:outputText value="{!Contact.SSN__c}"/> <br/>
    <apex:outputText value="{!Contact.SSN__c}" escape="false"/>
</apex:page>

 

Only the outputField returns the Masked Value. 

 

Can someone explain to me why querying the value of ANY field, let alone ENCRYPTED fields, would display differently in an apex:outputText on a page with a Standard Controller than it would in an Execute Anonymous call? If I run this in Execute Anonymous:

 

Contact tim = [select id, SSN__c from Contact where Name = 'Tim Barr' limit 1];

// Displays Masked Value: ***-**-6789
System.debug(tim.SSN__c);

the masked value is displayed. But when I run the above VF page with outputText the field is NOT masked. This seems very inconsistent to me... after all, the same user is executing both transactions! And, by the way, how is the apex:outputText component acquiring its data if not through the same channels as Apex code?

 

Is there a way in Apex to take a given XML file and verify that it is valid according to any XSD schemas that it uses? Will any of the various Apex XML parsing classes (i.e. XMLStreamReader, Dom.Document, Ron Hess' XMLDom, or Abhinav Gupta's Fast XML DOM) provide any sort of "validation" that a given XML string that gets loaded into a DOM representation actually conforms to any of its referenced Schemas? Or are there web services for XML validation that any devs know of that I could do a callout to?

 

Thanks!

 

Zach McElrath 

When requesting an access token from https://login.salesforce.com/services/oauth2/token, I get the response:

 

unknown error, please retry your request

 

I seem to be making a well-formatted request with proper credentials, but I get this mysterious error.  Has anybody seen this and can anybody help?

 

Many thanks,

MagneticDisk

I've encountered a customers sandbox where the standard "Save" and "Save & New" buttons have been replaced by a "Save & Add Brand" button on the standard new opportunity page. They have renamed Opportunity Line Items as Brands and have renamed the Products tab as such.

 

When pressed, the button saves the Opportunity (after validation of required fields etc...) and then redirects the user to a custom Visualforce page for entering the Brand details. The Visualforce Page they arrive on is configured as the override for Opportunity Product standard button AddProduct.

 

Salesforce New Opportunity Page with custom Save Button

 

How has the "Save & Add Brand" button been added to the New Opportunity page to replace the standard buttons?

 

I need to add some additional buttons but can't find where it has been configured.

 

Under Customize > Opportunities > Buttons and Links > Standard Buttons and Links New is not showing any override. Also, if I add ?nooveride=1 to the URL I get the same page with the custom button. Edit has been overridden but that Visualforce page isn't the one being displayed to new (as expected).

 

There is no Detail Page Button on Opportunity with a label corresponding to this button.

 

The same question appears on Stack Overflow.

Hello,

 

I've run into an issue that I believe to be a bug. I'm receiving an error on the submit of a form in a Visualforce page. The error is:

 

"Insufficient Privileges: You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary. "

 

The page is an unmanaged page, the controller is an unmanaged custom controller that extends a managed custom controller that is global virtual. I'm able to reproduce the error on submit when the extended controller has only 3 lines of code and one custom method that does not override anything from the managed controller. It's also worth noting that the page loads and constructor of the managed controller, via the extended controller fires just fine, without issue.

 

I've reproduced the error in a sandbox with a super-simple example. There is a controller called altController and a VF page called payment3. The page loads, and when clicking submit, you get the insufficient privileges error, which makes no sense.

 

Extended Controller: 

global with sharing class altController extends gwop.PaymentPageController {
   global pagereference doNada() {
       return null;
   }
}
 

 

Visualforce page:

<apex:page controller="altController" title="Online Payments from Groundwire" showHeader="true" >
  <apex:form >
      <apex:commandButton value="Submit" action="{!doNada}" />
  </apex:form>
</apex:page>

 

The page loads, runs the constructor without error. Clicking the button gives this:

 

Insufficient PrivilegesYou do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary. 

 

If I take out the extends gwop.PaymentPageController at top, of course, no more error on Submit.  Similarly, if I extend another global class from a different managed package, no error on submit:

 

global with sharing class altController extends gwbase.ONEN_CTRL_LeadConverter {
   global pagereference doNada() {
       return null;
   }
}

 

Also – appears to have nothing to do with permissions, as WITHOUT SHARING makes no difference.  And of course, the same code works fine if the page is contained within the same package as the controller.

 

I've enabled Salesforce support to access this sandbox instance by granting login access. Here is the Org Id:

Org Id: 00DW0000000HPkd

 

This problem is replicable in multiple instances using this managed package and I'd be glad to reproduce it in more than one place.

 

I have created a case in the partner portal, Case #: 07311941

 

Any help is appreciated. This is obviously a huge issue if we are to customize and extend code from a managed package, which is a very common scenario for consultants who customize their managed packages for clients.

 

Thanks,
Dave Manelski

I'd like to add a link to a custom report that's included in our managed package to a visualforce page (also packaged) but I'm hesitant to do so because it just uses a hard-coded ID link. I've seem to recall reading something way back when that report IDs were automatically swapped out upon package installation for object links, but I'm doubtful that will be the case for visualforce pages.


It would be ideal if this idea were delivered:

https://sites.secure.force.com/success/ideaView?id=08730000000bRreAAE

 

Does anyone have any experience linking to packaged reports?

 

Thanks,

Chuck

  • February 16, 2012
  • Like
  • 0

Just to set the context, my use case is: programmatically scheduling Scheduled Apex Jobs from other pieces of Apex code.

 

I know that there is a limit on the number of Scheduled APEX Jobs (i.e. scheduled executions of Apex classes implementing the Schedulable interface), but I'm having trouble figuring out a way to distinguish between APEX Scheduled Jobs and all other Scheduled Jobs (i.e. Scheduled Report/Dashboard Refreshes) using a query on the CronTrigger object. Right now I have the following:

 

public static final Integer MAX_SCHEDULED_APEX_JOBS = 10; 
	
// Determine whether the maximum number of Scheduled APEX Jobs has been reached
public static Boolean MaxScheduledJobsReached() {
   return (GetScheduledJobs().size() >= MAX_SCHEDULED_APEX_JOBS) ;
}
	
// Returns all Scheduled Apex jobs that have not been started yet 
public static List<CronTrigger> GetScheduledJobs() {
   return [select Id, NextFireTime 
	   from CronTrigger 
           where State in ('WAITING','ACQUIRED','EXECUTING')
            or NextFireTime != NULL];
}	

The problem is that this returns Dashboard and Report Refreshes as well. How do I weed-out Report and Dashboard Refresh Jobs from this query?

 

I thought of adopting a naming convention for Jobs, i.e. whenever I programmatically Schedule an Apex Job, I name it something like 'ApexJob__' etc, but if there were other Scheduled Apex Jobs scheduled that I didn't create, this wouldn't work.

 

Looking at the Scheduled Jobs page in the UI (i.e. Administration Setup > Monitoring > Scheduled Jobs), there's a Type field displayed that is not accessible through the CronTrigger API object. If only it was!!! This would be super helpful.

 

Any suggestions???

 

Thanks!

Zach McElrath

Skoodat LLC

 

 

 

Hi,

 

I have written a trigger that creates a Task when a CampaignMember attends a specific event. The trigger works great and I am now writing my Test Method so that I can implement this code in our live org, however I am not a coder and not sure how to achieve this.

 

I have written a couple of triggers recently along with the Test Methods and received some excellent help from this board.

 

Below is the trigger and Test Method I need help with so any advice is much appreciated.

 

 

trigger PowerOf3 on CampaignMember (after insert, after update) {
    Set<Id> contactIds = new Set<Id>();

    for (CampaignMember cm : trigger.new){
        contactIds.add(cm.ContactId);
    }
    List<Contact> contacts = [
        SELECT Id, AccountId, OwnerId, Contact.Account.Id, Contact.Account.Name, Contact.Owner.Id
, Contact.Owner.Name
        FROM Contact 
        WHERE Id in :contactIds
    ];
    Map<String, Contact> contactMap = new Map<String, Contact>();
    for (Contact contact : contacts){
        contactMap.put(contact.Id, contact);
    }
    for (CampaignMember cm : trigger.new){
        Contact currentContact = contactMap.get(cm.ContactId);
        String campaignId = cm.CampaignId;
        String powerOf3Id = '701R0000000AJPBIA4';
        if (campaignId == powerOf3Id){
            if (cm.Status == 'Attended'){
                Task task = new Task();
                task.RecordTypeId = '012R00000004lckIAA';
                //Contact contact = [SELECT Id,AccountId,OwnerId FROM Contact WHERE Id = :cm.ContactId];
                task.WhoId = cm.ContactId;
                task.WhatId = cm.CampaignId;
                task.Priority = 'Normal';
                task.Status = 'Not Started';
                task.Subject = 'Power of 3 Follow Up';
                task.Type = 'Call - outbound';
                //Account account = [SELECT Id,Name FROM Account WHERE Id = :contact.AccountId];
                task.Client_Account_Name__c = currentContact.account.Name;
                //User user = [SELECT Id,Name FROM User WHERE Id = :contact.OwnerId];
                task.Contact_Owner__c = currentContact.owner.Name;
                String mappedUserId = '';
                if (currentContact.owner.Id == '00530000000gSl9'){
                    mappedUserId = '00530000000kvVm';                    
                } else if (currentContact.owner.Id == '00530000000kvVm'){
                    mappedUserId = '00530000000kvVm';
                } else if (currentContact.owner.Id == '00530000000iMq2'){
                    mappedUserId = '00530000000lcQ1';
                } else if (currentContact.owner.Id == '00530000000lcQ1'){
                    mappedUserId = '00530000000lcQ1';
                } else if (currentContact.owner.Id == '00530000000i4Dg'){
                    mappedUserId = '00550000001Cjog';
                } else if (currentContact.owner.Id == '00550000001Cjog'){
                    mappedUserId = '00550000001Cjog';
                } else if (currentContact.owner.Id == '00530000000i4Dt'){
                    mappedUserId = '00550000001Cjog';
                } else if (currentContact.owner.Id == '00530000000i4D4'){
                    mappedUserId = '00550000000mez5';
                } else if (currentContact.owner.Id == '00550000000mez5'){
                    mappedUserId = '00550000000mez5';
                } else {
                    mappedUserId = '00550000000mFkK';
                }
                task.OwnerId = mappedUserId;
                upsert task;
            }
        }   
    }
}

 

@isTest
private class PowerOf3Test{
    static testMethod void PowerOf3Test(){

    //Set up the User record
    User u = new User(Firstname='Test',LastName='Test',Username='test.test@test.com',Email='test.test@test.com',Alias='ttest',CommunityNickname='test.test',TimeZoneSidKey='GMT',LocaleSidKey='en_GB',EmailEncodingKey='ISO-8859-1',ProfileId='00e50000000yyaB',LanguageLocaleKey='en_US');
    insert u;

    //Set up the Contact record
    Contact c = new Contact(Firstname='Test',LastName='Test');
    insert c;

    //Set up the Campaign record
    Campaign cg = new Campaign(Name='Test');
    insert cg;

    //Set up the CampaignMember record
    CampaignMember cm = new CampaignMember(CampaignId = cg.id,ContactId=c.id,Status='Sent');
    upsert cm;
    
    //Set up the Task record
    Task t = new Task(Subject = 'Test');
    upsert t;
    
    //Cause the Trigger to execute
    cm.Status='Attended';
    upsert cm;

    //Verify that the results are as expected
    Contact c2 = [SELECT Id,AccountId,OwnerId FROM Contact WHERE Id=:cm.ContactId];
    Campaign cg2 = [SELECT Id FROM Campaign WHERE Id=:cg.Id];
    CampaignMember cm2 = [SELECT ContactId,CampaignId,Status FROM CampaignMember WHERE ContactId=:c.Id];
    public List<Task> gettask() {
        return [SELECT RecordTypeId,WhoId,WhatId,Priority,Status,Subject,Type,Client_Account_Name__c,Contact_Owner__c,OwnerId FROM Task WHERE RecordTypeId='012R00000004lckIAA' AND WhoId=:c.Id];
    }
    String mappedUserId='';
    if(c2.Id=='00530000000gSl9'){
        mappedUserId='00530000000kvVm';
    } else if (c2.Id=='00530000000kvVm'){
        mappedUserId='00530000000kvVm';
    } else if (c2.Id=='00530000000iMq2'){
        mappedUserId='00530000000lcQ1';
    } else if (c2.Id=='00530000000lcQ1'){
        mappedUserId='00530000000lcQ1';
    } else if (c2.Id=='00530000000i4Dg'){
        mappedUserId='00550000001Cjog';
    } else if (c2.Id=='00550000001Cjog'){
        mappedUserId='00550000001Cjog';
    } else if (c2.Id=='00530000000i4Dt'){
        mappedUserId='00550000001Cjog';
    } else if (c2.Id=='00530000000i4D4'){
        mappedUserId='00550000000mez5';
    } else if (c2.Id=='00550000000mez5'){
        mappedUserId='00550000000mez5';
    } else {
        mappedUserId='00550000000mFkK';
    }
    System.assertEquals(t2.RecordTypeId,'012R00000004lckIAA');
    System.assertEquals(t2.WhoId,c2.Id);
    System.assertEquals(t2.WhatId,cg2.Id);
    System.assertEquals(t2.Priority,'Normal');
    System.assertEquals(t2.Status,'Not Started');
    System.assertEquals(t2.Subject,'Power of 3 Follow Up');
    System.assertEquals(t2.Type,'Call - outbound');
    System.assertEquals(t2.Client_Account_Name__c,c2.AccountId);
    System.assertEquals(t2.Contact_Owner__c,c2.OwnerId);
    System.assertEquals(t2.OwnerId,mappedUserId);
    }
}

 Can anyone advise me on how the Test Method should be made please?

 

Thanks,

 

Marco

I have a batch job

 

global class xyz  implements Database.Batchable<Sobject>  { 

}

 

I want to run it immidiately witiout running it as an apex job.Since,its takes some time to start execution, when I run it as an Apex job. How can I run it real-time ?

 

Thanks in advance!

 

  • September 27, 2011
  • Like
  • 0

Hi,

 

I have this situation.

 

I have a mapping table call SourceDetail__c.  It has RecordTypeId__c, LeadSubType__c, SourceDetailName__c.  I try to read the entire table into a Map.  Say it's a small table with 1000 rows.

 

Map<Id, SourceDetail__c> mSourceDetail = NEW Map<Id, SourceDetail__c>([SELECT RecordTypeId__c, LeadSubtype__c, SourceDetailName__c FROM SourceDetail__c]);

 

Will the Map key contain the RecordTypeId__c value from the SourceDetail__c table?

 

I try to use the following codes to see if it contains the RecordTypeId__c key from the table, but it returns null.

 

Boolean contains = mSourceDetail.containsKey('012V00000008U7h');

System.assertEquals(contains, True);

 

If I cannot do this, may you suggest a solution for my situation?

 

When I import leads, I need to update Lead Subtype field with value from the SourceDetail__c table base on the inserted lead RecordTypeId and Source Detail value.  In other word the SourceDetail__c table contains all the mapping values to Lead Subtype with RecordTypeId and SourceDetailName being the matching keys.

 

How do I address this in a bulkifiable manner?

 

I was thinking read all the SourceDetail__c into a Map<Id, SourceDetail__c> where Id is the RecordTypeId from this mapping table.

 

Then in the FOR(Lead l : TRIGGER.NEW), I match with the Map.  But the Map seems not contain the RecordTypeId as I wanted.  What can I do differently?

 

Thanks,

Brian

 

  • September 27, 2011
  • Like
  • 0

Hi, I am an administrator rather than a developer and i am trying to create a trigger that will automatically create a case (i.e. a case is created at 1st of every month) Can anyone help with me with the code for this or advice?

Many Thanks

Is there a way in Apex to take a given XML file and verify that it is valid according to any XSD schemas that it uses? Will any of the various Apex XML parsing classes (i.e. XMLStreamReader, Dom.Document, Ron Hess' XMLDom, or Abhinav Gupta's Fast XML DOM) provide any sort of "validation" that a given XML string that gets loaded into a DOM representation actually conforms to any of its referenced Schemas? Or are there web services for XML validation that any devs know of that I could do a callout to?

 

Thanks!

 

Zach McElrath 

While the API docs have a lot of great examples using cURL, I don't see an example of how to actually obtain the access token. I tried the following with no joy:

 

 

curl grant_type=authorization_code \
  client_id=MY-CONSUMER-KEY \
  client_secret=MY-CONSUMER-SECRET \
  https://na5.salesforce.com/services/oath2/token

 

 

Thanks

 

Jeff Douglas

Appirio, Inc.

http://blog.jeffdouglas.com

 

Author: The Salesforce Handbook

How can I determine the URL of a static resource from my Apex code?

 

I'm looking for the equivalent of the VisualForce $Resource variable, but one that I can use from with Apex code.

 

Thanks!

  • February 28, 2009
  • Like
  • 0
Given a contract I can get a list of attached Notes and Attachments using the following queries:

[SELECT Id, Name FROM Attachment WHERE ParentId=:contract.Id]
[SELECT Id, Title FROM Note WHERE ParentId=:contract.Id]

I combed through the schema and api documentation and I've been unable to find a way to retrieve a list of attached Google Docs.

Any Idea's?