• PawelWozniak
  • NEWBIE
  • 50 Points
  • Member since 2012

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 6
    Replies

I have created custom DateTime field on Lead "Status Change Date" it should store the date when status was changed from Open to other than Open.

 

Trigger code:

     public static void updateStatusChangeDate() {
     	String oldStatus = '';
     	String newStatus = '';
     	for (Lead l : Trigger.new) {
     		oldStatus = Trigger.oldMap.get(l.Id).Status;
     		newStatus = String.ValueOf(lead.Status);
			if (!newStatus.equals('Open') && oldStatus.equals('Open')) {
				l.ptt_Status_change_date__c = DateTime.now();	
			} else
			if (newStatus.equals('Open') && !oldStatus.equals('Open')) {
				l.ptt_Status_change_date__c = null; // This don't clear the value.
			}	
		}     	
     }

Problem is that l.ptt_Status_change_date__c = null; won't work. 

It does not set the field to empty value.

 

Please advise how to do that.

 

I want to diplay a table of products prices with product ID, have found that visualforce is making autoconversion which I want to avoid. 

 

The Apex SOQL query:

SELECT Id, Product2Id, Pricebook2Id, UnitPrice, CurrencyIsoCode, IsActive, UseStandardPrice FROM PricebookEntry WHERE // some coditions

 

Visualforce:
<apex:pageBlockTable id="pricesList" value="{!allPricesList}" var="price">
<!-- Id, Product2Id, Pricebook2Id, UnitPrice, CurrencyIsoCode, IsActive, UseStandardPrice -->
<apex:column headerValue="Product Id" value="{!price.Product2Id}" />
<apex:column headerValue="Pricebook Id" value="{!price.Pricebook2Id}"/>
<apex:column headerValue="CurrencyIsoCode" value="{!price.CurrencyIsoCode}"/>
<apex:column headerValue="UnitPrice" value="{!price.UnitPrice}"/>
<apex:column headerValue="UseStandardPrice" value="{!price.UseStandardPrice}"/>
<apex:column headerValue="IsActive" value="{!price.IsActive}"/>
</apex:pageBlockTable>

 

After page is rendered {!price.Product2Id} and {!price.Pricebook2Id} is changed to link to product/pricebook with its name. I want to have just salesforce ID here.

I tried:

{!price.Product2Id__r.Id} gives error: Invalid field Product2Id__r for SObject PricebookEntry

{!price.Product2Id.Id} error: Unknown property 'String.Id'

 

When I am diplaying content of List whoch hold values from SOQL which are given to VF page I see:

 

CurrencyIsoCode=EUR, IsActive=true, UseStandardPrice=false, Id=01uD000000B7LpVIAV, UnitPrice=1.00, Pricebook2Id=01sD0000000FE0sIAG, Product2Id=01tD0000001OvXoIAK
 

So conversion is made on VF page. How to stop it?

 

One of our users installed Salesforce Mobile for Android and synced about 700 contacts including private one. 

How to disable contact synchronization for this App?

He can not find anything under Settings -> Accounts. No synchronization with Salesforce.

Also in Salesforce Mobile there is no settings.

 

Phone is Samsung Galaxy SIII andorid 4.1.1

Is there a way to get from SOQL numbers ordered in natural order like 1, 5, 9, 10 not a 10, 1, 5, 9

 

I have query

SELECT Id, Name FROM  myObject__c ORDER BY Name ASC

 

results are passed to Visualforce apex:pageBlockTable where are displayed as:

 

Device 16
Device 2
Device 8

 

Users want to see them as 2,8,16.

I have a page with a button Create

<apex:commandButton value="Create" action="{!CreateLic}" >

 

and controller which search for specific file then puts it for download.

 

fileURL = '/servlet/servlet.FileDownload?file=' + att.Id; // where att.id is an attachement for a custom object record.

PageReference pr = new PageReference(fileURL);
pr.setRedirect(false);
return pr;

 

File is an binary encypted file with name as xxxx.lic so no text content.

 

This triggers file download dialog for Chrome and Firefox which is correct but Internet Explorer 9 (win 7) is trying to display content on a page it results in lot of characters displayed on the page as shown on image and no download possibility.

 

As an IE is a company standard we nedd to support it.

 

Is there a way to fix that?

 

 

I have two fields Picklist System with values SystemA, SystemB, SystemC and additional input text Configuration. 

I expect that if Pciklist System has value SystemB then inputtext Configuration is disabled. In all other cases it is enabled.

 

<apex:variable var="acDisabled" value="FALSE" /> 
<apex:inputField label="System:" id="System" value="{!ptt.ptt_System__c}" required="true" />
<apex:inputtext label="Configuration" id="Configuration" value="{!ptt.Configuration__c}" disabled="{!acDisabled}" /> 

 

I have found that using Visualfoce page variable I can controll that behavior so:

<apex:variable var="acDisabled" value="FALSE" /> 

 means that inputtext is enabled and

<apex:variable var="acDisabled" value="TRUE" /> 

 that it is disabled.

 

Question is how to control that variable? Or is there a better way with JS or JQuery to do that? 

I wouldlike to avoid using controller functionality and page reRender for that simple task.

 

The mian goal is to set up web service which accept few parameters and based on that returns the file.

As it is my first try with webservices I do not know too much about it.

 

Input http call is GET type: https://cs8.salesforce.com/services/apexrest/RemoteActivation?company=abc&street=xyz

so parameters are passed in URL, for simplicity lets use just those two parameters.

 

I have found this article http://wiki.developerforce.com/page/Creating_REST_APIs_using_Apex_REST and followed the sample code. 

 

As a result came up with that:

@RestResource(urlMapping='/RemoteActivation/*')
global class as_remoteActivationService {
	
@HttpGet 
	global static String remoteActivation(RestRequest req, RestResponse res) {
		String company = req.params.get('company');
		String street = req.params.get('street');
				
		System.debug('COMPANY: ' + company);
		System.debug('STREET: ' + street);
		return 'Done';
	}

and error when saving:

Save error: Invalid type: HTTP GET/DELETE methods do not support parameters 

 

Now I do not understant it. Example code exacly says:

@HttpGet
  global static List<Case> getOpenCases(RestRequest req, RestResponse res) {

 and I have done the same and getting error. Why?

I have page which use standard controller of Order__c with extension:

<apex:page standardController="Order__c" extensions="newOrderController" />

 I am able to display fields from Order__c:

 <apex:inputField label="Variant" value="{!Order__c.type__c}"/>

 

 on the same page want to place fields from EndUser__c object like that:

 

<apex:inputField label="Phone" value="{!End_User__c.phone__c}"/>

 it cause an error:  Error: Unknown property 'Order__cStandardController.End_User__c

 

So I added in controller:

 

sObject endUserObj = new End_User__c(); //End User Object

 

 and trying to acces fields of variable which hold an object:

 

<apex:inputField label="Phone" value="{!endUserObj.phone__c}"/>

 but still getting:

 

Error: Unknown property 'Order__cStandardController.cmEndUserObj' 

 

Tried to use this get and set methods:

    public sObject getEndUserObj () {
        return endUserObj;
    }
    
    public void setEndUserObj (sObject o) {
        this.endUserObj = o;
    }

 

but then getting error:

Error: Read access denied for {0}  

 
What kind of getters and setters should I use? 



 

Here is a requrement from client: 

 

 

In one line I need: field name, filed itself, and button.

This must be fitted inside one column of: <apex:pageBlockSection columns="2" >

 

So I came up with this:

 

<apex:pageBlockSectionItem >
    <apex:inputField label="Activation Counter" id="activationCounter" value="{!object.field__c}"/>
    <apex:commandButton value="Reset"/>
</apex:pageBlockSectionItem>

 which results in missing label:

 

So I wanted to add field label like this:

 

<apex:pageBlockSectionItem >
    <apex:outputLabel value="Activation Counter" for="activationCounter"/>
    <apex:inputField label="Activation Counter" id="activationCounter" value="{!object.field__c}"/>
    <apex:commandButton value="Reset"/>
</apex:pageBlockSectionItem>

 an now getting error:

 

Error: <apex:pageBlockSectionItem> may have no more than 2 child components

 

Is there a way to get it working together?

Hi,

I have written HTTP callout which calls external service like that:

  Http h = new Http(); 
        String strURL = BASE_URL +
        '?user=' + USER_NAME + 
        '&pwd=' + PWD;
        
        HTTPRequest req = new HttpRequest(); 
        req.setEndpoint(strURL); 
        req.setMethod('GET'); 

 Then response is checked for server errors and for callout aplication errors.

        try {
            HttpResponse res = h.send(req); 
            Integer statusCode = res.getStatusCode();
            String statusName = res.getStatus();
                // Check for returned code. 200 means OK. 
                if (StatusCode == 200) {
     
                    /* Parse error message returned by external app */
                    
                    String message_type = ''; 
String message_description = '';
String message_key = '';
String message_ref = '';

/* Code which process HTML response should go here */
errorMsg = 'Connected with server. Response: ' + 'Message type: ' + message_type; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, errorMsg)); } // Dsiplay error Msg if other status code is returned. else { errorMsg = 'Request failed. Please contact administrator. <br/> Error Code: <b>' + statusCode + '</b><br/> Error Message: <b>' + statusName + '</b>'; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING, errorMsg)); } } catch (System.CalloutException e) { System.debug('Callout ERROR: '+ e); }

 

 

 Sample HTML response from external service which contains information about error:

<?xml version="1.0" encoding="UTF-8" ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<span id="message_type" >ERROR</span>
<span id="message_description" >You are not allowed to use this function! </span>
<span id="message_key" >UNAUTHORIZED</span>
<span id="message_ref" >1341329156068</span>
</body>
</html>

 

Question is: How to extract informatins from HTML to their APEX varaiables?

Example:

<span id="message_type" >ERROR</span>  content should be assigned to   String message_type = ''; 

after processing  message_type should has value 'ERROR'

 

I have read about:

HttpResponse Class http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_restful_http_httpresponse.htm#httpresponse_class_name

XmlNode Class http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_xml_dom_xmlnode.htm

Document Class http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_xml_dom_document.htm

XmlStreamReader Class http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_XmlStream_reader.htm

but still not able to do anything usefull with that. 

Dear Community I am struggling with conversion of trigger to be bulk.

Trigger is set on Opportunity object, before insert and before update.

Task is simple. Get Owner Role Name and put it to field ptt_Owner_Role__c (Text 255)

 

I have already written code like this:

trigger ptt_Opportunity_Trigger on Opportunity (before insert, before update) {

updateOwnerRoleField();

public static void updateOwnerRoleField() { for (Opportunity currentOpp : Trigger.new) { Id ownerId = currentOpp.OwnerId; If (ownerId != null) { Id ownerRoleId = [Select UserRoleId From User WHERE User.Id=:ownerId].UserRoleId; String roleName = [SELECT Name FROM UserRole WHERE UserRole.Id=:ownerRoleId].Name; currentOpp.ptt_Owner_Role__c = roleName; } } }
}

 

 This works fine untill I need to do mass update of records. It is not bulk trigger and try to go beyound the limits because of SOQL statements in for loop. I understand the problem.

 

So I am trying to make it bulk using this article as a source http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_bulk_idioms.htm I have written this:

 

trigger ptt_Opportunity_Trigger on Opportunity (before insert, before update) {

updateOwnerRoleField();

public static void updateOwnerRoleField() {
	// For every Opportunity record, add its associated OwnerId 
    // to a set so there are no duplicates. 
    
    Set<Id> ownerIds = new Set<Id>();
    for (Opportunity opp : Trigger.new) 
        ownerIds.add(opp.OwnerId);
        
    // Query the Users for their associated RoleId
    
    Map<Id, User> entries = new Map<Id, User>(
        [select User.UserRoleId from User where id in :ownerIds]);
         
    // Now use the map to set the appropriate RoleId every Opportunity Owner Role field by the trigger. 
    
    for (Opportunity opp : Trigger.new)
(error)        opp.ptt_Owner_Role__c  = entries.get(User.UserRoleId).opp.OwnerId;
		
	}
}

 (error) means - Save error: Incompatible key type Schema.SObjectField for MAP<Id,User> 

and now I stuck.

 

I now that at this monet there is missing part for finding role name but at least I would like to see RoleID in field  

ptt_Owner_Role__c then I will add another step to discovery its name.

 

Please point what I am doing wrong. 

I have created custom DateTime field on Lead "Status Change Date" it should store the date when status was changed from Open to other than Open.

 

Trigger code:

     public static void updateStatusChangeDate() {
     	String oldStatus = '';
     	String newStatus = '';
     	for (Lead l : Trigger.new) {
     		oldStatus = Trigger.oldMap.get(l.Id).Status;
     		newStatus = String.ValueOf(lead.Status);
			if (!newStatus.equals('Open') && oldStatus.equals('Open')) {
				l.ptt_Status_change_date__c = DateTime.now();	
			} else
			if (newStatus.equals('Open') && !oldStatus.equals('Open')) {
				l.ptt_Status_change_date__c = null; // This don't clear the value.
			}	
		}     	
     }

Problem is that l.ptt_Status_change_date__c = null; won't work. 

It does not set the field to empty value.

 

Please advise how to do that.

 

I want to diplay a table of products prices with product ID, have found that visualforce is making autoconversion which I want to avoid. 

 

The Apex SOQL query:

SELECT Id, Product2Id, Pricebook2Id, UnitPrice, CurrencyIsoCode, IsActive, UseStandardPrice FROM PricebookEntry WHERE // some coditions

 

Visualforce:
<apex:pageBlockTable id="pricesList" value="{!allPricesList}" var="price">
<!-- Id, Product2Id, Pricebook2Id, UnitPrice, CurrencyIsoCode, IsActive, UseStandardPrice -->
<apex:column headerValue="Product Id" value="{!price.Product2Id}" />
<apex:column headerValue="Pricebook Id" value="{!price.Pricebook2Id}"/>
<apex:column headerValue="CurrencyIsoCode" value="{!price.CurrencyIsoCode}"/>
<apex:column headerValue="UnitPrice" value="{!price.UnitPrice}"/>
<apex:column headerValue="UseStandardPrice" value="{!price.UseStandardPrice}"/>
<apex:column headerValue="IsActive" value="{!price.IsActive}"/>
</apex:pageBlockTable>

 

After page is rendered {!price.Product2Id} and {!price.Pricebook2Id} is changed to link to product/pricebook with its name. I want to have just salesforce ID here.

I tried:

{!price.Product2Id__r.Id} gives error: Invalid field Product2Id__r for SObject PricebookEntry

{!price.Product2Id.Id} error: Unknown property 'String.Id'

 

When I am diplaying content of List whoch hold values from SOQL which are given to VF page I see:

 

CurrencyIsoCode=EUR, IsActive=true, UseStandardPrice=false, Id=01uD000000B7LpVIAV, UnitPrice=1.00, Pricebook2Id=01sD0000000FE0sIAG, Product2Id=01tD0000001OvXoIAK
 

So conversion is made on VF page. How to stop it?

 

I have page which use standard controller of Order__c with extension:

<apex:page standardController="Order__c" extensions="newOrderController" />

 I am able to display fields from Order__c:

 <apex:inputField label="Variant" value="{!Order__c.type__c}"/>

 

 on the same page want to place fields from EndUser__c object like that:

 

<apex:inputField label="Phone" value="{!End_User__c.phone__c}"/>

 it cause an error:  Error: Unknown property 'Order__cStandardController.End_User__c

 

So I added in controller:

 

sObject endUserObj = new End_User__c(); //End User Object

 

 and trying to acces fields of variable which hold an object:

 

<apex:inputField label="Phone" value="{!endUserObj.phone__c}"/>

 but still getting:

 

Error: Unknown property 'Order__cStandardController.cmEndUserObj' 

 

Tried to use this get and set methods:

    public sObject getEndUserObj () {
        return endUserObj;
    }
    
    public void setEndUserObj (sObject o) {
        this.endUserObj = o;
    }

 

but then getting error:

Error: Read access denied for {0}  

 
What kind of getters and setters should I use? 



 

Here is a requrement from client: 

 

 

In one line I need: field name, filed itself, and button.

This must be fitted inside one column of: <apex:pageBlockSection columns="2" >

 

So I came up with this:

 

<apex:pageBlockSectionItem >
    <apex:inputField label="Activation Counter" id="activationCounter" value="{!object.field__c}"/>
    <apex:commandButton value="Reset"/>
</apex:pageBlockSectionItem>

 which results in missing label:

 

So I wanted to add field label like this:

 

<apex:pageBlockSectionItem >
    <apex:outputLabel value="Activation Counter" for="activationCounter"/>
    <apex:inputField label="Activation Counter" id="activationCounter" value="{!object.field__c}"/>
    <apex:commandButton value="Reset"/>
</apex:pageBlockSectionItem>

 an now getting error:

 

Error: <apex:pageBlockSectionItem> may have no more than 2 child components

 

Is there a way to get it working together?

Hi,

I have written HTTP callout which calls external service like that:

  Http h = new Http(); 
        String strURL = BASE_URL +
        '?user=' + USER_NAME + 
        '&pwd=' + PWD;
        
        HTTPRequest req = new HttpRequest(); 
        req.setEndpoint(strURL); 
        req.setMethod('GET'); 

 Then response is checked for server errors and for callout aplication errors.

        try {
            HttpResponse res = h.send(req); 
            Integer statusCode = res.getStatusCode();
            String statusName = res.getStatus();
                // Check for returned code. 200 means OK. 
                if (StatusCode == 200) {
     
                    /* Parse error message returned by external app */
                    
                    String message_type = ''; 
String message_description = '';
String message_key = '';
String message_ref = '';

/* Code which process HTML response should go here */
errorMsg = 'Connected with server. Response: ' + 'Message type: ' + message_type; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, errorMsg)); } // Dsiplay error Msg if other status code is returned. else { errorMsg = 'Request failed. Please contact administrator. <br/> Error Code: <b>' + statusCode + '</b><br/> Error Message: <b>' + statusName + '</b>'; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING, errorMsg)); } } catch (System.CalloutException e) { System.debug('Callout ERROR: '+ e); }

 

 

 Sample HTML response from external service which contains information about error:

<?xml version="1.0" encoding="UTF-8" ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<span id="message_type" >ERROR</span>
<span id="message_description" >You are not allowed to use this function! </span>
<span id="message_key" >UNAUTHORIZED</span>
<span id="message_ref" >1341329156068</span>
</body>
</html>

 

Question is: How to extract informatins from HTML to their APEX varaiables?

Example:

<span id="message_type" >ERROR</span>  content should be assigned to   String message_type = ''; 

after processing  message_type should has value 'ERROR'

 

I have read about:

HttpResponse Class http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_restful_http_httpresponse.htm#httpresponse_class_name

XmlNode Class http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_xml_dom_xmlnode.htm

Document Class http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_xml_dom_document.htm

XmlStreamReader Class http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_XmlStream_reader.htm

but still not able to do anything usefull with that. 

Dear Community I am struggling with conversion of trigger to be bulk.

Trigger is set on Opportunity object, before insert and before update.

Task is simple. Get Owner Role Name and put it to field ptt_Owner_Role__c (Text 255)

 

I have already written code like this:

trigger ptt_Opportunity_Trigger on Opportunity (before insert, before update) {

updateOwnerRoleField();

public static void updateOwnerRoleField() { for (Opportunity currentOpp : Trigger.new) { Id ownerId = currentOpp.OwnerId; If (ownerId != null) { Id ownerRoleId = [Select UserRoleId From User WHERE User.Id=:ownerId].UserRoleId; String roleName = [SELECT Name FROM UserRole WHERE UserRole.Id=:ownerRoleId].Name; currentOpp.ptt_Owner_Role__c = roleName; } } }
}

 

 This works fine untill I need to do mass update of records. It is not bulk trigger and try to go beyound the limits because of SOQL statements in for loop. I understand the problem.

 

So I am trying to make it bulk using this article as a source http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_bulk_idioms.htm I have written this:

 

trigger ptt_Opportunity_Trigger on Opportunity (before insert, before update) {

updateOwnerRoleField();

public static void updateOwnerRoleField() {
	// For every Opportunity record, add its associated OwnerId 
    // to a set so there are no duplicates. 
    
    Set<Id> ownerIds = new Set<Id>();
    for (Opportunity opp : Trigger.new) 
        ownerIds.add(opp.OwnerId);
        
    // Query the Users for their associated RoleId
    
    Map<Id, User> entries = new Map<Id, User>(
        [select User.UserRoleId from User where id in :ownerIds]);
         
    // Now use the map to set the appropriate RoleId every Opportunity Owner Role field by the trigger. 
    
    for (Opportunity opp : Trigger.new)
(error)        opp.ptt_Owner_Role__c  = entries.get(User.UserRoleId).opp.OwnerId;
		
	}
}

 (error) means - Save error: Incompatible key type Schema.SObjectField for MAP<Id,User> 

and now I stuck.

 

I now that at this monet there is missing part for finding role name but at least I would like to see RoleID in field  

ptt_Owner_Role__c then I will add another step to discovery its name.

 

Please point what I am doing wrong.