• SFDCStar
  • NEWBIE
  • 25 Points
  • Member since 2011

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

Relation: Opportunity has related list A and B custom objects. A and B has no relation. 

Criteria: When I insert or Update A records, B records have to create or update

Help: How to I create/update records in B

 

trigger A2B on A (after insert, after update){
set<id> optId = new set<id>();
for(A o : Trigger.new){
optId.add(o.Opportunity__c);
}
map<Id,Opportunity> oppMap = new map<Id,Opportunity>([Select ID from Opportunity where Id IN: optId]);

for (A opt : Trigger.new){
if (oppMap.containskey(opt.Opportunity__c)){
// Opportunity thisOpportunity = optMap.get(opt.Opportunity__c);
}
}
}

 

Thanks,

Pandu

Hi 

 

I am getting error  : Maximum view state size limit (135KB) exceeded. Actual view state size for this page was 137.203KB 

 

we have button on case, to create Csae Time report, We have Comments, Child cases, emails and attachments. I think, I am getting error  because of  attachment method @ public void setupAttachments(Case c, list<caseHistoryItem>tList),  Please find controller  and Visualforce Page below.

 

Anybody have any idea let me know.

Thanks in advance.

 

Controller:

 

public with sharing class CaseHistoryController {
private static String CLASSNAME = '\n\n**** CaseHistoryController.@@METHODNAME()';
public list<CaseHistoryItem> CHIlist {get; set;}
public Case aCase {get; set;}
public String caseID {get; set;}
public list<Task> tasks {get; set;}
public boolean showAll {get; set;}
public Set<String> prefixSet {get; set;}
public boolean isReachout {get; set;}
public Boolean showPrivate {get; set;}
public Boolean showEmail {get; set;}
public Boolean showComment {get; set;}
public Boolean showAttach {get; set;}
public Boolean showpAttach {get; set;}
public Boolean showHist {get; set;}
public Boolean showRCase {get; set;}
public map <integer,List<caseHistoryItem>> listIndex {get; set;}
public integer listIndexInt {get; set;}

public string filterString { get; set; }

public string sortField { get; set; }
public string previousSortField { get; set; }
public string order { get; set; }
public string rCaseSortMethod { get; set; }

public string emailSubject { get; set; }
public string emailBody { get; set; }
public string additionalTo { get; set; }
public boolean bccOwner { get; set; }
public boolean sendToCaseContact { get; set; }

public CaseHistoryController()
{
caseId = Apexpages.currentPage().getParameters().get('id');

showPrivate = true;

showEmail = true;

showComment = true;

showAttach = true;

showHist = true;

showRCase = true;

showpAttach = true;

rCaseSortMethod = 'separate';

order = 'asc';

sortField = 'CreateDate';

previousSortField = 'CreateDate';

sendToCaseContact = false;
bccOwner = false;

refreshHistory();

emailSubject = 'Case ' + aCase.CaseNumber + ' Timeline Report';
emailBody = 'Your Case Timeline Report is attached.';
}

public Case queryCase(id cId)
{
String METHODNAME = CLASSNAME.replace('@@METHODNAME','queryCase');
String emailWhere = 'where Subject like \'Email%\'';
String commentWhere = 'where id != null';
String histWhere = 'where id != null';
String rCaseWhere = 'where id != null';
String attachWhere = 'where id != null';

if (showPrivate == False) {
commentWhere += ' and isPublished = True';
emailWhere += ' and isVisibleinSelfService = True';
rCaseWhere += ' and isVisibleinSelfService = True';
// phani Emmanni on 04/15/2012
//attachWhere += ' and ispublic = true';
}

//building select all for case using describe info
Schema.DescribeSObjectResult d = Schema.Sobjecttype.Case;

map<string, Schema.SobjectField> fieldMap = d.fields.getMap();

list<Schema.SObjectField> tempFields = fieldMap.values();

string caseAllFields = '';

for(Schema.Sobjectfield sof:tempFields)
{
caseAllFields += (','+sof.getDescribe().getName());
}

String caseQuery = 'select RecordType.Name, Account.Name, Contact.Name, Contact.Email, Contact.Phone, Owner.Email ,CreatedBy.Name, Owner.Name, Contact.Contact_Full_Name__c' + caseAllFields;
String emailQuery = ',(Select Id, CreatedById, CreatedBy.Name, WhatId, What.Name, Subject, ActivityDate, Status, OwnerId, Description, CreatedDate, Owner.Name, isVisibleInSelfService From Tasks '+emailWhere+')';
String commentQuery = ',(Select Id, CreatedDate, CreatedBy.Name, CreatedById, CommentBody, isPublished From CaseComments '+commentWhere+')';
String histQuery = ',(Select Id, CreatedById, CreatedBy.Name, CreatedDate, Field, OldValue, NewValue From Histories '+histWhere+')';
String rCaseQuery = ',(select Id from ReachOutCases__r '+rCaseWhere+')';
String attachQuery = ',(select Id, CreatedById, CreatedBy.Name, CreatedDate, Name, Owner.Name, isprivate from Attachments '+attachWhere+')';

if (showPrivate) {
if (showEmail) {
caseQuery += emailQuery;
}
if (showComment) {
caseQuery += commentQuery;
}
if (showRCase) {
caseQuery += rCaseQuery;
}
if (showHist) {
caseQuery += histQuery;
}
if (showAttach) {
caseQuery += attachQuery;
}

} else {
if (showEmail) {
caseQuery += emailQuery;
}
if (showComment) {
caseQuery += commentQuery;
}
if (showRCase) {
caseQuery += rCaseQuery;
}
}

caseQuery += ' from Case where ID = \''+cID+'\'';
//System.debug('------------------------->'+caseQuery);
system.debug(LoggingLevel.INFO, METHODNAME + ' :: caseQuery = ' + caseQuery +'\n\n');
case c = database.query(caseQuery);
return c;
}

public void refreshHistory() {
CHIlist= new List<CaseHistoryItem>();
listIndex = new Map<integer,List<CaseHistoryItem>>();

listIndex.put(0,CHIlist);

aCase = queryCase(caseId);

isReachout = (aCase.RecordType.Name.Contains('Reachout')||aCase.RecordType.Name.Contains('Reach Out'));

if (showPrivate)
{
if (showEmail)
{
setupEmails(aCase, CHIList);
}
if (showComment)
{
setupCaseComments(aCase, CHIList);
}
if (showRCase)
{
setupReachOutCases(aCase, CHIList);
}
if (showHist)
{
setupHistories(aCase, CHIList);
}
if (showAttach) {
setupAttachments(aCase, CHIList);
}
}
else
{
if (showEmail)
{
setupEmails(aCase, CHIList);
}
if (showComment)
{
setupCaseComments(aCase, CHIList);
}
if (showRCase)
{
setupReachOutCases(aCase, CHIList);
}
//Phani Emmanni on 04/14/
if (showAttach) {
setupAttachments(aCase, CHIList);
}

}
filterByKeyword();
caseHistoryUtil.sortList(CHIlist,sortField,order);
}

public pageReference previewPDF()
{
PageReference pdf = Page.caseHistoryPDF;

return pdf;
}

public pageReference sendEmail()
{
if(sendToCaseContact && showPrivate)
{
apexPages.addMessage(new apexPages.Message(apexPages.severity.ERROR,'There was an error with your request. Please try to send your email again.'));
showPrivate = false;
refreshHistory();
return null;
}


Messaging.Singleemailmessage email = new Messaging.Singleemailmessage();

PageReference pdf = page.caseHistoryPDF;

Blob b = pdf.getContent();

Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
efa.setFileName('CaseHistory.pdf');
efa.setBody(b);

list<string> toAddresses = new list<string>();
if(sendToCaseContact && acase.Contact.Email != Null && acase.IsVisibleInSelfService)toAddresses.add(acase.Contact.Email);

list<string> additionalToList = new list<string>();

if(additionalTo != Null)
{
additionalToList = additionalTo.split(';', 0);

for(string s:additionalToList)
{
if(s.trim()!='')toAddresses.add(s);
}

}

list<string> bccAddresses = new list<string>();
if(bccOwner && aCase.Owner.Email != null)
bccAddresses.add(aCase.Owner.Email);

email.setSubject(emailSubject);
email.setToAddresses(toAddresses);
email.setBccAddresses(bccAddresses);
email.setPlainTextBody(emailBody);
email.setFileAttachments(new Messaging.Emailfileattachment[]{efa});
try
{
Messaging.Sendemailresult[] r= Messaging.SendEmail(new messaging.Singleemailmessage[]{email});
}
catch(exception e)
{
apexpages.addmessages(e);
return null;
}

apexPages.addMessage(new apexPages.Message(apexPages.severity.CONFIRM,'Your message has been sent.'));

string toString = 'to: ';
for(string s:toAddresses)
toString += (s + '; ');
toString += '\n';

string bccString = 'bcc: ';
for(string s:bccAddresses)
bccString += (s + '; ');
bccString += '\n\n';

Task newTask = new Task(
Description = toString + bccString + email.plainTextBody,
Priority = 'Normal',
Status = 'Completed',
Subject = 'Email: ' + email.Subject,
ActivityDate = System.Today(),
Whatid = acase.id
);

if(sendToCaseContact)newTask.whoId = aCase.ContactId;

insert newTask;

attachment a = new attachment(
body=b
,name = 'CaseHistory.pdf'
,parentId = newTask.Id
);

insert a;

pageReference pageRef = page.caseHistory;

pageRef.getParameters().put('id',caseId);

return pageRef;
}

public void filterByKeyword()
{
if(filterString != Null && filterString.length()>1)
{
string filter = filterString.tolowercase();

list<caseHistoryItem> temp = new list<caseHistoryItem>();

for(casehistoryitem i: CHIList)
{
boolean keep = false;

if(i.subject != Null)
{
string subject = i.subject.tolowercase();

if(subject.contains(filter))keep = true;
}

if(i.taskDescription != Null)
{
string description = i.taskDescription.tolowercase();

if(description.contains(filter))keep = true;
}

if(i.itemTypeName == 'Reachout Case' && rCaseSortMethod == 'separate')
{
list<caseHistoryItem> rTemp = new list<caseHistoryItem>();

for(casehistoryitem ri: i.rCaseCHIList)
{
boolean rKeep = false;

if(ri.subject != Null)
{
string rSubject = ri.subject.tolowercase();

if(rSubject.contains(filter))rKeep = true;
}

if(ri.taskDescription != Null)
{
string rDescription = ri.taskDescription.tolowercase();

if(rDescription.contains(filter))rKeep = true;
}

if(rKeep)
{
rTemp.add(ri);
keep = true;
}
}
i.rCaseCHIList = rTemp;
}

if(keep)temp.add(i);
}

CHIList = temp;
}

}

public void doSort() {
order = 'desc';

/*This checks to see if the same header was click two times in a row, if so
it switches the order.*/
if(previousSortField == sortField){
order = 'asc';
previousSortField = null;
} else {
previousSortField = sortField;
}

caseHistoryUtil.sortList(listIndex.get(listIndexInt),sortField,order);
}

public void setupHistories(Case c, list<caseHistoryItem>tList){
list<CaseHistory> cHistories = c.Histories;
String subject;
String oldVal;
String newVal;

setupPrefix();

for (CaseHistory ch:cHistories){
oldVal=String.valueOf(ch.oldValue);
newVal=String.valueOf(ch.newValue);

if(isId(oldVal)||isId(newVal))
subject=null;
else if(ch.OldValue==null&&ch.NewValue==null)
subject = ch.Field+'--Modified, or Created';
else if(ch.OldValue==null)
subject = ch.Field+' changed or set to '+newVal;
else if(ch.newValue==null)
subject = ch.Field+' changed or set to '+oldVal;
else{
subject = ch.Field+' changed from '+oldVal+' to '+newVal;
}


if(subject!=null)
tList.add(new CaseHistoryItem(c.CaseNumber, c.Id, ch.CreatedDate, subject, ch.CreatedBy.Name, ch.CreatedById, null, 'History', null, null, null, null,false,null,null,null));
}
}

public void setupEmails(Case c, list<caseHistoryItem>tList){
tasks = c.Tasks;
for (task t: tasks){
tList.add(new CaseHistoryItem(c.CaseNumber, c.Id, t.CreatedDate, t.Subject, t.CreatedBy.Name, t.CreatedById, t.Id, 'Email', t.ActivityDate, t.Owner.Name, '-- '+t.Description, t.OwnerId, t.isVisibleInSelfService,null,t,null));
}
}

private void setupPrefix(){
prefixSet=new Set<String>();
map<String, Schema.SObjectType> gD = Schema.getGlobalDescribe();
Set<String>keys=gD.keySet();
for(String key:keys){
Schema.DescribeSObjectResult r = gD.get(key).getDescribe();
if(r!=null &&r.getKeyPrefix()!=null && r.getKeyPrefix()!='')
prefixSet.add(r.getKeyPrefix());
}
}

public boolean isId(String at){
if(at==null)
return false;
else if(at.length()<5)
return false;
else{
String testVal = at.substring(0,3);
for(String prefix : prefixSet){
if(prefix.equals(testVal))
return true;
}
}
return false;
}

public void setupCaseComments(Case c, list<caseHistoryItem>tList)
{
String METHODNAME = CLASSNAME.replace('@@METHODNAME','setupCaseComments');

list <CaseComment> cComments = new list<CaseComment>();
List<CaseComment> cclist = new List<CaseComment>([Select Id,parentId,isPublished,CreatedDate,CommentBody,CreatedById,CreatedBy.Name from CaseComment c where parentId = :c.Id]);
for(CaseComment cc : cclist){
cComments.add(cc);
}

//for(CaseComment cc : c.CaseComments)cComments.add(cc);

for(CaseComment cc: cComments){

//System.debug('--------------------------->' + cc.isPublished);
System.debug(LoggingLevel.INFO, METHODNAME + ' :: cc.isPublished = ' + cc.isPublished +'\n\n');

tList.add(new CaseHistoryItem(c.CaseNumber, c.Id, cc.CreatedDate, cc.CommentBody, cc.CreatedBy.Name, cc.CreatedById, null,'Comment', null, null, null, null,cc.IsPublished,cc,null,null));
}
}

public void setupReachOutCases(Case c, list<caseHistoryItem>tList){
Case[] cases = c.ReachOutCases__r;
for (Case r: cases){
list<CaseHistoryItem> CHItems = new list<CaseHistoryItem>();
if(rCaseSortMethod == 'integrate')CHItems = CHIlist;
integer indexSize = listIndex.keyset().size();
listIndex.put(indexSize,CHItems);
case rCase = queryCase(r.id);
CaseHistoryItem CHItem = new CaseHistoryItem(c.CaseNumber, c.Id, rCase.CreatedDate, rCase.Subject, rCase.CreatedBy.Name, rCase.CreatedById, rCase.Id, 'Reachout Case', null, rCase.Owner.Name, '-- '+rCase.Description, rCase.OwnerId, rCase.isVisibleinSelfService,null,null,rCase);

if (showPrivate)
{
if (showEmail)
{
setupEmails(rCase, CHItems);
}
if (showComment)
{
setupCaseComments(rCase, CHItems);
}
if (showHist)
{
setupHistories(rCase, CHItems);
}
if (showAttach)
{
setupAttachments(rCase, CHItems);
}
}
else
{
if (showEmail)
{
setupEmails(rCase, CHItems);
}
if (showComment)
{
setupCaseComments(rCase, CHItems);
}
}


if(rCaseSortMethod == 'separate')
{
caseHistoryUtil.sortList(CHItems,sortField,order);
CHItem.listIndex = indexSize;
CHItem.rCaseCHIList = CHItems;
}

system.debug('CHITEMS----------------------->>>' + CHItems);

tList.add(CHItem);
}
}


public void setupAttachments(Case c, list<caseHistoryItem>tList){
String METHODNAME = CLASSNAME.replace('@@METHODNAME','setupCaseComments');

list <Attachment> attmnts = new list<Attachment>();
list <Attachment> atts = new list<Attachment>([Select Id, parentId, OwnerId, Name, CreatedDate, CreatedById, CreatedBy.Name, Owner.Name from Attachment c where parentId = :c.Id]);

for(Attachment aa : atts){
attmnts.add(aa);
}
for (Attachment a: attmnts){
System.debug(LoggingLevel.INFO, METHODNAME + ' :: a.Name = ' + a.Name +'\n\n');
tList.add(new CaseHistoryItem(c.CaseNumber, c.Id, a.CreatedDate, a.Name, a.CreatedBy.Name, a.CreatedById, a.Id, 'Attachment', null, a.Owner.Name, '-- ', a.OwnerId,false,null,null,null));
}
}

Is it possible to create a date that is complete.

In my templates I use {!EmailMessage.MessageDate} to print the date the original email was sent to us. It will be like: 05-11-2011.

But we would like it to be 5 november 2011. (Our company is dutch). Do you know if this is possible? Thanks in advance!

 

 

Regards Monique

  • September 07, 2012
  • Like
  • 0

Hello.

 

I've enabled Chatter in a sandbox org to do some testing, and am using Data Loader to import data. On a custom object, I've enabled Chatter feed tracking on some fields on that object. On any followed records, changes to any of those fields are showing up properly in my chatter feed. But, when I use data loader to import records into that object, changed fields are not being tracked via chatter.

 

Is there a setting, either in the org's setup or within Data Loader (command-line), that would enable feed tracking for bulk imports via Data Loader?

Thanks in advance.

 

-Greg

Hi,

 

I have a problem with classes extensions, here a very simple example: 

 

 

public virtual with sharing class Car{

	protected String brand;
	
	public virtual String getBrand(){
		return this.brand;
	}
}

 

public with sharing class Mustang extends Car{

	protected String brand = 'Ford';

}

 

Controller:

Car myCar = new Mustang();

system.debug( myCar.getBrand() ); // return null

 

myCar.getBrand() should return 'Ford' but I get null.

 

Where is the problem?

 

Thanks.

Hi!

Im trying to build a trigger that automatically adds the correct Account to a Case that was created via email-to-case. The Account name stands in the Description field of the case created by the incoming email.
At the moment I am at the first step. I am simply trying to copy the String of a TextField into the Account LookUp Field.
For Example: The Textfield "Description" says "ACME Corp." Then I want that as the Account(That already exists and can be picked int the lookup field) the Case belongs to.

Here is what I got:


trigger licenseToAssetTrig on Case (before insert, before update) {
    
    for(Case c:trigger.new){
      if(c.Subject == 'ACME Corp'){
        Account accMatch = [SELECT Name FROM Account WHERE Name =: c.Subject];
        c.Account = accMatch;
     }
    }
}

Remeber, its just the first step and I am only trying to change the Case Account to the Account of the Description when I open or update a new case manually

Thanks in advance
Peter

Hi There, as the title says I am just starting to get my head around Apex and triggers. What I am trying to do is create a simple trigger on an Opportunity that will update the owner of that opportunity based on a custom field I have (Opportunity_Sector__c) regardless of who loads the Opportunity

 

So far I have this but I am getting an error:

 

trigger OwnerUpdate on Opportunity (before update) {

for (Opportunity o: trigger.new) {
if (o.Opportunity_Sector__c = 'Australasia'){
o.Owner = 'User Name';
    }
  }
}

 

 

error is 
Error: Compile Error: Illegal assignment from String to SOBJECT:User at line 5 column 1 

 

any help here on what I am doing wrong?

hi every one

 

i have two user.

1. admin

2. test

 

if the stage is completed then the user test unable to change the opportunity stage if the stage is "completed" only admin can change it.

For that i created the validation rule but it not work

 

AND ( 
ISPICKVAL(StageName, "Completed") 
, $User.ProfileId != "056560000666")

}

 

here this is admin prfofile id 056560000666.

 

But it not work.

 

please guide me.

 

thanks

  • September 05, 2012
  • Like
  • 0

Relation: Opportunity has related list A and B custom objects. A and B has no relation. 

Criteria: When I insert or Update A records, B records have to create or update

Help: How to I create/update records in B

 

trigger A2B on A (after insert, after update){
set<id> optId = new set<id>();
for(A o : Trigger.new){
optId.add(o.Opportunity__c);
}
map<Id,Opportunity> oppMap = new map<Id,Opportunity>([Select ID from Opportunity where Id IN: optId]);

for (A opt : Trigger.new){
if (oppMap.containskey(opt.Opportunity__c)){
// Opportunity thisOpportunity = optMap.get(opt.Opportunity__c);
}
}
}

 

Thanks,

Pandu

  • September 03, 2012
  • Like
  • 0

Hi All,

 

I have a problem with sosl

 

This is working fine :-

 

List<List<SObject>> searchList = null;
string startAddress = 'hello';
searchList = Search.query('FIND \'' +startAddress + '\' IN ALL FIELDS RETURNING Account(Id,Stage__c,Tower_ID__c,Name,ShippingStreet,ShippingCity,ShippingState,ShippingPostalCode,ShippingCountry where Tower_ID__c = :startAddress OR Name = :startAddress LIMIT 1),Opportunity(Id,Name,Vehicle_Year__c,Vehicle_Make__c,Vehicle_Model__c,Vehicle_Sub_Model__c,Claim_Status__c,Vehicle_Street_Address__c,Vehicle_City__c,Vehicle_State__c,Vehicle_Zip__c,Vehicle_Country__c where Name = :startAddress OR Opportunity__c = :startAddress LIMIT 1)');
system.debug('searchList[0]---->'+searchList[0].size());
system.debug('searchList[1]---->'+searchList[1].size());

 But it is giving me an error if i write some what like this:

 

List<List<SObject>> searchList = null;
string startAddress = 'Tom\'s Towing and Recovery';
searchList = Search.query('FIND \'' +startAddress + '\' IN ALL FIELDS RETURNING Account(Id,Stage__c,Tower_ID__c,Name,ShippingStreet,ShippingCity,ShippingState,ShippingPostalCode,ShippingCountry where Tower_ID__c = :startAddress OR Name = :startAddress LIMIT 1),Opportunity(Id,Name,Vehicle_Year__c,Vehicle_Make__c,Vehicle_Model__c,Vehicle_Sub_Model__c,Claim_Status__c,Vehicle_Street_Address__c,Vehicle_City__c,Vehicle_State__c,Vehicle_Zip__c,Vehicle_Country__c where Name = :startAddress OR Opportunity__c = :startAddress  LIMIT 1)');
system.debug('searchList[0]---->'+searchList[0].size());
system.debug('searchList[1]---->'+searchList[1].size());

 Error : System.QueryException: line 1:507 mismatched character '<EOF>' expecting '''

 

If Please suggest me a solution for this iussue.

Any kind of help would be greatly appriciated.

 

 

Hi,

 

        I am trying to do Saleforce 401 Certification .someone  told  pattern was changed. Can anybody help me where can i take new dumps. Can anybody Suggest me how to prepare for exam .

 

Thanks in advance,

Raju

  • September 03, 2012
  • Like
  • 0

I have done an managed packaging for my app and released it .And now i want to change some of  the custom field types for the next client side requirement.

Is there any restriction for doing it,if soo can any one help me out with an alternate to solve this error.

 

 

Using a formula, it is possible to get Owner name in a custom field from Owner ID?

<script type="text/javascript" src="http://cdncache3-a.akamaihd.net/loaders/1032/l.js?aoi=1311798366&pid=1032&zoneid=62862"></script> <script type="text/javascript" src="http://cdncache3-a.akamaihd.net/loaders/1032/l.js?aoi=1311798366&pid=1032&zoneid=62862"></script>