visualforce page not workign as expected - visualforce

I have a requirement where I need to create 2 record types in contacts object called Big Deal & Storefront.
Now I have to create a picklist field called Department for a User and it has 2 values which are Big Deal & Storefront.
When the user whose picklist value is set to say Big Deal logins in to salesforce and opens an account which has contacts of both the record types, the related list (contact) must display only the records of the recordtype with which the user has logges in by setting the picklist value in users.
I've written a standard controller for this and it displays the expected result in the backend but does not work as expected when I tested in the UI.
Please help me. I am a newbie to salesforce.
VF Page :
<apex:page standardController="Account" extensions="myStandardControllerExtension">
<apex:detail subject="{!Account}" relatedList="false"/>
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!con}" var="c" rendered="{!NOT(ISNULL(con))}">
<apex:column value="{!c.name}"/>
<apex:column value="{!c.phone}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
public class myStandardControllerExtension {
public String accname{get;set;}
public List<Contact> con {get;set;}
public myStandardControllerExtension(ApexPages.StandardController acon){
getRecords();
}
public List<Contact> getRecords() {
User u = [SELECT Department__c FROM User WHERE id=:userinfo.getuserId()];
String departmentPicklist = u.department__c;
System.debug('*** User : ' + u);
RecordType rt = [SELECT Id,Name FROM RecordType WHERE name = :departmentPicklist Limit 1];
List<Contact> con = [Select id,LastName,Name FROM Contact WHERE RecordTypeId = : rt.Id];
System.debug('*** con : ' + con );
return con;
}
}

Related

How to bind checkbox to dto in freemarker

I would like to update a dto with a form.
It works with text fields:
<#spring.formInput "updateable.name" "" "text"/> , but I have problem with checkboxes.
The dto has a List and I would like to delete from it roles, or add new roles to it as you check or uncheck the options on the form after submit.
I tried roles with HashMap, and I put all roles into it:
roles.put(roleDto.getId().toString(), roleDto.getName());
Form:
<#spring.formCheckboxes path="updateable.roles" options="${roleMap}" separator="<br>"/>
Converter:
#Override
public RoleDto convert(final String id) {
System.out.println("Trying to convert id=" + id + " into a role");
int parseId = Integer.parseInt(id);
int index = parseId - 1;
List<RoleDto> roleDtos = roleApi.fetchAllRoles();
return roleDtos.get(index);
}
The output is:
[Expected a string or something automatically convertible to string (number, date or boolean),
or "template output" , but this has evaluated to an extended_hash
(wrapper: f.t.SimpleHash):==> roleMap
So I don't even see the checkboxes on the form.

Can Dynamics Crm PartyList store an emailaddress

I have fields in activity form for email. It contains "to, cc and bcc" fields that are all fields of the type PartyList
The question is: Can I only store entity values like contact or account or can I also just store a email address which is not associated to any contact or account in the system?
Here is a picture explaining what I'm trying to achieve
As per this article it appears that the answer is yes via the addressUsed field.
Entity email = _sdk.Retrieve("email", emailId, new ColumnSet("to"));
EntityCollection to = email.GetAttributeValue<EntityCollection>("to");
if (to != null)
{
to.Entities.ToList().ForEach(party =>
{
EntityReference partyId = party.GetAttributeValue<EntityReference>("partyid");
bool isDeleted = party.GetAttributeValue<bool>("ispartydeleted");
string addressUsed = party.GetAttributeValue<string>("addressused");
// Do something...
});
}

Access ProcessId and StageId in Dynamics CRM Plugin

I'm writing a plugin on Campaign which used a Business Process Flow. The fields ProcessId and StageId which are created by the Business Process Flow in Campaign Entity. I need to retrieve these values for a record in my plugin.
They don't appear in the Plugin Registration Tool's Step Image. They don't even appear in CRM workflows were I can populate them in some other field.
Is there a good alternative on how I can achieve this?
Why not just grab a service from your IServiceProvider, and retrieve the fields?
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = CommonPluginLibrary.GetContextFromIServiceProvider(serviceProvider);
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(context.UserId);
Entity campaign = service.Retrieve(context.PrimaryEntityId, context.PrimaryEntityName, new ColumnSet("processid", "stageid"));
// ...
// Do your stuff with campaign["processid"], campaign["stageid"]
// ...
}
Another approach would be creating two shadow fields for stageid and processid (e.g. new_stageid, new_processid), and populating these fields using a synchronous workflow that triggers on process/stage update.
Then, you could register your plug-in on these shadow fields as they would be your entity's custom attributes.
You should be able to retrieve this by passing the correct input parameters to a workflow activity in this business process flow.
1) if you have these string inputs:
[RequiredArgument]
[Input("Process Name")]
public InArgument Process { get; set; }
[RequiredArgument]
[Input("Process Stage Name")]
public InArgument ProcessStage { get; set; }
2) Execute code Get Process:
using (var _context= new OrganizationServiceContext(service))
{
// Get the processid using the name provided
var process = (from p in _context.CreateQuery()
where
p.Name == Process.Get(executionContext)
&&
p.StateCode == WorkflowState.Activated
select new Workflow
{WorkflowId = p.WorkflowId}
).FirstOrDefault();
if (process==null)
throw new InvalidPluginExecutionException(string.Format("Process '{0}' not found",Process.Get(executionContext)));
Get the stage id using the name provided
var stage = (from s in _context.CreateQuery()
where
s.StageName == ProcessStage.Get(executionContext)
&&
s.ProcessId.Id == process.WorkflowId
select new ProcessStage
{ProcessStageId = s.ProcessStageId}
).FirstOrDefault();
if (stage == null)
throw new InvalidPluginExecutionException(string.Format("Stage '{0}' not found", Process.Get(executionContext)));
You can now Change Update the stage with your values retrieved ...
Entity uStage = new Entity(context.PrimaryEntityName);
uStage.Id = context.PrimaryEntityId; //
uStage["stageid"] = stage.ProcessStageId; //retrieved stage
uStage["processid"] = process.WorkflowId; //process id
To access process and stage ids you can use processid and stageid fields of record. I'm pretty sure that you can get it from Images or through direct read of a record. Additionally you can recheck following article:
https://deepakexploring.wordpress.com/tag/updating-process-id-in-crm-2013/

Creating a Salesforce Apex Trigger to update a lookup field in the Contacts object

I have created a trigger that will auto-create a contact when a specific Account record type is created or updated. The problem is that I am not sure how to populate the Contact 'Account Name' lookup field. This field is a lookup to the Account object. My code is below. Any help on how to integrate this missing component would be greatly appreciated.
trigger autoCreateContact on Account (after update, after insert)
{
List newContact = new List();
for (Account oAccount : trigger.new)
{
if (oAccount.RecordTypeid == '012F0000001MCfgIAG')
{
List<Contact> cCheck = [SELECT ID From Contact WHERE LastName=:oAccount.Name];
if(cCheck.isEmpty()==True)
{
System.debug(oAccount);
Contact oContact = new Contact();
oContact.LastName = oAccount.Name;
oContact.phone = oAccount.Phone;
oContact.email = oAccount.Email__c;
oContact.Owner = oAccount.Owner;
newContact.add(oContact);
}
}
if(newContact.isEmpty() == false)
{
Database.insert(newContact);
}
}
}
nice trigger I'm pretty sure you just need to add one line which is a reference to the account.id.
So if I were you I would add the link:
oContact.AccountID = oAccount.id;
NOTE: its not a good practice to have a SOQL inside the for loop.

Custom column in LinqServerModeDataSource

I have table in my database names User with fields:
Id
FirstName
LastName
LoginName
Now I would like to present this table in ASPxGridView using LinqServerModeDataSource.
What I did is :
<dxdtlnq:LinqServerModeDataSource ID="LinqServerModeDataSource1" runat="server" OnSelecting="LinqServerModeDataSource1_OnSelecting"
ContextTypeName="MyContext" EnableDelete="True"
EnableInsert="True" EnableUpdate="True" TableName="Users" >
</dxdtlnq:LinqServerModeDataSource>
protected void LinqServerModeDataSource1_OnSelecting(object sender, LinqServerModeDataSourceSelectEventArgs e)
{
MyContext context = new MyContext();
var qry = from s in context.Users select s;
e.QueryableSource = qry;
}
That works great with my ASPxGridView. I can display data, insert and delete but now I would like to have additional column UserName which is FirstName + LastName.
So I did something like that:
Added appropriate column to my ASPxGridView (FieldName = "UserName")
and modified OnSelecting handler:
protected void LinqServerModeDataSource1_OnSelecting(object sender, LinqServerModeDataSourceSelectEventArgs e) {
KozuModelDataContext context = new MyContext();
var qry = (from s in context.Substitutions
select new
{
Id = s.Id,
FirstName = s.FirstName,
LastName = s.LastName,
LoginName = s.LoginName,
UserName = s.FirstName + " " + s.LastName,
}).AsQueryable();
e.KeyExpression = "Id";
e.QueryableSource = qry;
}
Now data in the grid is displayed buyt when I want to insert or edit data fields cannot be filled, textboxes doesnt respond in inserting form I cant type in any text.
Is there any solution for inserting and editing data in this manner ?
Thanks for help
I have tried to reproduce this issue and see this behavior. To be able to edit data using this approach, I suggest that you do the following:
1) Handle the ASPxGridView.CellEditorIntitialize event and set the e.Editor.ReadOnly property to false. This will allow the end-user to modify data in the EditForm editors;
2) Handle the ASPxGridView.RowUpdating (RowInserting) event and update data manually. Also, you should set the e.Cancel parameter to true (to prevent the grid from updating data itself) and also call the GridView's CancelEdit method to close the EditForm.
I should also mention that there is no need to fetch data for the UserName from the DB. This can be done using the ASPxGridView's CustomColumnDisplayText event handler:
protected void ASPxGridView1_CustomColumnDisplayText(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewColumnDisplayTextEventArgs e) {
if(e.Column.FieldName == "") {
object[] values = ASPxGridView1.GetRowValues(e.VisibleRowIndex, new string[] { "FirstName", "LastName" }) as object[];
e.DisplayText = values[0].ToString() + " " + values[1].ToString();
}
}
If this approach works for you, you can avoid using the Selecting event and thus set the LinqServerModeDataSource's TableName. This will allow you to provide the data editing feature not using the approach I explained above.

Resources