Search

Tuesday, 23 October 2012

Apex:Variable

Oh how much I love this Apex:Variable

you can use it to do so many things, such as in an Apex:Repeat and tracking which element of the Repeat you are in, so if the user selects an item and you need to send this 1 change back to the controller and identify which item it is in the List object in the controller, you can easily do this using Apex:Variable


<apex:variable value="{!-1}" var="counter">
    <apex:Repeat value="{!zz}" var="x" >
        <apex:variable value="{!counter + 1}" var="counter" />

<apex:pageBlockSection title="" columns="2" >
<apex:pageBlockSectionItem >                  
                               <apex:outputLabel value="{!$ObjectType.XXX__c.fields.xxx.label}" />



<apex:selectList value="{!x.a__c}" size="1"  >
<apex:SelectOptions value="{!ss}"></apex:SelectOptions>
<apex:actionsupport event="onchange" action="{!ff}" rerender="qq" >
                           <apex:param name="g" assignTo="{!h}" value="{!x.tt__c}" />
<!-- <apex:param name="k" assignTo="{!k}" value="{!x.j__c}" /> -->
<apex:param name="v" assignTo="{!v}" value="{!counter}" />
</apex:actionsupport>
                      </apex:selectList>

</apex:pageBlockSectionItem>
                                                       
                        </apex:pageBlockSection>
                    </apex:outputpanel>
                   </apex:Repeat>






Or if you use <Apex:Variable value="{!X}" name="val" />

<Apex:outputText >
    <Apex:Param value="{!X}">
<Apex:outputText >

The outputText automatically inherits the param value which is set from the <Apex:Variable>

Here's a real example: This ensures that the outputText value number is displayed with , separated and to 2 decimal places even though the number could be provided to page in a different format


                   <apex:outputPanel >
                   <apex:variable var="tot" value="{!(l.dd__c * l.uu__c)}" />
                   <apex:outputText value="{0, number, ###,###,###,###.00}">
                    <apex:param value="{!l.ppp__c tot}"/>
</apex:outputText>
              </apex:outputPanel>



Add Values To A MultiPicklist In Apex

How easy is this

Simple as this create a String which separates the individual values with a ';' and assign the picklist to this String

myobj__c.myMultiPicklist__c = 'PicklistA;PicklistB;PicklistC';
update myobj__c;

Reflection In Salesforce

Where and how can we use reflection in Salesforce, well here's a good example

Say you have 3 classes that map values from 1 object to another.

Class A matches 3 fields from Object X to ObjectY
Class B matches 5 different fields from Object X to ObjectY
Class C matches 12 fields, same fields in Class A and B + 4 other fields from Object X to ObjectY

Instead of hard coding this mapping in the code provide it as a lookup to a custom object, which will allow you to change any mappings without having to rewrite and deploy new code. Also, will allow the code to be re-used in future projects.

Custom object Mapping__c
Name
FieldMappingGroup__c

Custom object FieldMappingGroup__c
Name

Custom object FieldMappings__c
Fields
FieldMappingGroup__c
Name - not unique
SourceObject__c
SourceField__c
DestinationObject__c
DestinationField__c


Mapping__c[] listofFieldToCopy = [Select (Select id From FieldMappingGroup__c ) From  Mapping__c where Name='XXX'];

set<id> mapIDs = new set<id>();
for (Mapping__c eachmap: listofFieldToCop){
     mapIDs.add(eachmap.FieldMappingGroup__.id);
}

FieldMappings__c[]  fieldMappings = [Select FieldMappingGroup__c , Name , SourceObject__c, SourceField__c, DestinationObject__c, DestinationField__c From FieldMappings__c where Id In: mapIDs];
For(String fieldName : fieldMappings )
Object1.put(fieldname, Object2.get(fieldname));


After writing all of this I've heard that Salesforce maybe introducing Reflection so this may not be necessary arrrgggghhh

Friday, 7 September 2012

This Best Article About IT I Simply Have Ever Read

I'm not going to introduce this article other than to say if you are even remotely connected to IT, be it an engineer, programmer, analyst, project manager, any manager, and even IT Directors

http://brucefwebster.com/2008/04/15/the-wetware-crisis-the-themocline-of-truth/

Only extra thing I would say to this is, if those in charge have unrealistic information the net affect is they may as well leave the building and never come back. Why? Their job is to direct, hence the name of the their job titles, if they are given inaccurate and unrealistic information they cannot direct affectively and therefore makes their job redundant. This is no fault directly of those who direct, but of those below who supply the information, but it is their fault for breeding an environment where it is the norm to supply inaccurate and unrealistic information to them. If you were to highlight the most important but equally difficult part of a leaders job it is to foster such an environment. This is what creates great leaders.

I've formed this opinion and knowledge only from what many people have told me of their experiences and what I've read.

Saturday, 1 September 2012

Self Evolving Software

I will be launching my long awaited App on the AppExchange in about 8 weeks. Wow how time flies, it's been 2 years + since I started developing my App, Self Evolving Software or SES.


SES is simply the holy grail of software development, the ability for a computer program to understand what is required in English and hunt down functions in the codebase to fulfill a particular requirement.

Development teams commonly duplicate code because they are not aware that the same function has already been developed by another developer, this may be in the same organization or not. Every time this happens an organization loses money in costly developers time and also by unnecessarily delaying IT projects.

SES literally automates the processes of finding relevant functions from the codebase and creating the code using these functions to fulfill the business requirement.

By utilizing crowd sourcing software development in SES is a catalyst to faster, more accurate and efficient software development.

Tuesday, 12 June 2012

Multiple Users on Tasks

Multiple Users on Tasks
Assigning a Task to Multiple Users sounded great. I was looking forward to 1 user out of a Group closing a Task, so whoever got there first would be able to close the Task.

Not quite. The new amazing piece of technology by Salesforce simply creates a Task for every user in the Public Group or Role.
 
Fantastic, not quite

Sunday, 10 June 2012

Salesforce to Salesforce Attachments Documents and Tasks

Ive blogged about Salesforce to Salesforce before and how to programmatically pass records from 1 org to another, but I wanted to blog about specifically how to pass over certain records, such as Attachments and Tasks etc


        list<PartnerNetworkRecordConnection> newrecords = new list<PartnerNetworkRecordConnection>();
        List<PartnerNetworkConnection> connMap = new List<PartnerNetworkConnection>();
        connMap=[select Id, ConnectionStatus, ConnectionName from PartnerNetworkConnection where ConnectionStatus = 'Accepted' and ConnectionName=<<connection>> LIMIT 1] ;
Account[] acc =[Select id From Account where Name = <<account>> limit 1];
Attachment[] attaches =[Select id,IsPartnerShared,Name  From Attachment where Parentid=: acc[0].id and IsPartnerShared=false limit 1];

               if (attaches.size() > 0){
                   Set<id> newfunctions = new Set<id>();
                   for(Attachment thisattach: attaches) {
            PartnerNetworkRecordConnection newrecord = SearchFunctionUtils.addPartnerNetworkRecordConnection(connMap);
                       if (!Test.isRunningTest()){
                        newrecord.LocalRecordId = acc[0].id ;
newrecord.RelatedRecords = 'Attachment';
                        newrecords.add(newrecord);
                       }
                       newfunctions.add(thisattach.id);//Attachments to be uploaded
                   }
                   insert newrecords;
 
}

The key difference is you have to set RelatedRecords and the LocalRecordId  is not the id of the Attachment but Id of the Account. There are also other standard objects which also require to use this method, which I have found are poorly documented. The best way of identifying which objects is probably by trial and error, but the Document object is another such object.

For Tasks SendClosedTasks and SendOpenTasks properties are important.


Seefor more details
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_partnernetworkrecordconnection.htm