• jeffdonthemic2
  • NEWBIE
  • 385 Points
  • Member since 2009

  • Chatter
    Feed
  • 15
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 94
    Replies

Hi -

 

Travel__c custom Object is the related list under Opportunity. When i try to grab the AccountId from Opportunity using child relationship the value is coming as null. When i query the same in Apex explorer i am getting the results.

 

Please advise what is wrong here?

 

 

trigger test_sample on Travel__c (after update,after insert) 
{
    if(trigger.isAfter)
    {
        if(trigger.isUpdate)        
{ for(Travel__c t:Trigger.new) { system.debug('Opportunity AccountId Value '+t.Opportunity__r.Account.Id); } } } }

 

 

 

hi,

 

i am new to this test classes concept. Can anybody give an example for writing a test class for a controller.

 

public PageReference psignup() {
    emailerror=false;
        emailacept=false;
        List<guestuser__c> ldtls=[select Id from guestuser__c where Email__c=:email];
        
        if(ldtls.size()>0)
        {
            emailerror=true;
            emailacept=false;
            //uid exist
        }
        else
        {
            if(pwd==rpwd)
            {
                emailerror=false;
                emailacept=false;
                guestuser__c gu=new guestuser__c();
                gu.First_Name__c=fname;
                gu.Password__c=pwd;
                gu.Email__c=email;
                gu.Title__c = job;
                gu.Email_Optout__c = echeck;
                gu.Last_Name__c = lname;
                gu.Company__c = comp;
                gu.Street__c = street;
                gu.State__c = state;
                gu.City__c = city;
                gu.Country__c = ctry;
                gu.Zipcode__c = zip;
                
                
                Lead ld=new Lead();          
                ld.FirstName =fname;
                ld.LastName=lname;
                ld.Company=comp;
                ld.Street=street;
                ld.State=state;
                ld.city=city;
                ld.PostalCode=zip;
                ld.country=ctry;
                ld.Title=job;
                ld.Email=email;
                ld.HasOptedOutOfEmail=echeck;
                
                
                try{
                insert ld;
                insert gu;
                Pagereference pageref=new Pagereference('/apex/thankq');     
                    pageref.setRedirect(true);
                    return pageref;
                }
                catch(Exception e)
                {
                    system.debug(e);
                }
            }
            else
            {
                ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.WARNING, 'PASSWORD MISS-MATCH');
                ApexPages.addMessage(myMsg);
            }
        }
        return null;
    }


    public Boolean echeck { get; set; }

    public String rpwd { get; set; }

    public String pwd { get; set; }

    public void checkavlble() {
        String lusername= Apexpages.currentPage().getParameters().get('mail');
        List<guestuser__c> chkldtls=[select Id from guestuser__c where Email__c=:email];
        if(chkldtls.size()>0)
        {
            emailerror=true;
            emailacept=false;
        }
        else
        {           //try another
            emailerror=false;
            emailacept=true;
        }
    }


    public Boolean emailacept { get; set; }

    public Boolean emailerror { get; set; }

    public String email { get; set; }

    public String job { get; set; }

    public String ctry { get; set; }

    public String zip { get; set; }

    public String state { get; set; }

    public String city { get; set; }

    public String street { get; set; }

    public String comp { get; set; }

    public String lname { get; set; }

    public String fname { get; set; }
}

 

i need to write the test class for this controller to deploy the page.can anybody help me with an example. 

 

I'm trying to make a simple notification for non-SF users that is triggered by creation or updating of a case. The first problem I ran into was a null object error on the following code:

 

trigger newCaseToCustomerService on Case (after insert, after update) {
Case myCase = trigger.new[0];
Account myAccount = myCase.Account;
User myOwner = myCase.Owner;
String CRLF = '\r\n'
String msgbody;

if(myAccount.BillingCountry == 'Denmark'){
//code here
}
}

 when SF is inserting or updating the Case, why would the Account or Owner be null since they are set in the case properties? I noticed from the other messages asking help for the null object issues that a common approach was to use SOSQL query to access related objects but I don't quite get it why is that?

 

My second question is about the Messaging -class: Does the Apex Email Class allow setting the Priority -flag on outbound, single messages?

I would like to refresh my Sandbox but before doing so want to save all the Classes and Pages I have been experimenting with.

 

Would appreciate a high check list of the steps I need to follow to ensure Sandbox classes and pages are securely saved (on a network drive) and how I could later import these into a refreshed Sandbox or Developer Org?

 

 

  • July 15, 2010
  • Like
  • 0

I can't tell why this isn't working...

 

Is there a way to add a de-bugging method to the trigger to see what is happening? 

 

How do I know if the first few definitions (particularly of the list "list_relatedstudents" isn't null after I try to define it; then when I go to update the list with "update list_relatedstudents" nothing happens)?

 

 

trigger Bulk_CallLogs on Student_Call_Log__c (after insert, after update) { list<Student_Call_Log__c> list_thelogs = new list<Student_Call_Log__c>(); // list contains all of the logs being processed // Step 1 set <id> list_relatedstudents_temp = new set <id> (); for (Student_Call_Log__c log :list_thelogs) { list_relatedstudents_temp.add(log.related_student__c); } list<Student__c> list_relatedstudents = ([select id, Most_Recent_Call_Note__c, Tech_Support_Logs__c, Call_Count__c from Student__c where id IN :list_relatedstudents_temp]); // Step 2 list<Student_Call_Log__c> list_relatedlogs = ([select id, related_student__c, date__c, note__c from Student_Call_Log__c where related_student__c IN :list_relatedstudents order by Date__c DESC ]); list<Student_Call_Log__c> list_relatedlogs_mostrecent = ([select id, related_student__c, date__c, note__c from Student_Call_Log__c where related_student__c IN :list_relatedstudents order by Date__c DESC limit 1 ]);

 

 

 

  • March 02, 2010
  • Like
  • 0

I need to populate a collection of drop-down boxes based on the previous selection.  The custom object structure is:

 

Categories

CategoryID

CategoryName

ParentCategoryID

 

The first drop-down box should be populated with everything with a ParentCategoryID of 0.  The subsequent drop-down boxes should appear and be populated with CategoryNames where the ParentCategoryID is equal to the value from the previous drop-down box.

 

Any help is greatly appreciated.

I dont want to write my own pageination methods if salesforce already has them. In the cookbook section called 'Selecting Records with a Visualforce Custom List Controller ' it says you can use standard list controller actions ({!previous} and {!next}), but its not working for me. Can you see what I am doing wrong?

 

 

 

public with sharing class commentPagination { private final Quote_Comment__c comment; public commentPagination(ApexPages.StandardSetController controller) { this.comment = (Quote_Comment__c)controller.getRecord(); } public ApexPages.StandardSetController comments{get { if(comments == null) { return new ApexPages.StandardSetController(Database.getQueryLocator([SELECT name,comment__c FROM Quote_Comment__c ])); } return comments; } private set; } public List<Quote_Comment__c> getCommentPagination() { return (List<Quote_Comment__c>) comments.getRecords(); } public integer listSize {get; set;} {listSize = comments.getRecords().size();} }

 

 

 

<apex:page standardController="Quote_Comment__c" recordSetVar="comments" extensions="commentPagination"> <apex:pageBlock title="Viewing {!listsize} Comments"> <apex:form id="theForm"> <apex:pageBlockSection columns="1"> <apex:dataList var="c" value="{!commentPagination}" type="1"> {!c.name} </apex:dataList> </apex:pageBlockSection> <apex:panelGrid columns="2"> <apex:commandLink action="{!previous}"> Previous </apex:commandlink> <apex:commandLink action="{!next}"> Next </apex:commandlink> </apex:panelGrid> </apex:form> </apex:pageBlock> </apex:page>

 

I'm using Eclipse to develop Apex code.  I was working on a pretty big controller directly in my production account (I know, I know...) and got a little behind on implementing the test routines.  Eventually the controller would no longer save to my server since the average test coverage dropped below 75%.  I was seeing this error in the 'Problems' window in Eclipse:

 

'Average test coverage across all Apex Classes and Triggers is 74%, at least 75% test coverage is required'  

 

I immediately stopped working on the controller and went back to implement test routines in this and a couple of the other controllers.  Now the controller will save but the error message persists even if I run tests from within Eclipse.  When I run tests directly in the UI I'm told the average coverage is 84%.

 

How can I 'clear' the error message from the Eclipse 'Problems' window? 

  • October 27, 2009
  • Like
  • 0
Is it possible to get more information from views that have been set up? I want to get the SOQL string that the view uses to be able to dynamically add additional filters to the already configured views for an opportunity.

Hi,

 

I've got a requirement to ensure that Lead Status values that are "Converted" aren't chosen while the Lead is unconverted, as Salesforce.com allows.

 

I suppose I could write a validation rule to accomplish this, ensuring I edit the validation rule every time something changes in the Lead Status offerings, but we know how un-elegant that is.

 

I thought I could accomplish this in a trigger by building a map of unacceptable values for Lead.Status:

 

Map<Id,LeadStatus> statusList = new Map<Id,LeadStatus>([SELECT Id, MasterLabel 

from LeadStatus where IsConverted=true]);

 

What I can't figure out is how can I compare the value being chosen for Lead.Status to ensure it's not in the map.

 

 

 for (Lead newLead : Trigger.new) {

if (Trigger.IsUpdate) {

if (newLead.IsConverted != true) {

// how can I do this :

// if (newLead.Status isn't a value in statusList) {

// Trigger.old[0].addError('Invalid Choice');

// }

}

 

Any insight is much appreciated!!

  • September 24, 2009
  • Like
  • 0

Hi,

 

I'm looking for a way to call an apex function every day at a particular time ( just like cronjob in linue ). Is this possible in salesforce?

 

Hi,

 

I understand that using Salesforce UI, we can associate certain record types (of an object) to a particular user profile. Once that is set, is there a way to extract that information using apex code?

 

For example:

Account object has 2 record types (Individual & Business)

Profile "Western Sales Rep" has access to only "Business" record type.

 

From Apex code, how can I identify the record types for a given profile and object?

 

Thanks. 

  • August 29, 2009
  • Like
  • 0

Can someone help me understand the correct way to access the value selected by the user in the selectList and run some logic against the selection?

 

This is not working for me. Its for a jump to page drop list in a visualforce wizard.

 

 

public String[] jumpToSelections = new String[]{}; string selectedJumpTo = ''; public pageReference test() { if(jumpToSelections!=null){selectedJumpTo=jumpToSelections[0];} if(selectedJumpTo!=null && selectedJumpTo=='1'){return Page.step1;} if(selectedJumpTo!=null && selectedJumpTo=='2'){return Page.step2;} return null; } public List<SelectOption> getJumpToItems() { List<SelectOption> jumpToOptions = new List<SelectOption>(); jumpToOptions.add(new SelectOption('0','')); jumpToOptions.add(new SelectOption('1','Step 1')); jumpToOptions.add(new SelectOption('2','Step 2')); return jumpToOptions; } public String[] getJumpToSelections() { return jumpToSelections; } public void setJumpToSelections(String[] jumpToSelections) { this.jumpToSelections = jumpToSelections; }

 

 

Thank you.

Hi all,

 

I am trying to construct a <selectOption> dynamically by reading the values from a custom object which will be displayed in VF page.

 

Here is my code:

 

 

public List<SelectOption> getZipList () { List<SelectOption> zipList = new List<SelectOption>(); List<Zip_List__c> zipListObj= new List<Zip_List__c>(); zipListObj = [Select Name From Zip_List__c]; for (integer i=0;i<zipListObj.size;i++) { zipList.add(new SelectOption(zipListObj[i],zipListObj[i])); } }

 When I try to save the controller, it throws:

 

 Error: Compile Error: Constructor not defined: [System.SelectOption].<Constructor>(SOBJECT:Zip_List__c, SOBJECT:Zip_List__c)

 

If I hardcode the values in " zipList.add(new SelectOption(zipListObj[i],zipListObj[i])); ", it is working fine for me,

 

Please advice. 

 

Thanks in Advance

 

I have my Rails app running like a champ locally with the REST API. However, it crashes on Heroku. I tried Quinton's code again from his omniauth-rails3-forcedotcom project and it crashes on Heroku with the same error. I've search for two days now and am finally giving up and asking for help. Here's the log from Heroku:

 

 

==> dyno-7328866.log (crash) <==
/app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:304:in `rescue in depend_on': No such file to load -- Accounts (LoadError)
	from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:299:in `depend_on'
	from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:216:in `require_dependency'
	from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.5/lib/rails/engine.rb:138:in `block (2 levels) in eager_load!'
	from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.5/lib/rails/engine.rb:137:in `each'
	from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.5/lib/rails/engine.rb:137:in `block in eager_load!'
	from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.5/lib/rails/engine.rb:135:in `each'
	from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.5/lib/rails/engine.rb:135:in `eager_load!'
	from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.5/lib/rails/application.rb:108:in `eager_load!'
	from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.5/lib/rails/application/finisher.rb:41:in `block in <module:Finisher>'
	from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.5/lib/rails/initializable.rb:25:in `instance_exec'
	from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.5/lib/rails/initializable.rb:25:in `run'
	from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.5/lib/rails/initializable.rb:50:in `block in run_initializers'
	from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.5/lib/rails/initializable.rb:49:in `each'
	from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.5/lib/rails/initializable.rb:49:in `run_initializers'
	from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.5/lib/rails/application.rb:134:in `initialize!'
	from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.5/lib/rails/application.rb:77:in `method_missing'
	from /app/config/environment.rb:5:in `<top (required)>'
	from <internal:lib/rubygems/custom_require>:29:in `require'
	from <internal:lib/rubygems/custom_require>:29:in `require'
	from config.ru:3:in `block (3 levels) in <main>'
	from /home/heroku_rack/heroku.ru:23:in `eval'
	from /home/heroku_rack/heroku.ru:23:in `block (3 levels) in <main>'
	from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.2.2/lib/rack/builder.rb:46:in `instance_eval'
	from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.2.2/lib/rack/builder.rb:46:in `initialize'
	from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.2.2/lib/rack/builder.rb:63:in `new'
	from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.2.2/lib/rack/builder.rb:63:in `map'
	from /home/heroku_rack/heroku.ru:18:in `block (2 levels) in <main>'
	from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.2.2/lib/rack/builder.rb:46:in `instance_eval'
	from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.2.2/lib/rack/builder.rb:46:in `initialize'
	from /home/heroku_rack/heroku.ru:11:in `new'
	from /home/heroku_rack/heroku.ru:11:in `block in <main>'
	from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.2.2/lib/rack/builder.rb:46:in `instance_eval'
	from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.2.2/lib/rack/builder.rb:46:in `initialize'
	from /home/heroku_rack/heroku.ru:1:in `new'
	from /home/heroku_rack/heroku.ru:1:in `<main>'
	from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/lib/rack/adapter/loader.rb:36:in `eval'
	from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/lib/rack/adapter/loader.rb:36:in `load'
	from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/lib/thin/controllers/controller.rb:175:in `load_rackup_config'
	from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/lib/thin/controllers/controller.rb:65:in `start'
	from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/lib/thin/runner.rb:177:in `run_command'
	from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/lib/thin/runner.rb:143:in `run!'
	from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/bin/thin:6:in `<top (required)>'
	from /usr/ruby1.9.2/bin/thin:19:in `load'
	from /usr/ruby1.9.2/bin/thin:19:in `<main>'

 

Thanks for the helping a ruby n00b out!

 

Jeff Douglas

Appirio, Inc.

http://blog.jeffdouglas.com

http://www.cloudspokes.com 

 

I started out with Quinton's article here and am trying to build out some samples using Rails and the REST API. I can query for and fetch records but am having problems creating new records.

 

Here's my code:

 

 

  def self.create()
    Accounts.set_headers
    options = {
      :body => {
          :Name => "TestRailsApp"
      }
    }
    response = post(Accounts.root_url+"/sobjects/Account/", options)
    puts response.body, response.code, response.message
  end

 

 

But I am getting the following response back:

 

 

opening connection to na5.salesforce.com...
opened
<- "POST /services/data/v21.0/sobjects/Account/ HTTP/1.1\r\nAuthorization: OAuth 00D700000009Bki!ARQAQHsUMNBjZTLupOGjYhGDQ9k8SN0FC9qGnVMhpM5rqgLsOBPVhgtsgwqYzELkcX47FlyqQhGAf83eaXXXXX\r\nConnection: close\r\nHost: na5.salesforce.com\r\nContent-Length: 8\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n"
<- "Name=TestRailsApp"
-> "HTTP/1.1 415 Unsupported Media Type\r\n"
-> "Server: \r\n"
-> "Content-Type: application/json; charset=UTF-8\r\n"
-> "Content-Length: 135\r\n"
-> "Date: Tue, 26 Apr 2011 14:15:34 GMT\r\n"
-> "Connection: close\r\n"
-> "\r\n"
reading 135 bytes...
-> "[{\"message\":\"MediaType of 'application/x-www-form-urlencoded' is not supported by this resource\",\"errorCode\":\"UNSUPPORTED_MEDIA_TYPE\"}]"
read 135 bytes
Conn close
[{"message":"MediaType of 'application/x-www-form-urlencoded' is not supported by this resource","errorCode":"UNSUPPORTED_MEDIA_TYPE"}]
415
Unsupported Media Type

 

 

Any ideas? Thanks!

 

Jeff Douglas

Appirio, Inc.

http://blog.jeffdouglas.com

http://www.cloudspokes.com

I've run into a few issues trying to install CMSForce 2 on a Force.com Free org:

 

1. I'm getting the same error as reported here. It's a brand new org and I've added the Sites user's access to all classes and visualforce pages. The page runs if I remove the pageController from the Visualforce page so I suspect that it's something in the controller. Possible the Custom Settings? I just installed CMSForce 2 in a DE account and everything works fine.

 

2. In CMSForceSetup.page the save button is hard-coded to only display if the current user's profile is 'System Administrator':

<apex:commandButton value="Save" action="{!save}" rendered="{!IF($Profile.Name == 'System Administrator', true, false)}"/>

 

However, if you install the package in a Force.com Free account, the profile is not 'System Administrator' but 'Platform System Admin' therefore the Save button doesn't render.
Thanks
Jeff Douglas

 

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

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

I have my Rails app running like a champ locally with the REST API. However, it crashes on Heroku. I tried Quinton's code again from his omniauth-rails3-forcedotcom project and it crashes on Heroku with the same error. I've search for two days now and am finally giving up and asking for help. Here's the log from Heroku:

 

 

==> dyno-7328866.log (crash) <==
/app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:304:in `rescue in depend_on': No such file to load -- Accounts (LoadError)
	from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:299:in `depend_on'
	from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:216:in `require_dependency'
	from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.5/lib/rails/engine.rb:138:in `block (2 levels) in eager_load!'
	from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.5/lib/rails/engine.rb:137:in `each'
	from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.5/lib/rails/engine.rb:137:in `block in eager_load!'
	from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.5/lib/rails/engine.rb:135:in `each'
	from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.5/lib/rails/engine.rb:135:in `eager_load!'
	from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.5/lib/rails/application.rb:108:in `eager_load!'
	from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.5/lib/rails/application/finisher.rb:41:in `block in <module:Finisher>'
	from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.5/lib/rails/initializable.rb:25:in `instance_exec'
	from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.5/lib/rails/initializable.rb:25:in `run'
	from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.5/lib/rails/initializable.rb:50:in `block in run_initializers'
	from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.5/lib/rails/initializable.rb:49:in `each'
	from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.5/lib/rails/initializable.rb:49:in `run_initializers'
	from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.5/lib/rails/application.rb:134:in `initialize!'
	from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.5/lib/rails/application.rb:77:in `method_missing'
	from /app/config/environment.rb:5:in `<top (required)>'
	from <internal:lib/rubygems/custom_require>:29:in `require'
	from <internal:lib/rubygems/custom_require>:29:in `require'
	from config.ru:3:in `block (3 levels) in <main>'
	from /home/heroku_rack/heroku.ru:23:in `eval'
	from /home/heroku_rack/heroku.ru:23:in `block (3 levels) in <main>'
	from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.2.2/lib/rack/builder.rb:46:in `instance_eval'
	from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.2.2/lib/rack/builder.rb:46:in `initialize'
	from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.2.2/lib/rack/builder.rb:63:in `new'
	from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.2.2/lib/rack/builder.rb:63:in `map'
	from /home/heroku_rack/heroku.ru:18:in `block (2 levels) in <main>'
	from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.2.2/lib/rack/builder.rb:46:in `instance_eval'
	from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.2.2/lib/rack/builder.rb:46:in `initialize'
	from /home/heroku_rack/heroku.ru:11:in `new'
	from /home/heroku_rack/heroku.ru:11:in `block in <main>'
	from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.2.2/lib/rack/builder.rb:46:in `instance_eval'
	from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.2.2/lib/rack/builder.rb:46:in `initialize'
	from /home/heroku_rack/heroku.ru:1:in `new'
	from /home/heroku_rack/heroku.ru:1:in `<main>'
	from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/lib/rack/adapter/loader.rb:36:in `eval'
	from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/lib/rack/adapter/loader.rb:36:in `load'
	from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/lib/thin/controllers/controller.rb:175:in `load_rackup_config'
	from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/lib/thin/controllers/controller.rb:65:in `start'
	from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/lib/thin/runner.rb:177:in `run_command'
	from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/lib/thin/runner.rb:143:in `run!'
	from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/bin/thin:6:in `<top (required)>'
	from /usr/ruby1.9.2/bin/thin:19:in `load'
	from /usr/ruby1.9.2/bin/thin:19:in `<main>'

 

Thanks for the helping a ruby n00b out!

 

Jeff Douglas

Appirio, Inc.

http://blog.jeffdouglas.com

http://www.cloudspokes.com 

 

I started out with Quinton's article here and am trying to build out some samples using Rails and the REST API. I can query for and fetch records but am having problems creating new records.

 

Here's my code:

 

 

  def self.create()
    Accounts.set_headers
    options = {
      :body => {
          :Name => "TestRailsApp"
      }
    }
    response = post(Accounts.root_url+"/sobjects/Account/", options)
    puts response.body, response.code, response.message
  end

 

 

But I am getting the following response back:

 

 

opening connection to na5.salesforce.com...
opened
<- "POST /services/data/v21.0/sobjects/Account/ HTTP/1.1\r\nAuthorization: OAuth 00D700000009Bki!ARQAQHsUMNBjZTLupOGjYhGDQ9k8SN0FC9qGnVMhpM5rqgLsOBPVhgtsgwqYzELkcX47FlyqQhGAf83eaXXXXX\r\nConnection: close\r\nHost: na5.salesforce.com\r\nContent-Length: 8\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n"
<- "Name=TestRailsApp"
-> "HTTP/1.1 415 Unsupported Media Type\r\n"
-> "Server: \r\n"
-> "Content-Type: application/json; charset=UTF-8\r\n"
-> "Content-Length: 135\r\n"
-> "Date: Tue, 26 Apr 2011 14:15:34 GMT\r\n"
-> "Connection: close\r\n"
-> "\r\n"
reading 135 bytes...
-> "[{\"message\":\"MediaType of 'application/x-www-form-urlencoded' is not supported by this resource\",\"errorCode\":\"UNSUPPORTED_MEDIA_TYPE\"}]"
read 135 bytes
Conn close
[{"message":"MediaType of 'application/x-www-form-urlencoded' is not supported by this resource","errorCode":"UNSUPPORTED_MEDIA_TYPE"}]
415
Unsupported Media Type

 

 

Any ideas? Thanks!

 

Jeff Douglas

Appirio, Inc.

http://blog.jeffdouglas.com

http://www.cloudspokes.com

I'm developing an application in Google app engine. In this application if user logs in with gmail user credentials, application should access that logged in user's sales force account details (if logged in user has a salesforce account). I should be able to get account details (and any other details in force.com) and display them in Google app in a needed format. How can I do this? Is there a way to accomplish this buy using 'force.com for Google app engine' + SSO ?

  • April 19, 2011
  • Like
  • 0

For everyone that's testing stuff with the command line, check out jsawk, this allows you to parse & process json from the command line. (If you're on a Mac, you can get the spidermonkey dependency via macports)

 

I have this script to get me an oauth token via the username password flow

 

 

curl https://login.salesforce.com/services/oauth2/token -d grant_type=password -d client_id=myClientId -d client_secret=mySecret -d username=foo@example.com -d password=myPassword  -# | ./jsawk "return this.access_token"

 This uses jsawk to extract the access_token value from the response json, using the shell's ` operator, its easy to stick this in a shell variable,

 

export SFDC_SID=`./login.sh`

You can then easily refer to your token when making curl calls to the rest API, e.g.

 

curl -H "Authorization: OAuth $SFDC_SID" http://na1.salesforce.com/services/data/v20.0/recent

 

 

 Of course, you can use jsawk on these as well to process the response, e.g. this will show just the Ids of the records in your MRU

 

 

curl -H "Authorization: OAuth $SFDC_SID" http://na1.salesforce.com/services/data/v20.0/recent | ./jsawk "return this.Id"
["006300000023MvwAAE","a003000000E2BalAAF","0033000000h0k6qAAA","0033000000jWKwJAAW","0033000000jWKwIAAW","0033000000h0k76AAA","0033000000ZsocCAAR","0033000000ZsimSAAR","0033000000PVjEqAAL","01530000000KBIOAA4"]
["006300000023MvwAAE","a003000000E2BalAAF","0033000000h0k6qAAA","0033000000jWKwJAAW","0033000000jWKwIAAW","0033000000h0k76AAA","0033000000ZsocCAAR","0033000000ZsimSAAR","0033000000PVjEqAAL","01530000000KBIOAA4"]

 

 

 

 

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

Hi,

 

I have created a simply visualforce page which PDFs a record and adds some branding.

 

The record is linked to a contact.

 

A contact can have many of these records.

 

Is it possible to produce a PDF of all the related records attached to a client.

 

Ideally in one PDF document?

 

Thanks

 

Ross

Hi All Is it possible to upload some word document as template on the platform and then generate new documents from merged fields and the uploaded document template?

 

Hi, 
I have created a extension class for Lead object. To insert the record from the site.
I wouldnot be able to get the code coverage upto 75%
Can any one please help me out in covering all the lines of code.
 
Apex Class : 
public with sharing  class leadExtension {

    private final ApexPages.StandardController controller;
    
       public leadExtension(ApexPages.StandardController stdController) {
      
        this.controller = stdController;
        
    }

 
    public PageReference Save()
    {
      
      lead l = (lead)controller.getRecord();
      insert l;
    
     Pagereference thanksPage2= Page.thanksPage2;
    hpathanksPage.setRedirect(True);
    return hpathanksPage;
    
    }
        
 public PageReference Submit()
    {
      
      lead l = (lead)controller.getRecord();
      insert l;
     Pagereference thanksPage= Page.thanksPage1;
   eppthanksPage.setRedirect(True);
     return eppthanksPage;
   
    }
}

================================================================

Test class :

@isTest
private class TestleadExtension  {
 


  static testMethod void Leadextension() {
 
    Lead l = new Lead();
  Leadextension controller = new Leadextension(new ApexPages.StandardController(l));
  
    l.LastName='testname';
    l.Company='testcompany';
    l.Internal_Contact_Title__c='testtitle';
    l.Internal_Contact_Phone_Number__c='123456';
    l.Internal_Contact_Name__c='testcontact';
    l.Internal_Contact_email_Address__c='testb@company.com';
    l.Phone='45678';
    l.Email='test@company.com';
    l.HR_Contact_Name__c='test HRContact';
    l.HR_Contact_Title__c='test HRContact title';
    l.HR_Contact_Phone_Number__c='6789';
    l.HR_Contact_Email_Address__c= 'test@company.com';         
    insert l;
   
    }
  static testMethod void save() {
 
    pageReference Pageref1 =Page.thankspage2;
      Test.setCurrentPage(Pageref1);
      Pageref1.setRedirect(true);
     
   
        }
       
    static testMethod void Submit() {
   
       
     PageReference pageRef2 = Page.hankspage1;
                  Test.setCurrentPageReference(pageRef2);
     Pageref2.setRedirect(true);
   
    }
   
}

Please help me out on this issue .

 

Thanks

Ramesh

Hi -

 

Travel__c custom Object is the related list under Opportunity. When i try to grab the AccountId from Opportunity using child relationship the value is coming as null. When i query the same in Apex explorer i am getting the results.

 

Please advise what is wrong here?

 

 

trigger test_sample on Travel__c (after update,after insert) 
{
    if(trigger.isAfter)
    {
        if(trigger.isUpdate)        
{ for(Travel__c t:Trigger.new) { system.debug('Opportunity AccountId Value '+t.Opportunity__r.Account.Id); } } } }

 

 

Hello all,

                I am a newbie to apex development. Can any one help me in bulkifying this trigger.

 

  trigger PopulateRegistrantGroup on Event_Registrant_zem__c (before insert, before update) {      

        String s;

        Id id1;

         for (Event_Registrant_zem__c e :Trigger.new)

          {
                 id1 = e.registrant_type__c;
                s = [select id,name from Registrant_Type_zem__c where id = :id1].name;
        
         if(e.Registrant_type_group__c == NULL)
          {
            e.Registrant_type_group__c = [select epz.Id from Event_permission_zem__c epz where epz.zimmer_event__c = :e.zimmer_event__c and epz.type__c = 'Event Capacity' and epz.Registrant_Types__c INCLUDES (:s)][0].id;
          }
       }

}

 

Any help is appriciated. Thanks in advance.

Hello,

 

I am a newbie Apex Developer trying to solve an issue with calling the StandardController.edit() method.

 

I created a custom Organization__c object for a user to enter info about their company.   I want logic in the class to limit t 1 instance of Organization__c, so I over-rode the "New" button on the object to point to a Visualforce page that calls my determinePageRedirect method.  If the list of Organization__c is > 0, it returns a PageReference to the edit page using the current ID.  If the list is null, I want to call StandardController.edit() to show the regular new page for Organization__c.  

 

Code works as expected when this.existingOrganization.size () > 0. however, I get an error message "cannot call edit() on null object when that list is empty. Seems like I need some mojo on my StandardController instantiation to make this work. Any ideas? Any help is greatly appreciated - this is driving me nuts!

 

Thanks

 

Apex Class

 

public class OrganizationValidation {

	//declare a private controller variable
	private ApexPages.StandardController controller;
	
	private Organization__c org {get;set;}
	
	//populate list of existingOrganizations
	public List<Organization__c> existingOrganizations;
		public List<Organization__c> getExistingOrganizations(){
			return existingOrganizations;	
	}

	//instatiate class
	public OrganizationValidation(){	
	}
	
	//standard controller constructor
	public OrganizationValidation(ApexPages.StandardController pController) {
        this.controller = pController;
        System.debug('***this.controller: ' +this.controller);
		
		//need StandardController to be aware of current context
		
		
		this.org = (Organization__c)pController.getRecord();
		System.debug('***org: '+ org);

    	OrganizationRedirect();
    }
    
	//Run these methods when we hit the Visualforce page
	public PageReference OrganizationRedirect(){
		
			
		//invoke method to query if there is an Organization__c result
		queryOrganizations();
		
		//invoke method to redirect based on if/then
		determinePageRedirect();
		
		return null;
	
	}
	
	//PageReference method – button on Visualforce page calls
	public PageReference editButtonRedirect() {

		PageReference editRedirect;
		for(Organization__c org: this.existingOrganizations){
				Organization__c myOrg = org;
				editRedirect = new PageReference ('/' + myOrg.id + '/e');
		
		}
	
		return editRedirect;
	
	}
		
	public void queryOrganizations(){
		//query the orgID
		this.existingOrganizations = [Select id, Name From Organization__c];
		//System debug
		System.debug('***existingOrganizations: '+existingOrganizations);
		
	}
	
	//Method to run if/else statement to redirect page
	public PageReference determinePageRedirect(){
	
		PageReference redirectPage;
		if (this.existingOrganizations.size() > 0){
			
			redirectPage = new PageReference ('apex/OrganizationRedirect');
			
		}else{
			
			//Show new page
			redirectPage = this.controller.edit();
			
		}
	
return redirectPage;
	
	}
}

 

Visualforce Page

 

<apex:page standardController="Organization__c" extensions="OrganizationValidation" action="{!determinePageRedirect}">
	<apex:outputPanel >
		<apex:form >
			<h1>Warning</h1>
			<p>You already entered your Organization's information.  Please edit the existing record.</p>
			<apex:commandButton action="{!editButtonRedirect}" value="Edit Organization" />
		</apex:form>
	</apex:outputPanel>
</apex:page>

 

 

 

 

 

This should be fairly simple

 

I have a pageTable with one column dedicated to a selectCheckbox for the row item. If the user click the pageBlockButton while no item is selected, I was hiping to either use the ApexPages Message component, or if that's overkill, just display a Javascript alert when the button is pushed.

 

I've tried creating a boolean checking method on the display list

 

 

public boolean checkMethod (list<object> objectList)
{
    boolean check = false;
    for (Object obj :ObjectList)
    {
        if (obj.Selected = true)
            check = true;
    }
     return check
}

 I then call this as part of the method referenced by the button:

 

public Pagereference processItems()
{
   if (!objectList.isEmpty())
   {
       if (!checkSelection(ObjectList)
       {
           ApexPages.Message err = new ApexPages.Message(
              ApexPages.Severity.ERROR, 'No selection has been made. Select an item before continuing');
           ApexPages.addMessage(err);
       }
   }
   else
   ...run Method

 however, this does not display anything in the page when using either <apex:PageMessages></apex:PageMessages>, or using <apex:Messages>.

 

 

The other idea was to put logic into the action attribute of the commandButton. I created a boolean property called checkSelection, I changed the above checkSelection method to 'getCheckSelection', and then wrote the action attribute as

action="{!IF checkSelection, processItems, alert('Please select item before continuing')}"

 

but that didn't work either.

 

Suggestions and solutions are most appreciated

 

ODB

 

Hi community,

 

I need to get a picklist filtered by record type in a Visualforce page. From Summer '10 we have the ability to use dependent picklists in Visualforce pages. But, correct me if I am wrong, there is no standard way to use picklists filtered by RecordType, isn't it?

 

If no possible, can anyone help me out to find a solution?

 

Thanks in advance.

 

Regards.

 

hi,

 

i am new to this test classes concept. Can anybody give an example for writing a test class for a controller.

 

public PageReference psignup() {
    emailerror=false;
        emailacept=false;
        List<guestuser__c> ldtls=[select Id from guestuser__c where Email__c=:email];
        
        if(ldtls.size()>0)
        {
            emailerror=true;
            emailacept=false;
            //uid exist
        }
        else
        {
            if(pwd==rpwd)
            {
                emailerror=false;
                emailacept=false;
                guestuser__c gu=new guestuser__c();
                gu.First_Name__c=fname;
                gu.Password__c=pwd;
                gu.Email__c=email;
                gu.Title__c = job;
                gu.Email_Optout__c = echeck;
                gu.Last_Name__c = lname;
                gu.Company__c = comp;
                gu.Street__c = street;
                gu.State__c = state;
                gu.City__c = city;
                gu.Country__c = ctry;
                gu.Zipcode__c = zip;
                
                
                Lead ld=new Lead();          
                ld.FirstName =fname;
                ld.LastName=lname;
                ld.Company=comp;
                ld.Street=street;
                ld.State=state;
                ld.city=city;
                ld.PostalCode=zip;
                ld.country=ctry;
                ld.Title=job;
                ld.Email=email;
                ld.HasOptedOutOfEmail=echeck;
                
                
                try{
                insert ld;
                insert gu;
                Pagereference pageref=new Pagereference('/apex/thankq');     
                    pageref.setRedirect(true);
                    return pageref;
                }
                catch(Exception e)
                {
                    system.debug(e);
                }
            }
            else
            {
                ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.WARNING, 'PASSWORD MISS-MATCH');
                ApexPages.addMessage(myMsg);
            }
        }
        return null;
    }


    public Boolean echeck { get; set; }

    public String rpwd { get; set; }

    public String pwd { get; set; }

    public void checkavlble() {
        String lusername= Apexpages.currentPage().getParameters().get('mail');
        List<guestuser__c> chkldtls=[select Id from guestuser__c where Email__c=:email];
        if(chkldtls.size()>0)
        {
            emailerror=true;
            emailacept=false;
        }
        else
        {           //try another
            emailerror=false;
            emailacept=true;
        }
    }


    public Boolean emailacept { get; set; }

    public Boolean emailerror { get; set; }

    public String email { get; set; }

    public String job { get; set; }

    public String ctry { get; set; }

    public String zip { get; set; }

    public String state { get; set; }

    public String city { get; set; }

    public String street { get; set; }

    public String comp { get; set; }

    public String lname { get; set; }

    public String fname { get; set; }
}

 

i need to write the test class for this controller to deploy the page.can anybody help me with an example. 

 

Hi

 

I have a query like

 

String querySoql = 'Select Id, Name from Account limit 10000';

 

 

Now I have the following functionality to implement them..

 

setCon = new ApexPages.StandardSetController(Database.query(soqlQuery));

setCon.next

setCon.prev

 

where next and prev are used for page wise move..

 

Since the number of rows in the objects is more than 10000 it is not showing the values in the page instead giving following error

 

Content cannot be displayed: Too many query rows: 10001

 

Content cannot be displayed: retrieve id limit reached

 

 

Any help on this will be much appreciated.

  • July 14, 2010
  • Like
  • 0