• MRutter
  • NEWBIE
  • 25 Points
  • Member since 2008

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 13
    Replies

I and trying to use Apex to create a new Task, then return to the user with the new Task in Edit mode where the user can edit and save the new Task

 

This is what I have:

// Apex class for a new Tour on Lead.
// Called from VF Page LeadTourPg

public class NewLeadTour{
 public Lead si;
 public NewLeadTour() {}

// get ID of current Page (a Lead in this case)  
  public PageReference init() {
    Id siId = ApexPages.currentPage().getParameters().get('id');
 
       
//Declare Variables and strings 
    Lead lead;
    Account acc;   
    Task tsk;
   

    String CurrUser = UserInfo.getUserId();    //Get Current User
    
 //Get variables from current Lead Record   
    try {
      if (si==null)
      si = [SELECT Id, Name, OwnerID FROM lead WHERE Id = :siId];
    }
      catch(Exception e) {
    }
 
//Create a scheduled task
    if(si.Name!=null){   
    tsk = new Task();
    tsk.whoId = si.Id;
    tsk.OwnerId = currUser; 
    tsk.Subject = 'New Tour for ' + si.Name;
    tsk.Status = 'Not Started';
    //tsk.Description = 'User = '+ currUser;
    tsk.Priority = 'Normal';
    tsk.OwnerID = si.OwnerID;
    tsk.ActivityDate = date.today()+2;
  
try{
insert tsk;
}catch (Exception ex){system.debug('error creating a scheduled Task:'+ex);} 
}
 
return (new ApexPages.StandardController(tsk)).edit();
      
//return new PageReference('/'+tsk.Id);     
 
    
    }
    }

 

This does create a new Task and shows the new Task to me in edit mode.

However, when I edit the Task and click Save, the Task is saved, but I still see a Task in edit mode.  I cannot get out of this edit mode

 

Something wrong with this statment?

return (new ApexPages.StandardController(tsk)).edit();

 

I just installed Excel Connector on my new computer, running Windows 7.

When doing a query, I either get no data, or only partial data. 

What's up?

I am VF Page to convert a spouse (in contacts) to a new contact.  I am using Multiple Page Block Sections to send information to the user based on the value of a custom field set in my custom controller.

<apex:page standardController="Contact" extensions="ConverSpouseExtension"> <apex:form > <apex:sectionheader title="Create Spouse As A New Contact"> <apex:actionregion > <apex:pageBlock title="Spouse Information" id="thePageBlock" mode="edit"> <apex:pageBlockButtons > <!-- Show Save Button if Spouse is not converted and Spouse has a First Name --> <apex:commandButton value="Convert" action="{!NContact}" rendered="{!SpouseCon.Spouse_Converted__c == 'SNCon'}" /> <apex:commandButton value="Cancel" action="{!cancel}"/> </apex:pageBlockButtons> <!-- Show if okay to Convert Spouse to a Contact --> <apex:pageBlockSection title="Spouse Ready to Convert to Contact" columns="1" rendered="{!SpouseCon.Spouse_Converted__c == 'SNCon'}"> <h1>Update information as needed and press 'Convert'</h1> </br> to convert Spouse to a Contact <apex:inputfield id="FirstName" value="{!SpouseInfo.FirstName}" /> <apex:inputfield id="LastName" value="{!SpouseInfo.LastName}" /> <apex:inputfield id="Email" value="{!SpouseInfo.Email}" /> <apex:inputfield id="Phone" value="{!SpouseInfo.Phone}" /> </apex:pageBlockSection> <!-- Show if Spouse already exists as a Contact --> <apex:pageBlockSection title="Spouse Exists as a Contact" columns="1" rendered="{!SpouseCon.Spouse_Converted__c == 'SCon'}"> <h1>A contact named {!SpouseInfo.FirstName} {!SpouseInfo.LastName} already exists</h1> </br> Press Cancel to return. </apex:pageBlockSection> <!-- Show if Spouse's First Name not entered --> <apex:pageBlockSection title="No Spouse First Name" columns="1" rendered="{!SpouseCon.Spouse_Converted__c == 'NoFName'}"> <h1>Spouse must have a First Name entered</h1></br> Press Cancel to return and add Spouse First Name. </apex:pageBlockSection> </apex:pageBlock> </apex:actionregion> </apex:sectionheader> </apex:form> </apex:page>

 

I have two questions:

1.  Is this the best way to do this type of 'branching'?

 

2.  When I do a 'Quick Save' from the Salesforce VF Page editor I get a Warning stating that,

Warning: The element type "apex:pageBlockSection" should be terminated by the matching end-tag "</apex:pageBlockSection>". at line 16 

(the bold line in the code above).  Why am I getting this warning?

 

Mark

I am using VisualForce pages and Apex to convert a spouse to a contact.  A new button was added to the Contacts detail pages to call the VF page.  All is going fairly well, but I cannot get the detail page of the new contact to show.

 

Part of my custom controller code is shown below and is based on the 'The Opportunity Wizard Controller' section in the VF developers guide to show the detail page of the newly created contact.

 

//Save the new contact public PageReference NContact(){ Contact newcontact = new contact (LastName = SLNAME); insert newcontact; PageReference contactPage = new ApexPages.StandardController(contact).view(); contactPage.setRedirect(true); return contactPage;

I get the following error message:

System.NullPointerException: Argument 1 cannot be null

The bold line above is referenced.

I would like to use a variable to define the where clause in a query.

 

I have defined a variable SLName with:

 

SLName=[select id, LastName, spouse_last_name__c from contact

where id = :ApexPages.currentPage().getParameters().get('id')].spouse_last_name__c;

 

How do I make something like the following work?

 

public Contact getSpouseCon(){

if(iscon == null)iscon = [

select FirstName, LastName, spouse_converted__c from contact where Lastname = SLName];

iscon.spouse_converted__c = SLName; //SLName value set properly

return iscon;

 

I am trying to see if a contact exists with the LastName = SLName.

 

Thanks, Mark

I am attempting to use an s-control to create a new event (easy enough), but want it to apply to a specific record type.  The following is the code I have tried:
 
<script type="text/javascript">
window.parent.location.href="{!URLFOR($Action.Activity.NewEvent,null,
[retURL=URLFOR( $Action.Contact.View, Contact.Id)]
)} &recordtype='01280000000EpvVAAS'";
</script>
 
This allows me to create a new event, but the default record type is used instead of the one specified in the code.  How do I make this work?
 
Mark
I have loaded the Eclipse SDK 3.3.2 and am having a problem when attempting to edit the properties for my Mileage Tracker.  The programs hangs when I attempt to Add/Remove in the Project content.  All I see is a blank page for Choose Metadata Components.  Whats wrong?
When I export data using the Apex Data Loader, leading zeros are deleted.  What's the problem?

I and trying to use Apex to create a new Task, then return to the user with the new Task in Edit mode where the user can edit and save the new Task

 

This is what I have:

// Apex class for a new Tour on Lead.
// Called from VF Page LeadTourPg

public class NewLeadTour{
 public Lead si;
 public NewLeadTour() {}

// get ID of current Page (a Lead in this case)  
  public PageReference init() {
    Id siId = ApexPages.currentPage().getParameters().get('id');
 
       
//Declare Variables and strings 
    Lead lead;
    Account acc;   
    Task tsk;
   

    String CurrUser = UserInfo.getUserId();    //Get Current User
    
 //Get variables from current Lead Record   
    try {
      if (si==null)
      si = [SELECT Id, Name, OwnerID FROM lead WHERE Id = :siId];
    }
      catch(Exception e) {
    }
 
//Create a scheduled task
    if(si.Name!=null){   
    tsk = new Task();
    tsk.whoId = si.Id;
    tsk.OwnerId = currUser; 
    tsk.Subject = 'New Tour for ' + si.Name;
    tsk.Status = 'Not Started';
    //tsk.Description = 'User = '+ currUser;
    tsk.Priority = 'Normal';
    tsk.OwnerID = si.OwnerID;
    tsk.ActivityDate = date.today()+2;
  
try{
insert tsk;
}catch (Exception ex){system.debug('error creating a scheduled Task:'+ex);} 
}
 
return (new ApexPages.StandardController(tsk)).edit();
      
//return new PageReference('/'+tsk.Id);     
 
    
    }
    }

 

This does create a new Task and shows the new Task to me in edit mode.

However, when I edit the Task and click Save, the Task is saved, but I still see a Task in edit mode.  I cannot get out of this edit mode

 

Something wrong with this statment?

return (new ApexPages.StandardController(tsk)).edit();

 

I am VF Page to convert a spouse (in contacts) to a new contact.  I am using Multiple Page Block Sections to send information to the user based on the value of a custom field set in my custom controller.

<apex:page standardController="Contact" extensions="ConverSpouseExtension"> <apex:form > <apex:sectionheader title="Create Spouse As A New Contact"> <apex:actionregion > <apex:pageBlock title="Spouse Information" id="thePageBlock" mode="edit"> <apex:pageBlockButtons > <!-- Show Save Button if Spouse is not converted and Spouse has a First Name --> <apex:commandButton value="Convert" action="{!NContact}" rendered="{!SpouseCon.Spouse_Converted__c == 'SNCon'}" /> <apex:commandButton value="Cancel" action="{!cancel}"/> </apex:pageBlockButtons> <!-- Show if okay to Convert Spouse to a Contact --> <apex:pageBlockSection title="Spouse Ready to Convert to Contact" columns="1" rendered="{!SpouseCon.Spouse_Converted__c == 'SNCon'}"> <h1>Update information as needed and press 'Convert'</h1> </br> to convert Spouse to a Contact <apex:inputfield id="FirstName" value="{!SpouseInfo.FirstName}" /> <apex:inputfield id="LastName" value="{!SpouseInfo.LastName}" /> <apex:inputfield id="Email" value="{!SpouseInfo.Email}" /> <apex:inputfield id="Phone" value="{!SpouseInfo.Phone}" /> </apex:pageBlockSection> <!-- Show if Spouse already exists as a Contact --> <apex:pageBlockSection title="Spouse Exists as a Contact" columns="1" rendered="{!SpouseCon.Spouse_Converted__c == 'SCon'}"> <h1>A contact named {!SpouseInfo.FirstName} {!SpouseInfo.LastName} already exists</h1> </br> Press Cancel to return. </apex:pageBlockSection> <!-- Show if Spouse's First Name not entered --> <apex:pageBlockSection title="No Spouse First Name" columns="1" rendered="{!SpouseCon.Spouse_Converted__c == 'NoFName'}"> <h1>Spouse must have a First Name entered</h1></br> Press Cancel to return and add Spouse First Name. </apex:pageBlockSection> </apex:pageBlock> </apex:actionregion> </apex:sectionheader> </apex:form> </apex:page>

 

I have two questions:

1.  Is this the best way to do this type of 'branching'?

 

2.  When I do a 'Quick Save' from the Salesforce VF Page editor I get a Warning stating that,

Warning: The element type "apex:pageBlockSection" should be terminated by the matching end-tag "</apex:pageBlockSection>". at line 16 

(the bold line in the code above).  Why am I getting this warning?

 

Mark

I am using VisualForce pages and Apex to convert a spouse to a contact.  A new button was added to the Contacts detail pages to call the VF page.  All is going fairly well, but I cannot get the detail page of the new contact to show.

 

Part of my custom controller code is shown below and is based on the 'The Opportunity Wizard Controller' section in the VF developers guide to show the detail page of the newly created contact.

 

//Save the new contact public PageReference NContact(){ Contact newcontact = new contact (LastName = SLNAME); insert newcontact; PageReference contactPage = new ApexPages.StandardController(contact).view(); contactPage.setRedirect(true); return contactPage;

I get the following error message:

System.NullPointerException: Argument 1 cannot be null

The bold line above is referenced.

I would like to use a variable to define the where clause in a query.

 

I have defined a variable SLName with:

 

SLName=[select id, LastName, spouse_last_name__c from contact

where id = :ApexPages.currentPage().getParameters().get('id')].spouse_last_name__c;

 

How do I make something like the following work?

 

public Contact getSpouseCon(){

if(iscon == null)iscon = [

select FirstName, LastName, spouse_converted__c from contact where Lastname = SLName];

iscon.spouse_converted__c = SLName; //SLName value set properly

return iscon;

 

I am trying to see if a contact exists with the LastName = SLName.

 

Thanks, Mark

I am attempting to use an s-control to create a new event (easy enough), but want it to apply to a specific record type.  The following is the code I have tried:
 
<script type="text/javascript">
window.parent.location.href="{!URLFOR($Action.Activity.NewEvent,null,
[retURL=URLFOR( $Action.Contact.View, Contact.Id)]
)} &recordtype='01280000000EpvVAAS'";
</script>
 
This allows me to create a new event, but the default record type is used instead of the one specified in the code.  How do I make this work?
 
Mark
I have loaded the Eclipse SDK 3.3.2 and am having a problem when attempting to edit the properties for my Mileage Tracker.  The programs hangs when I attempt to Add/Remove in the Project content.  All I see is a blank page for Choose Metadata Components.  Whats wrong?
Hi I'm not able to pass a Field Value in URL to another page so that a Particular field is always prepopulated on page load.

I've my button code as this:
Code:
<apex:commandButton value="New Billing" onclick="javascript:{!URLFOR($Action.Billing__c.New,null,[retURL=URLFOR($Action.Task.View,task.Id),ActivityId__c=task.Id],false)}"/>
With this URL the value is Set correctly, but the value is not prefiled on page load :(.


 Now if I replace the value of URL to this:
Code:
<apex:commandButton value="New Billing" onclick="javascript:{!URLFOR($Action.Billing__c.New,null,[retURL=URLFOR($Action.Task.View,task.Id),00N80000002c4Qe=task.Id],false)}"/>

 Where 00N80000002c4Qe is ID value of the control on target page which is needed to be pre-populated. But this above throws me SYNTAX Error of missing Field Name.

Can anyone guide me how to properly Set Return URL as well as pass some custom values in URL from a VF page?


  • December 16, 2008
  • Like
  • 0
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="ProgId" content="Word.Document"><meta name="Generator" content="Microsoft Word 11"><meta name="Originator" content="Microsoft Word 11">

I have two custom objects sutTer__c (which i call TER for clarity) and sutTraveller__c (Traveller). TER object has a lookup field into Traveller. When the user creates a new TER, I want him to see the last name of the traveller. I tried to do it by overriding the new button of TER with the following s-control:

<html>

<head>

<title></title>

<script>

//First construct the new URL

var newUrl = "{!URLFOR( $Action.sutTer__c.New, null,

[Traveller__c=sutTraveller__c.Name, TravellerLastName__c=sutTraveller__c.LastName__c, retURL=$Request.retURL] ,true)}";

//Then redirect the user to it

window.parent.location.replace(newUrl);

</script>

</head>


but this does not work: the Traveller and "Traveller last name" fields are blank when i open a new TER. I tried different approaches as well (like putting the field id (from the URL) instead of the field name, but this couldnt be saved, i got always a syntax error massage).


Can someone give me advise about the write syntax for URLFOR parameters when i use cumstom objects?

  • December 12, 2008
  • Like
  • 0
I've looked up as many examples of URLFOR as I can find, and I think I'm following them nicely, but I'm getting an error when I try to save the S-Control that says Syntax error.  Found '['
 
I'm putting the [ just where it seems it should go in the examples.  Can anyone tell me what the problem is then with this thing??
 
thanks!!!
 
 
window.parent.location.href="{!URLFOR($Action.Project__c.New, null,[00N20000001AgKn=Case.Workstation_Product__c,00N20000001Aelf=Case.LastModifiedDate,
CF00N20000001Aels=Case.Related_Opportunity_Name__c,
00N20000001AgKr=Case.Workstation_Product_Version__c,
CF00N20000001Aelp=Case.Business_Contact__c,
CF00N20000001Aell=Case.Opportunity_Account__c],null)}"
I am trying to use URLFOR() and set some parameters to default some custom fields values. The custom fields start with two leading zeroes. The S-Control syntax checker does not seem to accept any parameter name that starts with numbers. I get "Error: Syntax error. Missing field name". The whole s-control is as follows and is used to override New Opportunity functionality to default some fields. Help! I've tried changing spaces between the quotes, param names, etc.
 
<script>
window.location.href='{!URLFOR($Action.Opportunity.New, null, [  isdtp="mn", save="x",00N40000001V3eK="test" ] , true)}'
</script>