• sbarstow
  • NEWBIE
  • 0 Points
  • Member since 2005

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 8
    Replies
 to do this and I thought others might benefit from the example.  
The business function was to have a button on the account page that would create a new opportunity and case ( for the primary contact ).  I built a controller and page, then hooked it up to the button.  here is the process:
Go to Setup | Develop | Apex Classes
Create a new class and copy the following code into the editor ( it should format I hadcorrectly ):

  I had a customer that wanted to do this and I thought others might benefit from the example.  
The business function was to have a button on the account page that would create a new opportunity and case ( for the primary contact ).  I built a controller and page, then hooked it up to the button.  here is the process:

 

Go to Setup | Develop | Apex Classes


Create a new class and copy the following code into the editor ( it should format correctly ):

 

 

/****************************************************

*Name :  Account Controller 

*Purpose: acts as the extension for the standard functionality

          Creates a Opportunity with default values

          Creates a Case with default values

          with the primary contact and opp.Name selected by the user

***************************************************/

public class AccountController {

 

    //-------Private Variables Section------------//

    private final Account account;

    private List<Contact> lstContact;

    private String selectedContactId;

    private Case theCase;

 

    //-------------------Construtor-------------------------------//

    public AccountController(ApexPages.StandardController controller) {

       this.account = (Account)controller.getRecord();

       this.opportunity = new Opportunity();

       PopulateContacts();

    }

 

    //--------------------Public Properties Accessed on VF page-----------//

    public Opportunity opportunity {get;set;}

    public List<Contact> getAccountContacts() {

      return lstContact;

    }

 

    //-----------------------Private Methods--------------------------------//

    private void PopulateContacts() {

        if(this.account.Id == null) {

          this.lstContact = new List<Contact>();

          return;

        }

        //Load all Contact related to this Account,with Name,Title etc

      this.lstContact = [select Id,Name,Title,Email,Phone from Contact where AccountId = :this.account.Id];

    }

 

    //-----------------------------------------------------//

    //Create a Opportunity object, using default values, and current Account,seleccted Contact

    //-----------------------------------------------------//    

    private void CreateOpportunity() {

        this.opportunity.StageName = 'Prospecting';

        this.opportunity.CloseDate = System.today().addDays(14);

        this.opportunity.AccountId = this.account.ID;

        this.opportunity.LeadSource = this.account.AccountNumber;

 

      upsert this.opportunity;

    }

 

    //-----------------------------------------------------//

    //Create a Case object, using default values, and current Account,seleccted Contact

    //-----------------------------------------------------//

    private void CreateCase() {

      theCase = new Case();

      theCase .Origin = 'Web';

      theCase .Status = 'New';

      theCase .AccountId = this.account.Id;

      theCase .ContactId = this.selectedContactId;

      theCase .Subject = 'Case for ' + this.Account.Name;

 

 

      //Case cCase = new Case();

      //cCase.Origin = 'Web';

      //cCase.Status = 'New';

      //cCase.AccountId = this.account.Id;

      //cCase.ContactId = this.selectedContactId;

      //cCase.Subject = 'Case for ' + this.Account.Name;

 

      upsert theCase;

    }

 

    //------------------------Page Reference Methods-------------------------------------------------------// 

    public PageReference SaveOpportunity() {

 

      //Validate Data

      this.selectedContactId = ApexPages.currentPage().getParameters().get('ctRadio');

      if(selectedContactId == null || selectedContactId == '') {

        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'Please select a primary contact'));

        return null;

      }

 

      //Create Opportunity and Case

      try {

         CreateOpportunity();

         CreateCase();

      }

      catch(DmlException ex) {  //If any error occurs during creation of Case,Opportunity

        ApexPages.addMessages(ex);

        return null;

      }

      //Redirect back to the Account Detail page

      return new PageReference('/' + this.theCase.Id);

    }

 

 

    //---------------------------------------------TEST METHOD --------------------------------------------------------------//

    //Test Code coverage 75% required for moving code in Production environment

    //No data is committed or modified during test case execution

    //------------------------------------------------------------------------------------------------------------------------//

 

    @isTest

    private static void TestAccountController() {

      //Generate Sample Test data

      Account account = new Account(Name = 'Hello World');

      insert account;

 

      Contact contact = new Contact(LastName = 'Hello',AccountId = account.Id);

      insert contact;

 

      ApexPages.Standardcontroller stdController = new ApexPages.StandardController(account);

      AccountController ctrl = new AccountController(stdController);

 

      Test.startTest();

      Test.setCurrentPageReference(Page.MyNewPage);

 

      List<Contact> lstContact = ctrl.getAccountContacts();

      //Should contain 1 record

      System.assertEquals(lstContact.size(),1);

 

      ctrl.opportunity.Name = 'Hello world Opportunity';

      PageReference pg = ctrl.SaveOpportunity();

      //Should raise an error,because selected ContactId is not set

      System.assertEquals(null,pg);

 

      ApexPages.currentPage().getParameters().put('ctRadio',contact.Id);

      pg = ctrl.SaveOpportunity();

 

      Test.stopTest();

 

      //Assert that Opportunity and Case created

      Integer cCaseCount = [select count() from Case where AccountId = :account.Id AND ContactId = :contact.Id];

      Integer OpportunityCount = [select count() from Opportunity where AccountId = :account.Id];

 

      System.assertEquals(1,cCaseCount);

      System.assertEquals(1,opportunityCount); 

    }

}

 

I am interested in programatically creating workflows, approval processes, and steps via SOAP.  Is this currently supported?  Cannot find examples, etc.
Is there a way to re-use the WILs on a user layout inside the open source partner portal project?

I have related lists working, this is really the "final frontier".

Intuitively, it would not seem possible, but perhaps someone has done a workaround or something?

Thx.
Can we use the clone function via the API? Dont see it anywhere, but could be blind.

Obviously we can do the poor mans clone by doing an object copy and inserting.
 to do this and I thought others might benefit from the example.  
The business function was to have a button on the account page that would create a new opportunity and case ( for the primary contact ).  I built a controller and page, then hooked it up to the button.  here is the process:
Go to Setup | Develop | Apex Classes
Create a new class and copy the following code into the editor ( it should format I hadcorrectly ):

  I had a customer that wanted to do this and I thought others might benefit from the example.  
The business function was to have a button on the account page that would create a new opportunity and case ( for the primary contact ).  I built a controller and page, then hooked it up to the button.  here is the process:

 

Go to Setup | Develop | Apex Classes


Create a new class and copy the following code into the editor ( it should format correctly ):

 

 

/****************************************************

*Name :  Account Controller 

*Purpose: acts as the extension for the standard functionality

          Creates a Opportunity with default values

          Creates a Case with default values

          with the primary contact and opp.Name selected by the user

***************************************************/

public class AccountController {

 

    //-------Private Variables Section------------//

    private final Account account;

    private List<Contact> lstContact;

    private String selectedContactId;

    private Case theCase;

 

    //-------------------Construtor-------------------------------//

    public AccountController(ApexPages.StandardController controller) {

       this.account = (Account)controller.getRecord();

       this.opportunity = new Opportunity();

       PopulateContacts();

    }

 

    //--------------------Public Properties Accessed on VF page-----------//

    public Opportunity opportunity {get;set;}

    public List<Contact> getAccountContacts() {

      return lstContact;

    }

 

    //-----------------------Private Methods--------------------------------//

    private void PopulateContacts() {

        if(this.account.Id == null) {

          this.lstContact = new List<Contact>();

          return;

        }

        //Load all Contact related to this Account,with Name,Title etc

      this.lstContact = [select Id,Name,Title,Email,Phone from Contact where AccountId = :this.account.Id];

    }

 

    //-----------------------------------------------------//

    //Create a Opportunity object, using default values, and current Account,seleccted Contact

    //-----------------------------------------------------//    

    private void CreateOpportunity() {

        this.opportunity.StageName = 'Prospecting';

        this.opportunity.CloseDate = System.today().addDays(14);

        this.opportunity.AccountId = this.account.ID;

        this.opportunity.LeadSource = this.account.AccountNumber;

 

      upsert this.opportunity;

    }

 

    //-----------------------------------------------------//

    //Create a Case object, using default values, and current Account,seleccted Contact

    //-----------------------------------------------------//

    private void CreateCase() {

      theCase = new Case();

      theCase .Origin = 'Web';

      theCase .Status = 'New';

      theCase .AccountId = this.account.Id;

      theCase .ContactId = this.selectedContactId;

      theCase .Subject = 'Case for ' + this.Account.Name;

 

 

      //Case cCase = new Case();

      //cCase.Origin = 'Web';

      //cCase.Status = 'New';

      //cCase.AccountId = this.account.Id;

      //cCase.ContactId = this.selectedContactId;

      //cCase.Subject = 'Case for ' + this.Account.Name;

 

      upsert theCase;

    }

 

    //------------------------Page Reference Methods-------------------------------------------------------// 

    public PageReference SaveOpportunity() {

 

      //Validate Data

      this.selectedContactId = ApexPages.currentPage().getParameters().get('ctRadio');

      if(selectedContactId == null || selectedContactId == '') {

        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'Please select a primary contact'));

        return null;

      }

 

      //Create Opportunity and Case

      try {

         CreateOpportunity();

         CreateCase();

      }

      catch(DmlException ex) {  //If any error occurs during creation of Case,Opportunity

        ApexPages.addMessages(ex);

        return null;

      }

      //Redirect back to the Account Detail page

      return new PageReference('/' + this.theCase.Id);

    }

 

 

    //---------------------------------------------TEST METHOD --------------------------------------------------------------//

    //Test Code coverage 75% required for moving code in Production environment

    //No data is committed or modified during test case execution

    //------------------------------------------------------------------------------------------------------------------------//

 

    @isTest

    private static void TestAccountController() {

      //Generate Sample Test data

      Account account = new Account(Name = 'Hello World');

      insert account;

 

      Contact contact = new Contact(LastName = 'Hello',AccountId = account.Id);

      insert contact;

 

      ApexPages.Standardcontroller stdController = new ApexPages.StandardController(account);

      AccountController ctrl = new AccountController(stdController);

 

      Test.startTest();

      Test.setCurrentPageReference(Page.MyNewPage);

 

      List<Contact> lstContact = ctrl.getAccountContacts();

      //Should contain 1 record

      System.assertEquals(lstContact.size(),1);

 

      ctrl.opportunity.Name = 'Hello world Opportunity';

      PageReference pg = ctrl.SaveOpportunity();

      //Should raise an error,because selected ContactId is not set

      System.assertEquals(null,pg);

 

      ApexPages.currentPage().getParameters().put('ctRadio',contact.Id);

      pg = ctrl.SaveOpportunity();

 

      Test.stopTest();

 

      //Assert that Opportunity and Case created

      Integer cCaseCount = [select count() from Case where AccountId = :account.Id AND ContactId = :contact.Id];

      Integer OpportunityCount = [select count() from Opportunity where AccountId = :account.Id];

 

      System.assertEquals(1,cCaseCount);

      System.assertEquals(1,opportunityCount); 

    }

}

 

Is there a way to re-use the WILs on a user layout inside the open source partner portal project?

I have related lists working, this is really the "final frontier".

Intuitively, it would not seem possible, but perhaps someone has done a workaround or something?

Thx.

In development for our release of the partner portal, I thought that it would be pretty cool to be able to click on an item in the related list and have it take you to the page for that particular Contact/Opportunity or whatever your related list is.  I accomplished this by adding the following code in the "test for presence of any related Lists" section in the sObjectDetail.jsp file.

<c:if test="${colStatus.first}"><a href="<c:url value="/detail.do" ><c:param name="id" value="${map['Id']}" /></c:url>" Class="<c:out value="${thisRow}" />"></c:if>

This code was added right below the code that draws the related list table.

<c:if test="${colStatus.first}"><td class= "<c:out value="${thisRow}" />">&nbsp</td></c:if>

I'm not a java coder, so this may not be the best way to do this, but it works pretty well.  The downfall is that the link does not appear hot, or it is not an actionLink, so you have to train your users to know that it actually is.  If anyone can figure out how to make it an action link, please post it. 

 

Thanks

 

 

 

 

  • August 17, 2005
  • Like
  • 0
I just ran the new DescribeLayout call and was disappointed to find that web links aren't included in the results... Is this intentional or a bug? Or (hopefully) am I just missing something?

Thanks,

=> Darla