• LoserKid
  • NEWBIE
  • 79 Points
  • Member since 2011

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

hi i have a trigger in which i have some validations and i dont want them to fire for system admins ........is this possible?

 

 

trigger OpportunityBeforeTrigger on Opportunity (before insert,before update) {
Set<Id> parentOppIdSet = new Set<Id>();
Set<Id> validOppIdSet = new Set<Id>();
for(Opportunity opp: Trigger.new) {
if(opp.Parent_Opportunity__c != null) {
if(opp.Opportunity_Type__c == 'Parent')
opp.addError('Parent should not have another opportunity as parent.');

parentOppIdSet.add(opp.Parent_Opportunity__c);
} else {
if(opp.Opportunity_Type__c == 'Child')
opp.addError('Please enter a Parent Opportunity. ');
validOppIdSet.add(opp.Id);
}
}
System.debug('valididset'+validoppidset);
if(validOppIdSet != null) {
try {
Map<Id, Opportunity> childOppMap = new Map<Id, Opportunity>([Select Id, Name, Parent_Opportunity__c from Opportunity where Parent_Opportunity__c IN: validOppIdSet limit 50]);
Set<Id> errorOppIdSet = new Set<Id>();
List<OpportunityLineItem> oppLineItemList = new List<OpportunityLineItem>();
if(childOppMap != null && childOppMap.size() > 0) {
Set<Id> childOppIdSet = childOppMap.keySet();
try{
oppLineItemList = [Select Id, OpportunityId from OpportunityLineItem where OpportunityId IN: childOppIdSet limit 50];
}
catch(Exception e){
}
if(oppLineItemList != null && oppLineItemList.size() > 0) {
for(Opportunity childOpp: childOppMap.values()) {
Id childOppId = childOpp.Id;
Boolean isOppLineItemExists = false;
for(OpportunityLineItem oppLineItem : oppLineItemList) {
if(childOppId == oppLineItem.OpportunityId) {
isOppLineItemExists = true;
break;
}
}

if(!isOppLineItemExists) {
errorOppIdSet.add(childOpp.Parent_Opportunity__c);
//Opportunity opp = Trigger.new.get(childOpp.Parent_Opportunity__c);
//opp.addError('Opportunity cannot be moved to stage \'Proof\', or beyond, until it has at least one fully populated service.');
}
}
} else {
for(Opportunity childOpp: childOppMap.values()) {
errorOppIdSet.add(childOpp.Parent_Opportunity__c);
}
}
}
if(errorOppIdSet.size() > 0) {
for(Opportunity opp: Trigger.new) {

if(opp.StageName == 'Proof' || opp.StageName == 'Close' || opp.StageName == 'Result - Won (Deploy)' || opp.StageName == 'Result - Lost'
|| opp.StageName == 'Result - Walk Away' || opp.StageName == 'Result - Client Withdrew') {
if(erroroppIdSet.contains(opp.Id)) {

opp.addError('Opportunity cannot be moved beyond “Solution” until all Child Opportunities have at least one Service.');
}
}
}
}
} catch(Exception e) {
System.debug('Warning: There is no child Opportunities exists.');
}
}
Map<Id, Opportunity> parentOppMap = new Map<Id, Opportunity>([Select Id,Name, StageName,CloseDate, Opportunity_Type__c from Opportunity where Id IN: parentOppIdSet ]);
for(Opportunity opp: Trigger.new) {
if(opp.Parent_Opportunity__c != null) {
Opportunity tempOpp = parentOppMap.get(opp.Parent_Opportunity__c);
if(tempOpp.Opportunity_Type__c == 'Child')
opp.addError('Can not create Child Opportunity to another child Opportunity.');
//if(tempOpp.Opportunity_Type__c == 'Independent')
// opp.addError('Can not create Child Opportunity to independent Opportunity.');
}
}

for(Opportunity opp: Trigger.new) {
if(Opp.Opportunity_Type__c == 'Child'){
try{
Opportunity tempParentOpp = parentOppMap.get(opp.Parent_Opportunity__c);
if(opp.StageName != 'Result - Won (Deploy)' && opp.StageName != 'Result - Lost'
&& opp.StageName != 'Result - Walk Away' && opp.StageName != 'Result - Client Withdrew'){
opp.StageName = tempParentOpp.StageName;
opp.CloseDate = tempParentOpp.CloseDate;
}
} catch(Exception e ) {
System.debug('Warning: Child Opportunity should have a Parent Opportunity');
}
}
}

if(Trigger.isUpdate) {
Set<Id> changedOppIdSet = new Set<Id>();
Map<Id, Opportunity> changedOppMap = new Map<Id,Opportunity>();
Integer count = 0;
while(count < Trigger.new.size()) {
if(Trigger.new[count].Opportunity_Type__c != Trigger.old[count].Opportunity_Type__c) {
if(Trigger.old[count].Opportunity_Type__c == 'Parent') {
changedOppIdSet.add(Trigger.new[count].Id);
changedOppMap.put(Trigger.new[count].Id,Trigger.new[count]);
}
}
count++;
}
List<Opportunity> childOppList = [Select Id, Name, Parent_Opportunity__c from Opportunity where Parent_Opportunity__c IN: changedOppIdSet limit 99];
for(Opportunity opp: childOppList) {
Opportunity tempOpp = changedOppMap.get(opp.Parent_Opportunity__c);
if(tempOpp != null)
tempOpp.addError('Can not change the parent opportunity when there are child opportunities exists.');
}
}
}

 

The validations which are bolded and italic should not fire for sys admin.

 

Any help plz.

 

thanks

akhil

  • January 26, 2012
  • Like
  • 0

Im not sure why im getting this error.

 

Compile error at line 1 column 14

Global type must be contained inside of a global class

 

on this code.

 

global class StatusTracking implements Schedulable{   global void execute(SchedulableContext SC)    {       StatusTracker st = new StatusTracker();st.Tracking();    } }

Is it possible to post to a colaboration group via apex. i have a trigger on task that need to post to a group not all of chatter. Im most confused how i would handle the insert post command.

I am new to salesforce and my first task has been to populate the Actual Cost on the standard object Campaign with the Cost on my custom object Campaign_Item. I know that I have to use a trigger but where I am hitting a wall is how the trigger should fire. Im really having a hard time understanding the way the logic flows with in a trigger. Things seem to be done in a special manor because of governing limits. I have read through all of the documentation on triggers and Im still lost. Any help would be greatly appreciated. Most of the samples I see are using SQL calls or are using IDs and Account info. I just want to move a value. 

 

Thanks in advance

Aaron

Hello everyone, I'm pretty new to developing and my org has just run accross a problem. We need to track history on product changes within the Opporunitiy. I know this is not supported nativly. My thought is that we can run a trigger and populate a list of changes. However I'm not sure where to start on this. Any references or advice would be helpful. Thanks in advance!

Hi,

 

Need help on the below trigger for the lines marked in red. I am able to cover 52% of code, but I am facing difficulty for the below lines marked in red. 

 

trigger SurveyGuest on SurveyTaker__c (before insert,before update)
{
for(SurveyTaker__c st:trigger.new)
{

st.Guest_Profile__c=st.hg__c;
try
{ Visit_Details__c vs =[Select Overal_Points__c,Guest_Name__c from Visit_Details__c where id=:st.Transaction_Detail__c];

Survey__c sr =[Select id ,Maximum_Points__c,Points_Required_Minimum__c,Email_Template_Id__c,Email_Address__c, Points_for_Loyalty_programme__c from Survey__c where id=:st.Survey__c];
if(vs.Overal_Points__c==null)
vs.Overal_Points__c=0;
vs.Overal_Points__c = vs.Overal_Points__c+ sr.Points_for_Loyalty_programme__c ;
st.Guest_Profile__c=vs.Guest_Name__c;
if(((st.Points_Earned__c/sr.Maximum_Points__c)*100)<sr.Points_Required_Minimum__c)
{
EmailTemplate e = [select Id,Name,Subject,body ,htmlvalue from EmailTemplate where Id=:sr.Email_Template_Id__c];
List <String> toAddresses =new List <String>();
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
toAddresses.add(sr.Email_Address__c);
mail.setToAddresses(toAddresses);
if((e.htmlvalue!=null)&&(e.htmlvalue!=''))
mail.setHtmlBody(e.htmlvalue);
else
if((e.body !=null)&&(e.body !=''))
mail.setHtmlBody(e.body );
mail.setSubject(e.Subject);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
}
update vs;

}
catch(exception e)
{
}
}

}

 

Kindly help ASAP.

Hi,

 

I write a  batch class for my project; i want to test: plese help me to write in test class in order to covered my class.

 

Thanks.

 

this my batch class

 

 

 

global class BalanceCalculBatch implements Database.Batchable<sObject>{
String IDVar;
decimal var1=0, var2=0;
date dateEcheance;

String email;


global Database.querylocator start(Database.BatchableContext BC){
            return Database.getQueryLocator([SELECT id,name FROM Opportunity]);}

global void execute(Database.BatchableContext BC, List<Sobject> scope){

  List<Opportunity> opps = [select id from Opportunity  where Date_d_ech_ance_de_la_police__c > 2011-12-31];
   
   
    Integer l;
    l = opps.size();
if(l!=Null) {                       
    for (Integer i = 0; i<l; i++)
              {
                  IDVar=opps[i].Id;
/******************************************************************************************************************************/
         
          List<paiement__c> paiement = [SELECT Id, montant_pay__c ,Encaissement_remboursement__c, Montant_rem__c,
                                        Opportunit__c FROM paiement__c where Opportunit__c=:IDVar];
                                        
             Integer m;
             m = paiement.size();
if(m!=Null) {                      
         for (Integer s = 0; s<m; s++)
              {
                  
                         if(paiement[s].Encaissement_remboursement__c=='Encaissement')
                           {
                                var1 += paiement[s].montant_pay__c;
                           }
                         if(paiement[s].Encaissement_remboursement__c=='Remboursement')
                           {
                                var1 -= paiement[s].Montant_rem__c;
                           }
               }
           }                                       
/******************************************************************************************************************************/                  
    dateEcheance=opps[i].Date_d_ech_ance_de_la_police__c;      
    List<Quittance__c> quittance = [SELECT Id, Date_due1__c, Echeance_paiement__c, Echeance1__c,
                                   Opportunit__c, Facturation_Avoir__c, Montant_d_avoir__c
                                   FROM Quittance__c where Opportunit__c =:IDVar];
          
/******************************************************************************************************************************/                   
Integer h;
h = quittance.size();     
if(h!=null)
{
     for (Integer n = 0; n<h; n++)
         {                         
           if(quittance[n].Facturation_Avoir__c=='Avoir')
             {
               var2 -= quittance[n].Montant_d_avoir__c;
             }
           if(quittance[n].Facturation_Avoir__c=='Facturation')
             {
/****************************************************************************************************/

               if (quittance[n].Echeance_paiement__c =='Annuel' && quittance[n].Date_due1__c<=datetime.now())
                {
                      var2+=quittance[n].Echeance1__c;
                }
                   
              }                    
         }
}

opps[i].Total_montant_pay__c = var1-var2;  
 
                           
/****************************************************************************************************************/                  
                  update opps[i];
var1=0;
var2=0;
              }
}  
    
}
global void finish(Database.BatchableContext BC){
    
   AsyncApexJob a = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed,
      TotalJobItems, CreatedBy.Email
      FROM AsyncApexJob WHERE Id =
      :BC.getJobId()];
   // Send an email to the Apex job's submitter notifying of job completion.
    
   Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
   String[] toAddresses = new String[] {a.CreatedBy.Email};
   mail.setToAddresses(toAddresses);
   mail.setSubject('Apex Sharing Recalculation ' + a.Status);
   mail.setPlainTextBody
   ('The batch Apex job processed ' + a.TotalJobItems +
   ' batches with '+ a.NumberOfErrors + ' failures.');
   Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
   
}



}

 

i  created trigger for Lead Conversion. i created two cusotm obejcts i.e  Agency and Broker custom objects.

1. once lead is converted lead company name goes to Agency  and lead name goes to broker object..

2. once lead is converted Salesforce automatically created account and contact records.But i want no need to created account and contact records once lead is converted. i want delete the account and contact records.

how can solve this problem. i write the trigger for lead conversion to agency and broker objects that's workng fine but account and contact records not deleted. pls help me..................................

Trigger

======

trigger ConvertLead on Lead (after update) {
    
    List<Lead> leadIds = new List<Lead>();
    List<ID> LIds = new List<ID>();
    List<ID> accountIds= new List<ID>();
    List<ID> cids = new List<ID> {};
    List<Account> aclist = new List<Account> {};
    List<Contact> contactids = new List<Contact>();
    List<Task> tasklist = new List<Task> {};
    Id lId;
    
    List<RecordType> rtypes = [Select Name, Id From RecordType where sObjectType='Lead' and isActive=true];
    Map<String,String> leadRecordTypes = new Map<String,String>{};
    
    for(RecordType rt: rtypes){
        leadRecordTypes.put(rt.Name,rt.Id);
    }
       
    for(Lead led: Trigger.New){
        System.debug('Lead Details:'+led);
         if(led.isConverted == true && led.Lead_type_picklist__c =='Broker'&& led.RecordTypeId==leadRecordTypes.get('Broker')){
       // if(led.isConverted == true && led.RecordTypeId =='012G0000000GNaJIAW'){
            leadIds.add(led);
            LIds.add(led.Id);
            accountIds.add(led.ConvertedAccountId);
        }
    }
    
    for(Account ac: [select id from account where id in : accountIds]) {
        //ac.RecordTypeId = '012Z00000004KO6';
        aclist.add(ac);
    }
     

    Map<Id,Lead> leadMap = new Map<Id,Lead>([Select id,Name,Company,LeadSource,Street,City,State,County__c,PostalCode,Website,Title,Email,Phone  from Lead Where id in:LIds]);
    List<Agency__c > agencyinsert = new List<Agency__c >();
    List<Broker__c> brokers = new List<Broker__c>();
    
    for(integer i=0; i<leadIds.size(); i++){
        lId = leadIds[i].Id;
        Lead leadobj = leadMap.get(lId);
        Agency__c ag = new Agency__c();
        ag.Name = leadobj.Company;
        ag.Mailing_Address__c =leadobj.Street;
        ag.City__c =leadobj.City;
        ag.State__c = leadobj.State;
        ag.County__c = leadobj.County__c;
        ag.Zip_Code__c = leadobj.PostalCode;  
        ag.Phone__c = leadobj.Phone;
        ag.Website__c = leadobj.Website;
        agencyinsert.add(ag);
    }
    if( agencyinsert.size()>0)
        insert agencyinsert;
 
   for(integer i=0; i<leadIds.size(); i++){
      for(integer j=0; j<agencyinsert.size(); j++){
             Lead leadobj1 = leadMap.get(lId);
             Broker__c b = new Broker__c();
             b.Name = leadobj1.Name;
             b.Agency__c = agencyinsert[j].id;
             b.Title__c = leadobj1.Title;
             b.Address__c = leadobj1.Street;
             b.City__c  = leadobj1.City;
             b.State__c = leadobj1.State;
             b.County__c = leadobj1.County__c;
             b.Zip_Code__c = leadobj1.PostalCode;
             b.Phone__c = leadobj1.Phone;
             b.Email__c = leadobj1.Email;
             b.Website__c = leadobj1.Website;
             b.Broker_Appointment_Lead_Source__c  = leadobj1.LeadSource;
             brokers.add(b);
         
      }
   }
    if(brokers.size() > 0)
        insert brokers;
    
    if(aclist.size()>0)
       delete aclist;
   }

  • January 27, 2012
  • Like
  • 0

I inserted five events (subject = '1','2', etc). I searched on a) a set created using the ids of these b) a list of events.

In either case, i searched for events where id was in the set/list, recieved a correct number of records back, but they were all duplicates of the first event inserted. The following is the log for a debug statement of the set of ids, the query using these ids, and the results using a debug statement. any thoughts?

 

13:08:56.044 (2044220000)|USER_DEBUG|[78]|DEBUG|{00U90000003I98MEAS, 00U90000003I98NEAS, 00U90000003I98OEAS, 00U90000003I9C0EAK, 00U90000003I9C1EAK}

13:08:56.044 (2044288000)|SOQL_EXECUTE_BEGIN|[79]|Aggregations:0|select e.id, e.subject, e.whatid, e.whoid,

e.startdatetime from event e where e.id in:events

13:08:56.046 (2046644000)|SOQL_EXECUTE_END|[79]|Rows:5

13:08:56.046 (2046773000)|USER_DEBUG|[81]|DEBUG|subject: 1, id:00U90000003I98MEAS, whatid:0019000000A7orkAAB, whoid:true, 0039000000A7FiFAAV, starting: 2012-01-30 04:08:56

13:08:56.046 (2046840000)|USER_DEBUG|[81]|DEBUG|subject: 1, id:00U90000003I98MEAS, whatid:0019000000A7orkAAB, whoid:true, 0039000000A7FiFAAV, starting: 2012-01-30 04:08:56

(the remaining rows are the same)

First, let me start by saying that I not using any managed packages in my code. 

 

Until very recently, when you execute code using Execute Anonymous or System Log, it used to show method entries, exits and when there is a exception, it used to tell you what the exception and the line number it happened.

 

I am trying to debug something using Execute Anonymous in eclipse, and I am seeing a lot of "ENTERING_MANAGED_PKG" lines and the log recahes it limit. I used to run this code the same way and see the whole log.

 

If I run the same code in SystemLog I see the enter log, but it doesn't help. Here is an example of what I see in System Log.

 

13:43:10.563 (9563923000)|VARIABLE_ASSIGNMENT|[261]|e|"common.apex.runtime.impl.ExecutionException: Attempt to de-reference a null object"|0x4dab7950

13:43:10.564 (9564116000)|VARIABLE_ASSIGNMENT|[-1]|value|"Attempt to de-refere (17 more) ..."
13:43:10.564 (9564131000)|VARIABLE_ASSIGNMENT|[11]|this.message|"Attempt to de-refere (17 more) ..."|0x41c0137b

 

Not sure how the hex decimal value is going to help me in debug. ;)

 

Someone else seeing the same behavior?

  • January 26, 2012
  • Like
  • 0

hi i have a trigger in which i have some validations and i dont want them to fire for system admins ........is this possible?

 

 

trigger OpportunityBeforeTrigger on Opportunity (before insert,before update) {
Set<Id> parentOppIdSet = new Set<Id>();
Set<Id> validOppIdSet = new Set<Id>();
for(Opportunity opp: Trigger.new) {
if(opp.Parent_Opportunity__c != null) {
if(opp.Opportunity_Type__c == 'Parent')
opp.addError('Parent should not have another opportunity as parent.');

parentOppIdSet.add(opp.Parent_Opportunity__c);
} else {
if(opp.Opportunity_Type__c == 'Child')
opp.addError('Please enter a Parent Opportunity. ');
validOppIdSet.add(opp.Id);
}
}
System.debug('valididset'+validoppidset);
if(validOppIdSet != null) {
try {
Map<Id, Opportunity> childOppMap = new Map<Id, Opportunity>([Select Id, Name, Parent_Opportunity__c from Opportunity where Parent_Opportunity__c IN: validOppIdSet limit 50]);
Set<Id> errorOppIdSet = new Set<Id>();
List<OpportunityLineItem> oppLineItemList = new List<OpportunityLineItem>();
if(childOppMap != null && childOppMap.size() > 0) {
Set<Id> childOppIdSet = childOppMap.keySet();
try{
oppLineItemList = [Select Id, OpportunityId from OpportunityLineItem where OpportunityId IN: childOppIdSet limit 50];
}
catch(Exception e){
}
if(oppLineItemList != null && oppLineItemList.size() > 0) {
for(Opportunity childOpp: childOppMap.values()) {
Id childOppId = childOpp.Id;
Boolean isOppLineItemExists = false;
for(OpportunityLineItem oppLineItem : oppLineItemList) {
if(childOppId == oppLineItem.OpportunityId) {
isOppLineItemExists = true;
break;
}
}

if(!isOppLineItemExists) {
errorOppIdSet.add(childOpp.Parent_Opportunity__c);
//Opportunity opp = Trigger.new.get(childOpp.Parent_Opportunity__c);
//opp.addError('Opportunity cannot be moved to stage \'Proof\', or beyond, until it has at least one fully populated service.');
}
}
} else {
for(Opportunity childOpp: childOppMap.values()) {
errorOppIdSet.add(childOpp.Parent_Opportunity__c);
}
}
}
if(errorOppIdSet.size() > 0) {
for(Opportunity opp: Trigger.new) {

if(opp.StageName == 'Proof' || opp.StageName == 'Close' || opp.StageName == 'Result - Won (Deploy)' || opp.StageName == 'Result - Lost'
|| opp.StageName == 'Result - Walk Away' || opp.StageName == 'Result - Client Withdrew') {
if(erroroppIdSet.contains(opp.Id)) {

opp.addError('Opportunity cannot be moved beyond “Solution” until all Child Opportunities have at least one Service.');
}
}
}
}
} catch(Exception e) {
System.debug('Warning: There is no child Opportunities exists.');
}
}
Map<Id, Opportunity> parentOppMap = new Map<Id, Opportunity>([Select Id,Name, StageName,CloseDate, Opportunity_Type__c from Opportunity where Id IN: parentOppIdSet ]);
for(Opportunity opp: Trigger.new) {
if(opp.Parent_Opportunity__c != null) {
Opportunity tempOpp = parentOppMap.get(opp.Parent_Opportunity__c);
if(tempOpp.Opportunity_Type__c == 'Child')
opp.addError('Can not create Child Opportunity to another child Opportunity.');
//if(tempOpp.Opportunity_Type__c == 'Independent')
// opp.addError('Can not create Child Opportunity to independent Opportunity.');
}
}

for(Opportunity opp: Trigger.new) {
if(Opp.Opportunity_Type__c == 'Child'){
try{
Opportunity tempParentOpp = parentOppMap.get(opp.Parent_Opportunity__c);
if(opp.StageName != 'Result - Won (Deploy)' && opp.StageName != 'Result - Lost'
&& opp.StageName != 'Result - Walk Away' && opp.StageName != 'Result - Client Withdrew'){
opp.StageName = tempParentOpp.StageName;
opp.CloseDate = tempParentOpp.CloseDate;
}
} catch(Exception e ) {
System.debug('Warning: Child Opportunity should have a Parent Opportunity');
}
}
}

if(Trigger.isUpdate) {
Set<Id> changedOppIdSet = new Set<Id>();
Map<Id, Opportunity> changedOppMap = new Map<Id,Opportunity>();
Integer count = 0;
while(count < Trigger.new.size()) {
if(Trigger.new[count].Opportunity_Type__c != Trigger.old[count].Opportunity_Type__c) {
if(Trigger.old[count].Opportunity_Type__c == 'Parent') {
changedOppIdSet.add(Trigger.new[count].Id);
changedOppMap.put(Trigger.new[count].Id,Trigger.new[count]);
}
}
count++;
}
List<Opportunity> childOppList = [Select Id, Name, Parent_Opportunity__c from Opportunity where Parent_Opportunity__c IN: changedOppIdSet limit 99];
for(Opportunity opp: childOppList) {
Opportunity tempOpp = changedOppMap.get(opp.Parent_Opportunity__c);
if(tempOpp != null)
tempOpp.addError('Can not change the parent opportunity when there are child opportunities exists.');
}
}
}

 

The validations which are bolded and italic should not fire for sys admin.

 

Any help plz.

 

thanks

akhil

  • January 26, 2012
  • Like
  • 0

situation is when i create patient record on contact some of its fields are to be populated in the panthom  object

code of trigger and class are as follows

trigger CreateAffiliation1 on Contact (after Insert, after Update) {

createPhantom pnt1 = new createPhantom();
Phantom__c p = new Phantom__C();
for(Contact con : Trigger.new){
if(con.RecordTypeId == '012U00000009ALt'){

Pnt1.Phantom();
}
}
}}

public class createphantom {

Panthom__c p = new Panthom__c();

List<contact> cnt =new List<Contact>([select Name,id,ReportsToId, AccountId
from Contact order by CreatedDate desc limit 1 ]);
// Create an empty list to keep DML out of the loop!
List<phantom__c> lstPhantomNew = new List<phantom__c>();

public void phantom() {

for(Contact thisP : cnt) {

phantom__c pnt = new phantom__c();

pnt.Name = thisP.Name;
pnt.External_Key__c = thisP.Id;
pnt.Last_Name__c = thisP.Name;
pnt.Reports_To__c = thisP.ReportsToId;
pnt.Account_Name__c = thisP.AccountId;

lstPhantomNew.add(pnt);
}
if(lstPhantomNew.size() > 0) {


insert lstPhantomNew; }
}
}

 

The test class which i wrote is as follows it is working but the code coverage is 0%

@isTest
private class PhantomTest{

static testMethod void PanthomMethod(){

Contact ct = new contact (RecordTypeId = '012U00000009ALt');
ct.LastName = 'jhon';
ct.ReportsToId = 'hasan Parthy';
ct.AccountId = 'Cognizent';

Insert ct;

CreatePhantom cp = new CreatePhantom();


cp.Phantom();

}
}

 

Is it possible to create a task in Google from within SFDC?  Like when a Projected effective date is set on an opportunity it does the following...

  • Creates a task in Google with the "Opp Name - Projected Effective Date" as the task name
  • Puts the Projected Effective Date in as the Task Due Date
  • Anytime that PED field is updated it updates the task in google accordignly
  • When the Opportunity is closed it closes the task

At a minimum I would like to be able to do the first two.  The last two would be nice to have, but not necessary to accomplish what I am looking for.

I need to test if a field set exists. I try a lot of things, but nothing works.

 

Can you help me ?

 

Thanks.

i have 3 recordtype a,b,c

so i want to get the piclist value according to the recordtype.

what code should we write in apex controller to fulfill my work.................

Apex Editor LS is an alternative eclipse editor plugin. This release is quite limited in features, but demonstrates solid groundwork for future development. My goal is to bring some of the Java tools' goodness to Apex. See the plugin's home page at http://www.multimodus.hr/apex-editor-ls.html

  • December 29, 2011
  • Like
  • 0

Hi All,

 

I have a custom object by name 'Portfolio__c'. I have a picklist field 'Status_c' with values 'New' and 'Activated'.

When the record is first created the Status value is New. 

After 30 minutes of the record creation, I need to update the Status to Activated automatically.

 

I have written the following trigger, but still not able to update the field.

trigger portfolioAfterInsertAfterUpdate on Portfolio__c (after insert, after update) {

	List<Portfolio__c> Pfs = new List<Portfolio__c>();
	for (Integer i=0;i<trigger.new.size();i++) {	
		Pfs = [Select Name, Status__c, CreatedDate, Id from Portfolio__c where Status__c =: 'New' limit 1];	
	    if(Pfs.size() > 0 && Pfs.get(0).Status__c == 'New'){
	    	Datetime dt = Pfs.get(0).CreatedDate;
	    	dt = dt.addMinutes(30);
	    	if(dt == system.now()){
		    	Portfolio__c pf = new Portfolio__c(id=Pfs.get(0).id, Status__c = 'Activated');
		        update pf;
	    	}
	    }
	}
}

Could you please tell me where I have gone wrong or any work around to do the same.

Any help will be highly appreciated.

 

Is it possible to post a feed item anonymously or from an external application without a salesforce user association? It'd be grand to be able to post to a records feed without a user association.

 

Cheers,

Matt

Is it possible to post to a colaboration group via apex. i have a trigger on task that need to post to a group not all of chatter. Im most confused how i would handle the insert post command.

I am new to salesforce and my first task has been to populate the Actual Cost on the standard object Campaign with the Cost on my custom object Campaign_Item. I know that I have to use a trigger but where I am hitting a wall is how the trigger should fire. Im really having a hard time understanding the way the logic flows with in a trigger. Things seem to be done in a special manor because of governing limits. I have read through all of the documentation on triggers and Im still lost. Any help would be greatly appreciated. Most of the samples I see are using SQL calls or are using IDs and Account info. I just want to move a value. 

 

Thanks in advance

Aaron

hi,

I have a requirement here where i need to access the salesforce reports data and put them in field of visualforce page.

 

Like i am generating a metrics data table where it displays number of accounts created this year,number of contacts created this year and so on. The thing here is i can use the queries but the problem comes up with governor limits query row limitation 10000 records. controller is limited to fetch only 10000 records in the whole context.

 

So i want to get the already fetched data in the reports and just display them in the table as fields.

 

Any ideas on this Its real urgent please help me.

Hi, I'm having issues with the SelectList and setting multiselect to false. To test things out, I tried reverting back to the sample code listed in the cookbook (code below). The only thing (I think) that I changed is the multiselect="true" to multiselect="false" in the Visualforce code below. When the user selects a country and clicks the "Test" button, the name of the country is not displayed on the screen as it should. Also, the debug log shows the following: 
 
15:19:14 DEBUG - ***Begining Page Log for /apexpages/devmode/developerModeContainer.apexpj_id0:j_id1:j_id2: An error occurred when processing your submitted information.
 
Any thoughts? Thanks!
 
Code:
<apex:page controller="samplecon">
        <apex:form >
                <apex:selectList value="{!countries}" multiselect="false">
                        <apex:selectOptions value="{!items}"/>
                </apex:selectList><p/>
                <apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
        </apex:form>
        <apex:outputPanel id="out">
                <apex:actionstatus id="status" startText="testing...">
                        <apex:facet name="stop">
                                <apex:outputPanel >
                                        <p>You have selected:</p>
                                        <apex:dataList value="{!countries}" var="c">{!c}</apex:dataList>
                                </apex:outputPanel>
                        </apex:facet>
                </apex:actionstatus>
        </apex:outputPanel>
  </apex:page>

 
Code:
public class samplecon {
        String[] countries = new String[]{};
        public PageReference test() {
                return null;
        }
        public List<SelectOption> getItems() {
                List<SelectOption> options = new List<SelectOption>();
                options.add(new SelectOption('US','US'));
                options.add(new SelectOption('CANADA','Canada'));
                options.add(new SelectOption('MEXICO','Mexico'));
                return options;
        }
        public String[] getCountries() {
             return countries;
        }
        public void setCountries(String[] countries) {
                this.countries = countries;
        }
  
  }
  • November 17, 2008
  • Like
  • 0