• Sunil Shah 12
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 4
    Likes Given
  • 0
    Questions
  • 12
    Replies
Hi ,

I have a scenario where i want to update the lead record's rating field when the status changes to status == 'Closed - Not Converted'.And i wrote after update trigger  for this: Below is the code
 trigger leadUpdate on Lead (after update) {
list<lead> leadUpdate = new List<Lead>();
    for(Lead l :trigger.new){
        if(trigger.oldMap.get(l.id).status != l.status && l.status == 'Closed - Not Converted'){
           lead ld = new lead(id = l.id,rating = 'cold');
            leadUpdate.add(ld); 
        }
    
    }
    update leadUpdate; 
}


And samething can be achieved through  before trigger as well. Below code:
trigger  leadUpdate on Lead (before update) {
List<lead> leadUpdate = new List<Lead>();
if(trigger.isBefore && trigger.isUpdate){
         for(Lead l :trigger.new){
        if(trigger.oldMap.get(l.id).status != l.status && l.status == 'Closed - Not Converted'){
           l.rating = 'cold';
            leadUpdate.add(l); 
        }
    
    }
   
    
    }
}
 
I'd like to create an Apex trigger to copy the values from two fields on a custom object to two fields on the Contact object. The custom object hed__Affiliation__c has a lookup to Contact. I'm doing this so we can pull these field into Pardot as our version of Pardot does not allow custom objects. I'm using Apex triggers instead of Process Builder because although Process Builder can copy the files, it cannot handle deleting, which will be my next step.

Here is my code. This works put it populates the account ID for educational institution instead of the name. I'm pulling from the organization field on hed__Affiliation__c which is a lookup to account. If I try to assign education institution to a.hed__Account__c.Name I receive a "A non foreign key field cannot be referenced in a path expression" error when trying to compile. How can I pull the name of the account instead of the ID?

Thanks!
 
trigger CopySchoolToContact on hed__Affiliation__c (after insert, after update) {
List<Contact> conList = new List<Contact>();
    
    for (hed__Affiliation__c a : [SELECT Id,hed__Contact__c,hed__Account__c,Educational_Institution_Class_Year__c FROM hed__Affiliation__c
                     WHERE Id IN :Trigger.New]) {
    
        conList.add(new Contact(Id=a.hed__Contact__c,
            					Educational_Institution__c=a.hed__Account__c, // This populates ID of account and not Name. 
                                Educational_Institution_Class_Year__c=a.Educational_Institution_Class_Year__c)); 
    }
    
    try{
        update conList;
    }
    catch(Exception E){
        system.debug('Error thrown is: ' + E.getMessage());
    }
}



 
I am getting this message "This page isn't available in Salesforce Lightning Experience or Salesforce1." when trying to finish this "https://trailhead.salesforce.com/projects/trailhead_on_mars/steps/trailhead_on_mars_step_4" challenge. Can someone tell me why am i getting this error message. thanks!

 
Both Visualforce and lighning Components used to desighn ui.But i dont know what is the differense between this two.
Hello Buddies,

Can some one explain how to create Approval Process using Process Builder. I created on Approval Process and trying to initiate using process builder but it is not working fine. But Approval Process alone(With out Process Builder) is working as expected.

Any suggessions ?
Thanks in Advance !!!
Hi Devs,

How do we something simple like below in SOQL.

SELECT ID as  ROW_NATURAL_ID FROM ACCOUNT;

Regards,
Nandika
Hi,
I created a quick action that I then used with process builder that isn't working. The quick action is to update a record. I then needed to use it with process builder since the object I'm trying to use it on is a managed package visualforce page without chatter so I can't make the action visible via a button. I'm not getting an error message but it's just not working. 
What I'm trying to do is get a lookup field to autopopulate when the record is created or edited. 
Any thoughts/ideas/ways to find out what's going wrong with my quick action or process, or alternate approaches?
Thank you!
Missy
 
hi all,

I am unable to understand the behaviour of the feature login hour restrictions.
If a users profile can login from 4pm to 5pm and a user logs in at 4.30 pm then what happens at 5.01pm?

Some have said that it automatically logs out,
some assume that the session goes on but he can only view.Once he tries for any DML operation,hez logged out

Can anyone help me out on this?

Thanks

hi,

 I want to add a custom button in Related List.

 for example  I have a custom button named add in contact and i want that button in account  Related List.

  • March 26, 2011
  • Like
  • 0

Do workflows trigger when using import wizard?

 

I found that the workflow does not trigger when I import lead data.

 

Is there any settings to make the workflow trigger when using import wizard?

 

Thank you.

  • June 26, 2009
  • Like
  • 0
Hi
 
I've created this trigger to update the total time for a case based on the times in all the tasks (custom fields).
But I couldn't work out how to use "What.type" to only run the code for tasks associated to cases (I've got a workaround in there as you can see).
Code:
trigger TaskTriggerAfter on Task (after insert, after update, after delete) {
 for (Task task : Trigger.new) {
  String acctID=task.accountid;
  String caseID='';

  Task[] task2 = [select Id from task where (Id=:task.id) AND (What.Type = 'Case')];
  if (task2.size()>0) {
   caseID = task.WhatId;
   Task[] tasks = [select Total_Time_Spent_hours__c from task where WhatId=:caseID];
   Decimal TotalTimeSpent = 0;
   for (Task t : tasks) {
    TotalTimeSpent = TotalTimeSpent + t.Total_Time_Spent_hours__c;
   }
   Case cas = [select Id,TotalTimeSpent__c from Case WHERE Id=:caseID];
   cas.TotalTimeSpent__c = TotalTimeSpent;
   update cas;
  } 
 }
}
 I thought:
  if (task.What.type == 'Case') { would work (replacing the task2 stuff) but it didn't.
So I tried to find out if I got a result from the query but couldn't unless I did it using size (even though only 1 result max will be returned).
Maybe something based on the caseID would be possible: if (caseID.length() )? (I'm not sure about the string functions).
 
If anyone has advice on more efficient ways to code this then please do let me know. Also any links to descriptions of string functions in Apex as I can't find any (such as length).
 
And finally, I've read that you should code triggers to allow for bulk updates, but when will/how can bulk updates occur? (I tried to do a replacement of a picklist value but that only seems to replace the value and the last modified date - it doesn't run the triggers).
 
Thanks.
 


Message Edited by jeremy_w on 03-29-2008 07:01 PM
hi,

i have set the OWD to public read/write and  profile is read only .  i have a sharing rule ( with read/ write)in which  user A wants to share that record to the another user B (in the same profile) .here i have doubt is whether the second user can edit the records or not.

1)and my secod question is profile over rides the OWD....? 

 
I am not getting milestone tracker at case level in service console.

I have valid criteria for Milestones in active Entitlement process( Case Status equals New), Gave permission to Entitlement object at profile level,
gave field level security "Visible" to Entitlement Name field and also added it to case feed page layout. Gone each and every documentation and repeated whole steps, but not able to success in this. Any help on this would be really helpful. Thanks in advance.

User-added image
Hi,
I created a quick action that I then used with process builder that isn't working. The quick action is to update a record. I then needed to use it with process builder since the object I'm trying to use it on is a managed package visualforce page without chatter so I can't make the action visible via a button. I'm not getting an error message but it's just not working. 
What I'm trying to do is get a lookup field to autopopulate when the record is created or edited. 
Any thoughts/ideas/ways to find out what's going wrong with my quick action or process, or alternate approaches?
Thank you!
Missy
 
Hi
 
I've created this trigger to update the total time for a case based on the times in all the tasks (custom fields).
But I couldn't work out how to use "What.type" to only run the code for tasks associated to cases (I've got a workaround in there as you can see).
Code:
trigger TaskTriggerAfter on Task (after insert, after update, after delete) {
 for (Task task : Trigger.new) {
  String acctID=task.accountid;
  String caseID='';

  Task[] task2 = [select Id from task where (Id=:task.id) AND (What.Type = 'Case')];
  if (task2.size()>0) {
   caseID = task.WhatId;
   Task[] tasks = [select Total_Time_Spent_hours__c from task where WhatId=:caseID];
   Decimal TotalTimeSpent = 0;
   for (Task t : tasks) {
    TotalTimeSpent = TotalTimeSpent + t.Total_Time_Spent_hours__c;
   }
   Case cas = [select Id,TotalTimeSpent__c from Case WHERE Id=:caseID];
   cas.TotalTimeSpent__c = TotalTimeSpent;
   update cas;
  } 
 }
}
 I thought:
  if (task.What.type == 'Case') { would work (replacing the task2 stuff) but it didn't.
So I tried to find out if I got a result from the query but couldn't unless I did it using size (even though only 1 result max will be returned).
Maybe something based on the caseID would be possible: if (caseID.length() )? (I'm not sure about the string functions).
 
If anyone has advice on more efficient ways to code this then please do let me know. Also any links to descriptions of string functions in Apex as I can't find any (such as length).
 
And finally, I've read that you should code triggers to allow for bulk updates, but when will/how can bulk updates occur? (I tried to do a replacement of a picklist value but that only seems to replace the value and the last modified date - it doesn't run the triggers).
 
Thanks.
 


Message Edited by jeremy_w on 03-29-2008 07:01 PM