• Sanpreet Saini
  • NEWBIE
  • 109 Points
  • Member since 2015
  • Salesforce Developer/Consultant
  • HCL Technologies Ltd


  • Chatter
    Feed
  • 4
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 0
    Questions
  • 36
    Replies
Hi All,

I have an object with 2 lookup fields in it. My scenario goes in this way-
1. If User selects both the lookup fields in detail page and Click on Save, it should throw the Validation Error to select any one of lookup instead of both

Thanks
Hello,

Excecuting below code inside trigger gave me below exception

System.CalloutException: Callout from triggers are currently not supported.
trigger XYZ on Account (before update) {

HttpRequest req = new HttpRequest();
Http http = new Http();
req.setMethod('GET');
String url = 'https://maps.googleapis.com/maps/api/distancematrix/json' + '?origins=' + address1 + '&destinations=' + address2 + '&mode=driving' + '&sensor=false' + '&language=en' + '&units=imperial';
req.setEndPoint(url);
HTTPResponse resp = http.send(req);

}

Thank you for suggestion !
  • November 19, 2015
  • Like
  • 0
I have created the trigger where there a update in the master record status field ,resultant update should be in child record.but am getting the error  of update the child record.Please see the trigger code and please let me know your suggestion.

trigger CreateContoofPositionUpdate on Account  (after insert,after update){    
    List<Contact> Cont =new List<Contact>();
     
  Contact con = [select id, Warehouse_14__Rounds__c, Warehouse_14__Status__c,Warehouse_14__Types__c,Warehouse_14__Name__c from Contact limit 1];
    for (Account posi: trigger.new)
        if(posi.Warehouse_14__Type__c == 'High Level' || posi.Warehouse_14__Functional_Area__c =='Project Management' || posi.Warehouse_14__Functional_Area__c == 'Infrastructure Architect' 
           || posi.Warehouse_14__Functional_Area__c == 'Domain Expert'){
             con.Warehouse_14__Rounds__c ='Managerial';
             con.Warehouse_14__Status__c ='N/A';
             con.Warehouse_14__Types__c ='Skype';
             con.Warehouse_14__Name__c = posi.id;
           }    
       
             Cont.add(con);
    
    update Cont;
}

Error Message as :
Error:Apex trigger Warehouse_14.CreateContoofPositionUpdate caused an unexpected exception, contact your administrator: Warehouse_14.CreateContoofPositionUpdate : execution of AfterUpdate caused by: System.QueryException: List has more than 1 row for assignment to SObject:Trigger.Warehouse_14.CreateContoofPositionUpdate : line 6, column 1

Is there further  changes needed on the above trigger code.

Regards,
Karthik
I have a  requirement to copy phone from contact to related account phone.but my trigger not works, can some one help me on this
trigger copy on account(after insert,after update) {

List<id> carry=New list<id>();
For(account acc:trigger.new){
carry.add(acc.id);

}
List<Contact> hold=[select id, name,phone from contact where id IN: carry];
List<account> take=[Select id,phone from account where id IN: carry];
for(account acc:take){
for(contact c:hold){
acc.phone=c.phone;
}
}
}

I tried to create a trigger on contact also as below but not works.
trigger abc on Contact (after insert,after update) {

List<id> carry=New list<id>();
For(contact c:trigger.new){
carry.add(c.id);

}
List<Contact> hold=[select id, name,phone from contact ];
List<account> take=[Select id,phone from account where id IN: carry];
for(account acc:take){
for(contact c:hold){
acc.phone=c.phone;
}
}

}
I have created a process builder action that automatically fills the Service End Date of an Opportunity, how can I make setting to make the value in the Service End Date field editable if it's wrong?
Hi All,

I have an object with 2 lookup fields in it. My scenario goes in this way-
1. If User selects both the lookup fields in detail page and Click on Save, it should throw the Validation Error to select any one of lookup instead of both

Thanks
Hello,

Excecuting below code inside trigger gave me below exception

System.CalloutException: Callout from triggers are currently not supported.
trigger XYZ on Account (before update) {

HttpRequest req = new HttpRequest();
Http http = new Http();
req.setMethod('GET');
String url = 'https://maps.googleapis.com/maps/api/distancematrix/json' + '?origins=' + address1 + '&destinations=' + address2 + '&mode=driving' + '&sensor=false' + '&language=en' + '&units=imperial';
req.setEndPoint(url);
HTTPResponse resp = http.send(req);

}

Thank you for suggestion !
  • November 19, 2015
  • Like
  • 0
Hi Experts,

My requirment is  i have object called Site__C it contains fields called , Public_Site_Clear__c,Private_Site_Clear__c,Site_Clear__c so what we need to do that 

When Public Site Clear(Public_Site_Clear__c) and Private Site Clear(Private_Site_Clear__c) dates are both populated, trigger the update (on initial population only) of the Site Clear(Site_Clear__c) field with the latest date. i.e Public Site Clear = 23/10/2015, Private Site Clear = 02/11/2015, therefore Site Clear = 02/11/2015. If the dates are subsequently changed then do nothing.

Could anyone help me pleaase

 
I'm posting here in an effort to get what is clearly a gap/bug in functionality some attention. I tried the route of Salesforce support, but as always it was a frustrating weeks long process that ended with them suggesting I post an Idea to the IdeaExchange so it can remain unacknowledged for 3-5 years. 

Issue:  It is possible to upload a file to Chatter Files in a way that doesn't activate any triggers.

Ways to upload a file to chatter:
  1. 'Upload Files' link on the 'Files' tab
  2. Create a new Chatter post, using the 'File' post type
  3. Comment on an existing Chatter post, and use the 'Attach File' link

2 of these methods fire a trigger: 
  1. A trigger on ContentVersion will fire for uploads directly to the File Tab
  2. A trigger on FeedItem will fire if the file is uploaded on a File chatter post

However, it is possible to upload a file through a Chatter comment without firing any trigger!

Even if a trigger is in place on FeedItem, this trigger will only fire upon submitting the comment as a whole - it is possible to upload the attached file to a comment before the comment is even submitted!

Steps to replicate (upload to Files without firing a trigger):
1. Find a chatter post you can add a comment to.
2. Click the 'Attach File' link and select a file
3. An upload progress bar will complete - this is the point where a trigger should have fired!
4. Don't press the 'cancel' link on the attached file. So long as this isn't pressed, it doesn't matter whether the comment is actually posted or not.
5. Now go to your Files tab: voila, the comment's attached file was uploaded, even though the comment was never posted!

User-added image

Again, no trigger is fired on any object when a file is uploaded using this method. Clearly the file upload should not be allowed to complete until after the comment is posted, but this is not the case.

Am I going crazy here, or is this clearly unexpected behavior that needs to be fixed? Why am I having such a hard time trying to get Salesforce to acknowledge this is a real issue? 

 
I have created the trigger where there a update in the master record status field ,resultant update should be in child record.but am getting the error  of update the child record.Please see the trigger code and please let me know your suggestion.

trigger CreateContoofPositionUpdate on Account  (after insert,after update){    
    List<Contact> Cont =new List<Contact>();
     
  Contact con = [select id, Warehouse_14__Rounds__c, Warehouse_14__Status__c,Warehouse_14__Types__c,Warehouse_14__Name__c from Contact limit 1];
    for (Account posi: trigger.new)
        if(posi.Warehouse_14__Type__c == 'High Level' || posi.Warehouse_14__Functional_Area__c =='Project Management' || posi.Warehouse_14__Functional_Area__c == 'Infrastructure Architect' 
           || posi.Warehouse_14__Functional_Area__c == 'Domain Expert'){
             con.Warehouse_14__Rounds__c ='Managerial';
             con.Warehouse_14__Status__c ='N/A';
             con.Warehouse_14__Types__c ='Skype';
             con.Warehouse_14__Name__c = posi.id;
           }    
       
             Cont.add(con);
    
    update Cont;
}

Error Message as :
Error:Apex trigger Warehouse_14.CreateContoofPositionUpdate caused an unexpected exception, contact your administrator: Warehouse_14.CreateContoofPositionUpdate : execution of AfterUpdate caused by: System.QueryException: List has more than 1 row for assignment to SObject:Trigger.Warehouse_14.CreateContoofPositionUpdate : line 6, column 1

Is there further  changes needed on the above trigger code.

Regards,
Karthik
Hi

I need to have a dynamic query to retrieve the fields in Campaign object (keeping aside the governace limit) but when i execute a sample query with all the fields in query editor I see an error "No such column 'hierarchyactualcost' on entity 'Campaign'."

when i set this field as visible for profile and then execute the query i do not see this error. Any ways on how to fix this so that i can perform the query without any errors?

the code to get the fields from the object is:

        Map <String, Schema.SObjectField> objectFields = Campaign.getSobjectType().getDescribe().fields.getMap();
        for (SObjectField fld : objectFields.values()) {
            query += ' ' + fld + ', ';
        }

is there a way to see if the field is set as not visible and if so then do not consider the field in the query?
  • October 07, 2015
  • Like
  • 0
I have a Task trigger on which I'm tyring to also reset the checkbox values to be unchecked in the before context but still use the initial values (prior to resetting) in the after context.  The idea is to reset them without having to execute a DML update later on in the trigger.  The problem is that the values are not being captured in the before context - they are all remaining false, so I can't use them for logic in the after context.  Thank you in advance for any help you can provide.

Code
 trigger EmailTaskDescription on Task(before insert, after insert, before update, after update)
 {
     Boolean nofityRIW = false;
     Boolean nofityREW = false;
     Boolean nofityBDC = false;
     Boolean nofityGIW = false;
     Boolean nofityGEW = false;

     if (trigger.isBefore)
     {
         Task tt = Trigger.new[0];
         //capture checkbox selections
         nofityRIW = tt.Notify_R_IW__c;
         nofityREW = tt.Notify_R_EW__c;
         nofityBDC = tt.Notify_BDC__c;
         nofityGIW = tt.Notify_G_IW__c;
         nofityGEW = tt.Notify_G_EW__c;
         //reset checkbox selections to unchecked
         tt.Notify_R_IW__c = false;
         tt.Notify_R_EW__c = false;
         tt.Notify_BDC__c = false;
         tt.Notify_G_EW__c = false;
         tt.Notify_G_IW__c = false;
     }
     if (trigger.isAfter)
     {
        //use initial values to execute logic 
        if (nofityRIW)
         {

         }
         else if (nofityREW)
         {

         }
     }
 }
I have a  requirement to copy phone from contact to related account phone.but my trigger not works, can some one help me on this
trigger copy on account(after insert,after update) {

List<id> carry=New list<id>();
For(account acc:trigger.new){
carry.add(acc.id);

}
List<Contact> hold=[select id, name,phone from contact where id IN: carry];
List<account> take=[Select id,phone from account where id IN: carry];
for(account acc:take){
for(contact c:hold){
acc.phone=c.phone;
}
}
}

I tried to create a trigger on contact also as below but not works.
trigger abc on Contact (after insert,after update) {

List<id> carry=New list<id>();
For(contact c:trigger.new){
carry.add(c.id);

}
List<Contact> hold=[select id, name,phone from contact ];
List<account> take=[Select id,phone from account where id IN: carry];
for(account acc:take){
for(contact c:hold){
acc.phone=c.phone;
}
}

}
When attempting to convert a Lead to an Opportunity, our LeadConvert class is throwing the same exception every 2-3 hours. The exception is thrown from the convertLeads method.

Is there any way we can kill the process that's throwing the exceptions? Any test conversions we've done succeed so it looks like it's the same one trying and failing every 2-3 hours.

The exception email says:
 
Apex script unhandled trigger exception by user/organization: 005200000033tk4/00D20000000Cl2i
 
LeadConverter: execution of AfterInsert
 
caused by: System.DmlException: ConvertLead failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Validation error on Opportunity: If the Lead is to be converted ... please set a Lead Source: []
 
Trigger.LeadConverter: line 44, column 1
and the LeadConverter class is
Trigger LeadConverter on Lead (after insert) 
{

    // Get String for 'Converted'
    LeadStatus convertStatus = [
        select MasterLabel
        from LeadStatus
        where IsConverted = true
        limit 1
    ];
    
    // Get Automated Lead RecordTypeId
    RecordType leadRt = [
        Select id 
        From RecordType
        where developername='Automated_Lead'
        limit 1
    ];
    
    List<Database.LeadConvert> leadConverts = new List<Database.LeadConvert>();
    
    for (Lead lead: Trigger.new) 
    {
    
      // For each unconverted Automated Lead
      if (!lead.isConverted && lead.RecordTypeId == leadRt.id) 
      {
      
        Database.LeadConvert lc = new Database.LeadConvert();
               
        lc.setLeadId(lead.Id);
        lc.setOpportunityName(lead.Name);
        lc.setConvertedStatus(convertStatus.MasterLabel);
               
        leadConverts.add(lc);

      }
    }
 
    if (!leadConverts.isEmpty())
    {
      List<Database.LeadConvertResult> lcr = Database.convertLead(leadConverts);
    }
}
The Validation Rule referenced in the email is
AND(  IsConverted = True,  LEN(TEXT(LeadSource))=0 )
Any help much appreciated!
I am not sure how to go about creating the best solution for the senario below. 

If Signed_By_Client__c date is > Signed_by_Vendor__c  date, populate date in Executed_Date__c field 
If Signed_By_Vendor__c date is > Signed_By_Client__c date, populate date in Executed_Date__c field
If Signed_by_Vendor__c date and Signed_By_Client__c date is = to each other,  Executed_Date__c field will be either of the 2  

The executed field must contain the latest date of the two fields. 

Thanks in advance!

Thanks in advance! 

Hello Friends,

I need assistance writing a trigger that will allow me to copy an attachment from a DocuSign object to a contract.

Just some background...

I have a trigger that creates a contract when DocuSign_Status (object) = Completed. The DocuSign workflow adds the attachment to the already created DocuSign_Status record when signing is completed; which fires the trigger to create the contract. Unfortunately, the trigger does not include copying of the attachment. 

I need to add in copying of the attachment to the current trigger or write a new one, but I need help! I have researched and seen many ways of doing something similar, but not sure it is what I need. I am attaching my trigger below. Any help would be greatly appreciated.

Thanks!  Shannon

trigger CreateContractDocSignComp on dsfs__DocuSign_Status__c (after update)
{
    List<Contract> ctr = new List<Contract>();
    
      for(dsfs__DocuSign_Status__c dsfs : Trigger.new)
      {
        if(dsfs.dsfs__Envelope_Status__c == 'Completed')
        {
             Contract c = new Contract(Name = dsfs.Name,
             Status = 'Draft',
             Total_Contract_Value__c =dsfs.Total_Contract_Value__c,
             StartDate = dsfs.Contract_Start_Date__c,
             Payment_Status__c = 'Ready to be Invoiced',
             AccountId = dsfs.dsfs__Company__c,
             Opportunity_Name__c = dsfs.dsfs__Opportunity__c);
             ctr.add(c);
         }
      }
      if(ctr.size() > 0)
      {
            System.debug('-ctr------->'+ctr.size());
            insert ctr;
      }     
}

Hi everybody, 
Now I have very fruitful position in Germany, Berlin from product company. main requirements: 3+ years of experience in Salesforce.com (frontend and backend), Java, JavaScript (CSS and HTML), advanced English level. Full relocation package(if you need). Salary rate 45-50k euro per a year. If you are interested in working in Germany or changing your current project, please write me by skype: somova.it

I'll be grateful for any recommendations:) Thank you for attention and have a perfect day!