• Souls
  • NEWBIE
  • 0 Points
  • Member since 2013
  • Systems Engineer

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

I have problems using the IsPortalUser flag on the User object in Apex.

 

This line gives the error:

List<User>lstUsers=[select Id, IsActive, IsPortalEnabled from User where IsActive=true and IsPortalEnabled=true];

 

We are on Enterprise Edition with Customer Portal licenses in our org.

 

The select statement works in the Development Console and in the Eclipse Salesforce Schema query interface

 

Any ideas?

 

/Mats

  • November 12, 2013
  • Like
  • 0

I have a solution where the Case object has got a Master/child relationship to the custom object Invoice__c.

 

I have overridden the standard view method with my own VF page in which the field linking master and child is displayed. Until Winter 14 you could click that link to get back to the parent but not any longer. Ajax renders the small popup properly when hovering over the link. But clicking the link does nothing.

 

I do not have clickjack protection enabled for custom VF Pages.

 

What is this?

 

/Mats

 

  • October 24, 2013
  • Like
  • 0

I have written an After Insert trigger on Case that re-assigns AccountId and Contact Id associated wiith the case based on if the case is created by a customer portal user or not.

 

The trigger will not compile because of  an error that I don't quite understand here:  Initial term of field expression must be a concrete SObject: LIST<Case>

 

It fails where I'm extracting the new Id from a map of Accounts keyed by a custom field: SSNumber__c and try to assign that Id to the Case.AccountId field (see ==> below). What am I doing wrong?

 

trigger AfterInsertCase on Case (after insert) {
	List<Id> lstCases = new List<Id>();
	List<String>lstSSNumbers=new List<String>();
// Find cases created by Customer Portals for (Case caseObj:Trigger.new) { if(caseObj.Account.IsCustomerPortal==true){ lstCases.add(caseObj.Id); lstSSNumbers.add(caseObj.SSNumber__c); } } // Create a map with the AccountID's keyed by SSNumber__c Map<String,Account>MapAccBySSNumber=new Map<String,Account>(); List<Account>lstAcc=new List<Account>([Select Id, SSNumber__c from Account where SSNumber__c IN:lstSSNumbers]); for(Account ac:lstAcc){ MapAccBySSNumber.put(ac.SSNumber__c,ac); } // Update the Case object with new references to Contact and Account List<Case>lstCaseInfo=new List<Case>([Select Id, AccountId, ContactId, SSNumber__c from Case where Id IN :lstCases]); list<Case>lstCasesToUpdate=new List<Case>(); for(Case cse: lstCaseInfo){ ==> cse.AccountId = MapAccBySSNumber.get(lstCaseInfo.SSNumber__c).Id; ==> cse.ContactId=MapAccBySSNumber.get(lstCaseInfo.SSNumber__c).Id; lstCasesToUpdate.add(cse); } update lstCasesToUpdate; }

 

  • September 11, 2013
  • Like
  • 0

I have a custom object which is a child object to Case where the standard “Create New” method is overridden and points to a custom Visualforce page. I want to handle two use cases, the proper one selected based on a property in the parent case.

 

I want to get hold of the parent case number (through the master/child relationship) and with it do a SOQL query to get the value of a certain field in the case object and based on this value I want to render the correct part of the VF page. The rest of the form fields are empty at this stage, ready to be populated manually.

 

So, basically I want to render the VF page based on information that is not available (?) before the page is rendered it seems.

  

I have tried doing the lookup in the constructor of the controller or through the page’s action method but that all takes place before the page is populated and thus I don’t get a valid case number to use as an argument for my SOQL query. How to go about this?

 

/Mats

  • March 18, 2013
  • Like
  • 0

I want to create custom clone button for the standard control "Account", but when i click on the "Custom Clone Button" it should clone the needed values of the Account record as well as the Children Record too. Your help is really appriciated. This should be done in a Visual Force Page.

 

 

Hi,

 

I am trying to show Pop-Up when I click a button.

 

I need to have button So that I can click button in Pop-Up to do some action.

 

Any Links will be appreciated..

  • October 24, 2013
  • Like
  • 0

I have written an After Insert trigger on Case that re-assigns AccountId and Contact Id associated wiith the case based on if the case is created by a customer portal user or not.

 

The trigger will not compile because of  an error that I don't quite understand here:  Initial term of field expression must be a concrete SObject: LIST<Case>

 

It fails where I'm extracting the new Id from a map of Accounts keyed by a custom field: SSNumber__c and try to assign that Id to the Case.AccountId field (see ==> below). What am I doing wrong?

 

trigger AfterInsertCase on Case (after insert) {
	List<Id> lstCases = new List<Id>();
	List<String>lstSSNumbers=new List<String>();
// Find cases created by Customer Portals for (Case caseObj:Trigger.new) { if(caseObj.Account.IsCustomerPortal==true){ lstCases.add(caseObj.Id); lstSSNumbers.add(caseObj.SSNumber__c); } } // Create a map with the AccountID's keyed by SSNumber__c Map<String,Account>MapAccBySSNumber=new Map<String,Account>(); List<Account>lstAcc=new List<Account>([Select Id, SSNumber__c from Account where SSNumber__c IN:lstSSNumbers]); for(Account ac:lstAcc){ MapAccBySSNumber.put(ac.SSNumber__c,ac); } // Update the Case object with new references to Contact and Account List<Case>lstCaseInfo=new List<Case>([Select Id, AccountId, ContactId, SSNumber__c from Case where Id IN :lstCases]); list<Case>lstCasesToUpdate=new List<Case>(); for(Case cse: lstCaseInfo){ ==> cse.AccountId = MapAccBySSNumber.get(lstCaseInfo.SSNumber__c).Id; ==> cse.ContactId=MapAccBySSNumber.get(lstCaseInfo.SSNumber__c).Id; lstCasesToUpdate.add(cse); } update lstCasesToUpdate; }

 

  • September 11, 2013
  • Like
  • 0

i cannot use the said function upon creating formula field(text)

I have a custom object which is a child object to Case where the standard “Create New” method is overridden and points to a custom Visualforce page. I want to handle two use cases, the proper one selected based on a property in the parent case.

 

I want to get hold of the parent case number (through the master/child relationship) and with it do a SOQL query to get the value of a certain field in the case object and based on this value I want to render the correct part of the VF page. The rest of the form fields are empty at this stage, ready to be populated manually.

 

So, basically I want to render the VF page based on information that is not available (?) before the page is rendered it seems.

  

I have tried doing the lookup in the constructor of the controller or through the page’s action method but that all takes place before the page is populated and thus I don’t get a valid case number to use as an argument for my SOQL query. How to go about this?

 

/Mats

  • March 18, 2013
  • Like
  • 0

When developing a Visualforce page for overiding view page for any object, one problem that creeps up is to display the History details of a record. The standard related list Component doesn't works for History.

 

With the help of some code from Community ( I now can't find the link to it :( ), I wrote my own code  then to display the history of an object. It mimics the standard list as far as possible.  

 

Heres the code. It is for the Case object but it can be used for any other object.

 1.Component Code

 

<apex:component controller="CaseHistoriesComponentController">
<!-- Attribute Definition -->
<apex:attribute name="CaseId" description="Salesforce Id of the Case whose Case History needs to be rendered" type="Id" required="true" assignTo="{!caseId}" />

<!-- Case History Related List -->
<apex:pageBlock title="Case History">
<apex:pageBlockTable value="{!histories}" var="History" >
<apex:column headerValue="Date" value="{!History.thedate}"/>
<apex:column headerValue="User"> <apex:outputLink value="/{!History.userId}"> {!History.who} </apex:outputLink></apex:column>
<apex:column headerValue="Action"><apex:outputText escape="false" value="{!History.action}"/></apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:component>

 

 

 

 

2. Apex Code

 

public class CaseHistoriesComponentController {

public Id caseId {get; set;}
public cHistories[] histories;

// Variables
public Static final Map<String, Schema.SObjectField> CaseFieldmap = Schema.SObjectType.Case.fields.getMap();
public Static final List<Schema.PicklistEntry> fieldPicklistValues = CaseHistory.Field.getDescribe().getPicklistValues();

public List<cHistories> getHistories()
{
list<cHistories> histories = new list<cHistories>();
String prevDate = '';
for(CaseHistory cHistory : [Select CreatedDate, CreatedBy.Name, CreatedBy.Id, Field, NewValue, OldValue from CaseHistory where CaseId = :caseId order by CreatedDate desc])
{
if((cHistory.newValue == null && cHistory.oldValue == null)
|| (cHistory.newValue != null && !(string.valueOf(cHistory.newValue).startsWith('005') || string.valueOf(cHistory.newValue).startsWith('00G')))
|| (cHistory.oldValue != null && !(string.valueOf(cHistory.oldValue).startsWith('005') || string.valueOf(cHistory.oldValue).startsWith('00G'))))
{
cHistories tempHistory = new cHistories();
// Set the Date and who performed the action
if(String.valueOf(cHistory.CreatedDate) != prevDate)
{
tempHistory.theDate = String.valueOf(cHistory.CreatedDate);
tempHistory.who = cHistory.CreatedBy.Name;
tempHistory.userId = cHistory.CreatedBy.Id;
}
else
{
tempHistory.theDate = '';
tempHistory.who = '';
tempHistory.userId = cHistory.CreatedBy.Id;
}
prevDate = String.valueOf(cHistory.CreatedDate);

// Get the field label
String fieldLabel = CaseHistoriesComponentController.returnFieldLabel(String.valueOf(cHistory.Field));

// Set the Action value
if (String.valueOf(cHistory.Field) == 'created') { // on Creation
tempHistory.action = 'Created.';
}
else if(cHistory.OldValue != null && cHistory.NewValue == null){ // when deleting a value from a field
// Format the Date and if there's an error, catch it and re
try {
tempHistory.action = 'Deleted ' + Date.valueOf(cHistory.OldValue).format() + ' in <b>' + fieldLabel + '</b>.';
} catch (Exception e){
tempHistory.action = 'Deleted ' + String.valueOf(cHistory.OldValue) + ' in <b>' + fieldLabel + '</b>.';
}
}
else{ // all other scenarios
String fromText = '';
if (cHistory.OldValue != null) {
try {
fromText = ' from ' + Date.valueOf(cHistory.OldValue).format();
} catch (Exception e) {
fromText = ' from ' + String.valueOf(cHistory.OldValue);
}
}

String toText = '';
if (cHistory.OldValue != null) {
try {
toText = Date.valueOf(cHistory.NewValue).format();
} catch (Exception e) {
toText = String.valueOf(cHistory.NewValue);
}
}
if(toText != '')
tempHistory.action = 'Changed <b>' + fieldLabel + '</b>' + fromText + ' to <b>' + toText + '</b>.';
else
tempHistory.action = 'Changed <b>' + fieldLabel;
}

// Add to the list
histories.add(tempHistory);
}
}

return histories;
}

// Function to return Field Label of a Case field given a Field API name
public Static String returnFieldLabel(String fieldName)
{
if(CaseHistoriesComponentController.CaseFieldmap.containsKey(fieldName))
return CaseHistoriesComponentController.CaseFieldmap.get(fieldName).getDescribe().getLabel();
else
{
for(Schema.PicklistEntry pickList : fieldPicklistValues)
{
if(pickList.getValue() == fieldName)
{
if(pickList.getLabel() != null)
return pickList.getLabel();
else
return pickList.getValue();
}
}
}
return '';
}
// Inner Class to store the detail of the case histories
public class cHistories {

public String theDate {get; set;}
public String who {get; set;}
public Id userId {get; set;}
public String action {get; set;}
}
}

  Let me know your views on the code or if you have any questions