• carmant
  • NEWBIE
  • 25 Points
  • Member since 2012

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

Hi,

 

We have a custom object (Supplier) that can be related to Case via a lookup.

 

Would like to set the Case currency the same as the Supplier, when a Supplier is chosen.

 

Doesnt seem to be possible via Workflow / Formula?

 

Just wanted to check if anyone else had come up against this and managed to do it declaritively? Otherwise I think it should be fairly simple via a Trigger.

 

Cheers,

Tom

 

A picture is worth a thousand words in this instance....

 

 

Problem.....

 

 

What would be preferable is...

 

 

 

Struggling to find a way to "merge cells"  - eg. have one field in colum A, but 2 in colum B  - all in the same row.

 

Just to note - the radio buttons are treated as one field.

 

Any advice appreciated, thanks!

Hi,

 

I am making a simple VF page with some date fields.

 

There is also a javascript to gray out boxes depending on which radio button is selected.

 

However, how can I stop the date fields from being autopopulated with the current date and time? I want them to be blank by default.

 

Date Fields

 

Here is the code:

 

<!-- Define controller, create main page block and first section -->
<apex:page controller="dashboardRadio">
<apex:PageBlock title="Dashboard">
<apex:pageBlockSection title="Select Type of Update" columns="1">

<!-- Java script to gray out n/a boxes -->
<script type="text/javascript"> function getActive(selectedValue) 
     {
        if( selectedValue == 'noDate') 
           { 
          var ele=document.getElementById('{!$Component.form1.startDate}');
              ele.disabled =true;
          var ele=document.getElementById('{!$Component.form1.endDate}');
              ele.disabled =true;
           }
        else if(selectedValue == 'oneDate')   
           {
           var ele=document.getElementById('{!$Component.form1.startDate}');
               ele.disabled =true;
           var ele=document.getElementById('{!$Component.form1.endDate}');
               ele.disabled =false;
           }
        else if(selectedValue == 'twoDate')
           {
           var ele=document.getElementById('{!$Component.form1.startDate}');
               ele.disabled =false;
           var ele=document.getElementById('{!$Component.form1.endDate}');
               ele.disabled =false;
           }
    }       
</script>

<style>
    .dateFormat{display:none;}
</style>



<apex:form id="form1">
<apex:selectRadio value="{!selectedValue}" layout="pageDirection" onchange="getActive(this.value);">
        <apex:selectOption itemValue="noDate" itemLabel="No date & time"/>
        <apex:selectOption itemValue="oneDate" itemLabel="Single date & time"/>
        <apex:selectOption itemValue="twoDate" itemLabel="Date & time span"/>
            </apex:selectRadio><p/>

        
      Start Date  <apex:inputField value="{!c.dashboard_start_date__c}" id="startDate" required="false"/><br></br>
    End Date  <apex:inputField value="{!c.dashboard_end_date__c}" id="endDate" required="false"/><br></br>
</apex:Form>
</apex:PageBlockSection>

</apex:PageBlock>        
</apex:page>
 

 

 

 

Thanks!

 

 

 

 

Hi,

 

Our org uses Person Accounts.

 

This trigger I wrote works perfectly when creating a Person Account. However it throws the following error when creating a normal business Account - 

 

System.QueryException: List has no rows for assignment to SObject: Trigger.CreateCase: line 14, column 1

 

Here is the trigger - 

 

//define trigger and when it fires
trigger CreateCase on Account (after insert) {


  //create list of cases to be inserted
  List<Case> newcase = new List<Case>();


  //find the ID of the correct record type
  Id rtId = [select Id, name from RecordType where name ='My Case Record Type' and SObjectType='Case' limit 1].Id;
  
  //find contact ID to attach to the to case
  Id personContact = [select id, Name from Contact where Contact.AccountId in : Trigger.New].Id;   

  // create some strings define criteria when the trigger fires
  for (Account acc: Trigger.New) {
  String corpacclink = acc.Corporate_Account_Link_Text__c;
  String mylink = 'My Link';
    if (corpacclink.contains(mylink))  
      {  
      //define what values to put against the new case
      newcase.add(new Case(
            AccountId = acc.Id,
            ContactId = personContact,
            RecordTypeId = rtId,
            Type='Welcome Call',
            Origin='Email',
            Status='Not Started',
            Call_Attempt__c='1'
            )
            );

      }
    
      //insert the new case(s)
      insert newcase;  
      }
  }

 

 

I understand WHY I am getting the error - the SOQL query looking for a Contact in line 14 isn't finding a Contact, because normal Accounts don't create Contacts (whilst Person Accounts do).

 

However - not sure how to fix this? Do I have to catch and handle the exception in some way? Or alternatively is there a way to get the trigger to only fire on Person Accounts?

 

Thanks!

Surprise surprise...after hacking a trigger together I am struggling with the test class...

 

The trigger is pretty simple - it creates a Case when an Account is created with certain criteria (may be worth pointing out our org uses PersonAccounts)

 

Here is the trigger:

 

//define trigger and when it fires
trigger CreateCase on Account (after insert) {
  
  //create list for cases to be inserted
  List<Case> newcase = new List<Case>();

  //find the ID of the correct record type
  Id rtId = [select Id, name from RecordType where name ='My Record Type' and   SObjectType='Case' limit 1].Id;

  //find contact ID which relates to the Account created to attach to the to case
  Id personContact = [select id, Name from Contact where Contact.AccountId in : Trigger.New].Id;

  //define criteria when the trigger fires
  for (Account acc: Trigger.New) {
    if (acc.Corporate_Account_Link_Text__c == 'My Corporate Account') {
      

      //define what values to put against the new case
      newcase.add(new Case(
            AccountId = acc.Id,
            ContactId = personContact,
            RecordTypeId = rtId,
            Type='My Type',
            Origin='My Origin',
            Status='My Status',
            Call_Attempt__c='1'
          )
      
        );
        }
    
      //insert the new case(s)
      insert newcase;  
    }
}

 

 

 

Have had a go with the test class, but not come up with much useful...any pointers appreciated!

 

Thanks

Hi,

 

I am trying to create a trigger that automatically creates a Case when an Account (PersonAccount) is created that meets certain criteria.

 

I have managed to get the trigger to create the Case, however, struggling to get it to link to Account. The field we normally use to link is the "Contact Name" - a Contact lookup field. Guessing this is because we use PersonAccounts and they are an amalgamation of Accounts & Contacts?

 

Here is what I have so far:

 

trigger CreateCase on Account (after insert) {
  
  List<Case> newcase = new List<Case>();

  Id rtId = [select Id, name from RecordType where name ='My Record Type' and SObjectType='Case' limit 1].Id;

  for (Account acc: Trigger.New) {
    if (acc.Custom_Field__c == 'My Criteria') {
 
      newcase.add(new Case(
            RecordTypeId = rtId,
            Type='My Type',
            Origin='My Origin',
            Status='My Status',

          )
        ); 

      insert newcase;  
    }
  }
}

 

Any help appreciated!

 

Thanks

Hi all,

 

Trying to get the Force.com Migration Tool setup.

 

Running it on Ubuntu (on a Linode).

 

Whenever I try and deploy the sample package, I get the following error:

 

BUILD FAILED
/home/tcarman/Salesforce/Files/sample/build.xml:46: Failed to login: Failed to send request to https://login.salesforce.com/services/Soap/u/24.0

 

 

Checked, double checked, and triple checked the username/password/URL in build.properties. Even tried putting the values directly into the build.xml and bypassing the build.properties alltogether....no luck. Yep - I'm using the security token.

 

Given SFDC shows nothing in login history, I don't think its an issue with the credentials. 

 

Perhaps Proxy issue? I don't know if Linode boxes require any special settings - and if so I can't find anywhere.

 

Also I'm pretty new to linux, so could be something silly I have missed.

 

Any advice, hugely appreciated :)

 

 

Hi,

 

Is there any way to assign page layouts via APEX or otherwise?

 

Use case:

  • We wish to limit which information/fields/related lists users view on the Account object, depending on the USER POSITION and the TYPE OF ACCOUNT
  • I'm open to suggestions on how we define their "position" - it could be via Groups, or via an additional parameter we create against their user record.
  • The TYPE of account is already defined by a field on the Account record (we dont use record types)
  • Eg. User clicks Account, code runs to check their position vs the type of account they are trying to view
  • If user is Position A, they are trying to view Account Type A, send to Page Layout A. 
    If  user is Position B, they are trying to view Account type A, send to Page Layout B
    If user is Postion A or B, they are trying to view Acount Type C, sent to Page Layout C
  • Would rather leverage Page Layouts rather than build VF pages, but thats still a possibility if its the only way.

 

Why I don't want to use profiles?

I know this could partly be achieved via profiles / page layout assignment. BUT we already have around 50 profiles, its a nightmare to manage already, and I would rather explore other methods of achieving this, as opposed to introducing a whole pile more profiles. ALso this would create "blanket" rules - eg. user of position (Profile) A would always see page layout A - we need this to be dynamic based on not only their position, but the TYPE of account that user is trying to view.

 

Any ideas or pointers greatly appreciated!

 

Thanks,

Tom

 

for(Task T1:trigger.new)
{
try{

for(opportunity o:Oppids)
{

if(T1.WhatId == o.id && (T1.Subject).startsWith('Email: BAS') ){

if(o.StageName =='Booking Acknowledged'){
o.BAS_Sent_Date__c=date.valueof(T1.CreatedDate);
o.StageName='Booking Verified';

}}

}
}catch(Exception e){system.debug('Exception Here'+e);}

Hi All,

 

I need some help with my trigger.  I have the following trigger that sends an email to the task creator when the task assignee has completed the task.  I would like to include the name of the Related To object in the email.  I have the WhatId in my code but this only pulls the Id of the record.  I tried WhatName but i dont think there is such a field.  

 

 

 

trigger TaskSendEmail on Task (before update) {
// Don't forget this- all triggers in SF are bulk triggers and so
// they can fire on multiple objects. So you need to process objects
// in a FOR loop.
Set<Id> CBIds = new Set<Id>();

for(Task tsk: Trigger.New)

if(tsk.RecordTypeId == '012G00000017Bb5' && tsk.Status == 'Completed' &&
tsk.OwnerId <> tsk.CreatedById)

CBIds.add(tsk.CreatedById);

// Build a map of all users who created the tasks.
Map<Id, User> userMap = new Map<Id,User>([select Name, Email from User where Id in :CBIds]);

for(Task tsk : Trigger.New){
if(!TriggerHelperClass.HasAlreadyFired()){

if(tsk.RecordTypeId == '012G00000017Bb5' && tsk.Status == 'Completed'
&&
tsk.OwnerId <> tsk.CreatedById)
{


User theUser = userMap.get(tsk.CreatedById);

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {theUser.Email};
mail.setToAddresses(toAddresses); // Set the TO addresses
mail.setSubject('The following Task has been Completed'); // Set the subject
// Next, create a string template. Specify {0}, {1} etc. in place of actual values.
// You can replace these values with a call to String.Format.
String template = 'The following Task has been Completed: \n\n';
template+= 'Related To: {0}\n';
template+= 'Subject: {1}\n';
template+= 'Comments: {2}\n\n';
template+= 'Click the link to access the record: https://cs9.salesforce.com/{3}\n';
String duedate = '';

if (tsk.ActivityDate==null)
duedate = '';
else
duedate = tsk.ActivityDate.format();

List<String> args = new List<String>();
args.add(tsk.WhatId);
args.add(tsk.Subject);
args.add(tsk.Description);
args.add(tsk.Id);




// Here's the String.format() call.
String formattedHtml = String.format(template, args);

mail.setPlainTextBody(formattedHtml);

TriggerHelperClass.setAlreadyFired();
Messaging.SendEmail(new Messaging.SingleEmailMessage[] {mail});

}
}
}
}

  • May 12, 2013
  • Like
  • 0

Hi,

 

I am making a simple VF page with some date fields.

 

There is also a javascript to gray out boxes depending on which radio button is selected.

 

However, how can I stop the date fields from being autopopulated with the current date and time? I want them to be blank by default.

 

Date Fields

 

Here is the code:

 

<!-- Define controller, create main page block and first section -->
<apex:page controller="dashboardRadio">
<apex:PageBlock title="Dashboard">
<apex:pageBlockSection title="Select Type of Update" columns="1">

<!-- Java script to gray out n/a boxes -->
<script type="text/javascript"> function getActive(selectedValue) 
     {
        if( selectedValue == 'noDate') 
           { 
          var ele=document.getElementById('{!$Component.form1.startDate}');
              ele.disabled =true;
          var ele=document.getElementById('{!$Component.form1.endDate}');
              ele.disabled =true;
           }
        else if(selectedValue == 'oneDate')   
           {
           var ele=document.getElementById('{!$Component.form1.startDate}');
               ele.disabled =true;
           var ele=document.getElementById('{!$Component.form1.endDate}');
               ele.disabled =false;
           }
        else if(selectedValue == 'twoDate')
           {
           var ele=document.getElementById('{!$Component.form1.startDate}');
               ele.disabled =false;
           var ele=document.getElementById('{!$Component.form1.endDate}');
               ele.disabled =false;
           }
    }       
</script>

<style>
    .dateFormat{display:none;}
</style>



<apex:form id="form1">
<apex:selectRadio value="{!selectedValue}" layout="pageDirection" onchange="getActive(this.value);">
        <apex:selectOption itemValue="noDate" itemLabel="No date & time"/>
        <apex:selectOption itemValue="oneDate" itemLabel="Single date & time"/>
        <apex:selectOption itemValue="twoDate" itemLabel="Date & time span"/>
            </apex:selectRadio><p/>

        
      Start Date  <apex:inputField value="{!c.dashboard_start_date__c}" id="startDate" required="false"/><br></br>
    End Date  <apex:inputField value="{!c.dashboard_end_date__c}" id="endDate" required="false"/><br></br>
</apex:Form>
</apex:PageBlockSection>

</apex:PageBlock>        
</apex:page>
 

 

 

 

Thanks!

 

 

 

 

Hi,

 

Our org uses Person Accounts.

 

This trigger I wrote works perfectly when creating a Person Account. However it throws the following error when creating a normal business Account - 

 

System.QueryException: List has no rows for assignment to SObject: Trigger.CreateCase: line 14, column 1

 

Here is the trigger - 

 

//define trigger and when it fires
trigger CreateCase on Account (after insert) {


  //create list of cases to be inserted
  List<Case> newcase = new List<Case>();


  //find the ID of the correct record type
  Id rtId = [select Id, name from RecordType where name ='My Case Record Type' and SObjectType='Case' limit 1].Id;
  
  //find contact ID to attach to the to case
  Id personContact = [select id, Name from Contact where Contact.AccountId in : Trigger.New].Id;   

  // create some strings define criteria when the trigger fires
  for (Account acc: Trigger.New) {
  String corpacclink = acc.Corporate_Account_Link_Text__c;
  String mylink = 'My Link';
    if (corpacclink.contains(mylink))  
      {  
      //define what values to put against the new case
      newcase.add(new Case(
            AccountId = acc.Id,
            ContactId = personContact,
            RecordTypeId = rtId,
            Type='Welcome Call',
            Origin='Email',
            Status='Not Started',
            Call_Attempt__c='1'
            )
            );

      }
    
      //insert the new case(s)
      insert newcase;  
      }
  }

 

 

I understand WHY I am getting the error - the SOQL query looking for a Contact in line 14 isn't finding a Contact, because normal Accounts don't create Contacts (whilst Person Accounts do).

 

However - not sure how to fix this? Do I have to catch and handle the exception in some way? Or alternatively is there a way to get the trigger to only fire on Person Accounts?

 

Thanks!

Surprise surprise...after hacking a trigger together I am struggling with the test class...

 

The trigger is pretty simple - it creates a Case when an Account is created with certain criteria (may be worth pointing out our org uses PersonAccounts)

 

Here is the trigger:

 

//define trigger and when it fires
trigger CreateCase on Account (after insert) {
  
  //create list for cases to be inserted
  List<Case> newcase = new List<Case>();

  //find the ID of the correct record type
  Id rtId = [select Id, name from RecordType where name ='My Record Type' and   SObjectType='Case' limit 1].Id;

  //find contact ID which relates to the Account created to attach to the to case
  Id personContact = [select id, Name from Contact where Contact.AccountId in : Trigger.New].Id;

  //define criteria when the trigger fires
  for (Account acc: Trigger.New) {
    if (acc.Corporate_Account_Link_Text__c == 'My Corporate Account') {
      

      //define what values to put against the new case
      newcase.add(new Case(
            AccountId = acc.Id,
            ContactId = personContact,
            RecordTypeId = rtId,
            Type='My Type',
            Origin='My Origin',
            Status='My Status',
            Call_Attempt__c='1'
          )
      
        );
        }
    
      //insert the new case(s)
      insert newcase;  
    }
}

 

 

 

Have had a go with the test class, but not come up with much useful...any pointers appreciated!

 

Thanks

Hi,

 

I am trying to create a trigger that automatically creates a Case when an Account (PersonAccount) is created that meets certain criteria.

 

I have managed to get the trigger to create the Case, however, struggling to get it to link to Account. The field we normally use to link is the "Contact Name" - a Contact lookup field. Guessing this is because we use PersonAccounts and they are an amalgamation of Accounts & Contacts?

 

Here is what I have so far:

 

trigger CreateCase on Account (after insert) {
  
  List<Case> newcase = new List<Case>();

  Id rtId = [select Id, name from RecordType where name ='My Record Type' and SObjectType='Case' limit 1].Id;

  for (Account acc: Trigger.New) {
    if (acc.Custom_Field__c == 'My Criteria') {
 
      newcase.add(new Case(
            RecordTypeId = rtId,
            Type='My Type',
            Origin='My Origin',
            Status='My Status',

          )
        ); 

      insert newcase;  
    }
  }
}

 

Any help appreciated!

 

Thanks

Hi all,

 

Trying to get the Force.com Migration Tool setup.

 

Running it on Ubuntu (on a Linode).

 

Whenever I try and deploy the sample package, I get the following error:

 

BUILD FAILED
/home/tcarman/Salesforce/Files/sample/build.xml:46: Failed to login: Failed to send request to https://login.salesforce.com/services/Soap/u/24.0

 

 

Checked, double checked, and triple checked the username/password/URL in build.properties. Even tried putting the values directly into the build.xml and bypassing the build.properties alltogether....no luck. Yep - I'm using the security token.

 

Given SFDC shows nothing in login history, I don't think its an issue with the credentials. 

 

Perhaps Proxy issue? I don't know if Linode boxes require any special settings - and if so I can't find anywhere.

 

Also I'm pretty new to linux, so could be something silly I have missed.

 

Any advice, hugely appreciated :)

 

 

I must be overlooking something very basic, but I don't understand why this code is throwing a DmlException error when I evoke the update.

 

I've stripped the code down to bare basics, hoping the problem would jump out at me - but it isn't.

 

public class FacultyApprovalWizard { private final Account thisStudent; public FacultyApprovalWizard() { thisStudent = [select Id, Name, Department_Notified_GPA__c, X2TOR_Recommendation__c, UNIV_Response_Due__c from Account where id = :System.currentPageReference().getParameters().get('id')]; } public Account getThisStudent() { return thisStudent; } public Attachment attachment { get { if (attachment == null) attachment = new Attachment(); return attachment; } set; } public PageReference saveAttachments() { // Add the attachment to our Person-Account(Student) record attachment.parentid = thisStudent.id; insert attachment; // redraw the page, so user can see their Attachment has been added to Student record PageReference page = ApexPages.currentPage(); page.setRedirect(true); return page; } public PageReference step1() { return Page.RequestFacultyApproval1; } public PageReference step2() { update thisStudent; return null; // return Page.RequestFacultyApproval2; } public PageReference cancel() { PageReference accountPage = new PageReference('/' + thisStudent.id); accountPage.setRedirect(true); return accountPage; } }

 

 

As soon as I hit the Update highlighted, I get this error.

 

 

System.DmlException: Update failed. First exception on row 0 with id 001Q0000002NXtJIAW;

first error: INVALID_FIELD_FOR_INSERT_UPDATE, Account: bad field names on

insert/update call: Name: [Name]

 

Class.FacultyApprovalWizard.step2: line 39, column 7
External entry point

 

 

If it's releveant, these are Person-Account fields (not regular Account fields). Here's the VF page (though I think the problem is in my Apex class):

 

 

<apex:page controller="FacultyApprovalWizard" tabStyle="Account"> <!-- ABSTRACT: Evoked from button on Applied Student Person-Account record type --> <!-- Navigates user through the step of sending Faculty Approval Request and Attachments. --> <!-- TEMP SID: 001Q0000002IwlC --> <apex:sectionHeader title="Submit for Faculty Approval Wizard" subtitle="Step 1: Select Attachments" /> <apex:form > <apex:pageBlock title="Student Information" mode="edit"> <apex:pageBlockButtons location="top"> <apex:commandButton action="{!step2}" value="Step 2: Select Faculty Reviewers" /> <apex:commandButton action="{!cancel}" value="Cancel" /> </apex:pageBlockButtons> <apex:pageBlockSection columns="1"> <apex:outputField value="{!thisStudent.Name}"/> <apex:inputField value="{!thisStudent.Department_Notified_GPA__c}" required="TRUE"/> <apex:inputField value="{!thisStudent.X2TOR_Recommendation__c}" required="TRUE"/> <br/> </apex:pageBlockSection> </apex:pageBlock> <apex:pageBlock title="Select Attachments"> <apex:pageBlockSection > <apex:inputFile value="{!attachment.body}" filename="{!attachment.name}"/> <apex:commandButton value="save" action="{!saveAttachments}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> <apex:relatedList list="NotesAndAttachments" subject="{!thisStudent}"/> </apex:page>

 

I did some stare and compare at this document article, but it looks like we're largely doing similar things.

Message Edited by JPSeabury on 04-21-2009 07:10 PM