• Ramesh Somalagari
  • NEWBIE
  • 44 Points
  • Member since 2013
  • Senior Saleforce Consultant

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 1
    Likes Given
  • 25
    Questions
  • 38
    Replies
I'm getting the following error while deploying the case page layout to another org vi Copado.
Deployment Error:

[QuickAction Case.Custom_Email] Send Email is disabled or activities are not allowed. Enable Send Email and allow activities, then try again.[Layout Case-Billing Line Item Adjustment] In field: QuickAction - no QuickAction named Case.Custom_Email found

In target org I did the "No Access" for Deliverability under the Email Administration and tried to deploy the page layout still getting the same error.
Kindly please help me out.
Hi All I have written the apex trigger.It working in sandbox but not in Production.While upload the csv file by using apex data loader in production it throws an exception below.

**Exception:**

    31:04.975 (975279099)|EXCEPTION_THROWN|[29]|System.DmlException: Delete failed. First exception on row 0 with id a3O80000001pJnxxxx; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = a3N8000000aaaa) is currently in trigger Bidpro_Details_Delete, therefore it cannot recursively update itself: []
    12:31:04.975 (975850995)|SYSTEM_METHOD_EXIT|[29]|Database.delete(LIST<SObject>)
    12:31:04.975 (975925291)|SYSTEM_METHOD_ENTRY|[46]|String.valueOf(Object)
    12:31:04.975 (975965515)|SYSTEM_METHOD_EXIT|[46]|String.valueOf(Object)
    12:31:04.975 (975987895)|SYSTEM_METHOD_ENTRY|[46]|System.debug(ANY)
    12:31:04.975 (975997242)|USER_DEBUG|[46]|DEBUG|ERROR : Trigger BidDeleteTrigger_Delete :System.DmlException: Delete failed. First exception on row 0 with id a3O80000001pJnxxxx; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = a3N8000000aaaa) is currently in trigger Delete, therefore it cannot recursively update itself: []
    12:31:04.976 (976004076)|SYSTEM_METHOD_EXIT|[46]|System.debug(ANY)

**Apex Trigger:**

    Trigger BidDeleteTrigger on Bid__c (BEFORE UPDATE)
    {  
   
        TRY
        {
            LIST<Bid_line__c> bidline = NEW LIST<Bid_line__c>();
            LIST<Id> bidid = NEW LIST<Id>();
            FOR(Bid__c bidpro : Trigger.NEW) 
            { 
                 IF(bidpro.Delete__c == TRUE)
                 { 
                    bidpro.Delete__c = FALSE;      
                    bidid.add(bidpro.Id);
                 }
            }
            IF(bidid.SIZE() != 0)
            {   
                bidline = [SELECT ID FROM Bid_line__c WHERE Bid__c IN: bidid LIMIT 50000];
                IF(bidline.size() != 0)               
                      Database.DeleteResult[] del = Database.DELETE(bidline);
            }
         }
         CATCH(EXCEPTION E){
             SYSTEM.DEBUG('ERROR:'+E);
         }  
    }

Same code is working in Sandbox.It not throws any exception.Can someone please help me.


Exception :
System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out*

**Visualforce Page**

    <apex:page controller="Controller" action="{!init}" showHeader="false" sidebar="false">
        <center>
            <apex:pageBlock title="Request Listener"></apex:pageBlock>         
        </center>
    </apex:page>
**Controller :**         


    PUBLIC with sharing class Controller
    {  
        PUBLIC String fromNumber      = ApexPages.currentPage().getParameters().get('From');
        PUBLIC String toNumber        = ApexPages.currentPage().getParameters().get('To');
        PUBLIC String body            = ApexPages.currentPage().getParameters().get('Body');  
        PUBLIC PageReference init()
        {          
            System.debug('From Phone Number :' +fromNumber);
            System.debug('To phone NUmber :' + toNumber);
            System.debug('Message Body :' + body);
                          
            TwilioRestClient Client = TwilioAPI.getDefaultClient();                                                  
                SYSTEM.DEBUG('FROM AND To  Number is NOT NULL');        
                String formattedNumber='+919876543210';   
                IF(body != NULL)
                    body = body;
                ELSE
                    body = '';
                Case c = NEW Case (Subject = formattedNumber,Description = body,Origin = 'Phone');
                INSERT c;                
               
                Map<String,String> params1 = new Map<String,String>
                {
                   'To'   => fromNumber,
                   'From' => '+1908280****',
                   'Body' => 'Conformation to customer'
                };
                TwilioMessage message = client.getAccount().getMessages().create(params1); /* Valid conformation SMS sent to the Customer.*/                                  
            return null ;
        }
    }
   

While login as admin then click preview on visualforce page executed but case is not created.I have checked the the debug log it throw the exception.

 
I have created simple site that create a new case.

User-added image
Note :

- I have given the Site permissions Visualforce page,Controller ,Lead Object and Case Object.
- While execute the site Lead is created similarly I tried to create a new case it not happens.
- I have given the case Object create permission but why it is not created
Can someone please help me.
While executing the site it showing the error:

**Visualforce Page**

    <apex:page controller="Controller" action="{!init}" showHeader="false" sidebar="false">
        <center>
            <apex:pageBlock title="Request Listener"></apex:pageBlock>         
        </center>
    </apex:page>
**Controller :**
  

         public with sharing class Controller
                {           
                    public PageReference init()
                    {
                    try
                    {                   
                    // Lead l1 = new Lead(FirstName='first name1',LastName = 'lead last name',phone ='9876543210');//testing
                     //insert l1;   testing       
                   Case c = new Case(Subject = 'Subject Test',Description ='Description Test');
                  insert c;
                }
                  }
                   catch(exception e){}
                    RETURN null;
                   } 
                }



I have a class that can access the site url in the salesforce.
The site url "https://somesalesforce.com/smsToApex" and same as the twilio account sms URL but this class can't called.User-added image I have reference https://developer.salesforce.com/blogs/developer-relations/2012/04/sms-to-lead-with-the-twilio-library-for-salesforce.html#comment-1449666487 .The twilio SMS url correct are not how to check?The Twilio account SMS url and salesforce site url are same as of now.Whenever SMS is came via twilio then automatically Case is createin the sandbox.But here not happened.I doing correct producer are not?.Can someone please help me.How to resolve this problem.I have checked the twilio sms url like this "https://somesalesforce.com/service/apexrest/smsToApex".which url I will give both Salesforce site url, Twilio SMS url.


    @RestResource(urlMapping='/smsToApex')
    global class smsToApex
    {  
        Static TwilioAccount account = TwilioAPI.getDefaultAccount();        
        @HttpPost
        global static void incomingSMS()
        {       
            // This will error out with System.LimitException if we would exceed
            // our daily email limit
            Messaging.reserveSingleEmailCapacity(1);
   
            String expectedSignature = RestContext.request.headers.get('X-Twilio-Signature');
            system.debug('ES' + expectedSignature);
            String url = 'https://' + RestContext.request.headers.get('Host') + '/services/apexrest' + RestContext.request.requestURI;
            Map <String, String> params = RestContext.request.params;
           system.debug('smsToApex========>'+params);
            // Validate signature
            if (!TwilioAPI.getDefaultClient().validateRequest(expectedSignature, url, params)) {
                RestContext.response.statusCode = 403;
                RestContext.response.responseBody = Blob.valueOf('Failure! Rcvd '+expectedSignature+'\nURL '+url/*+'\nHeaders'+RestContext.request.headers*/);
               
                return;
            }      
            RestContext.response.responseBody = Blob.valueOf('ok');       
            String caseFrom = params.get('From');
             String caseTo = params.get('To');
            String   caseBody = params.get('Body');         
              System.debug('Step 4 smsToApex caseFrom==>'+caseFrom);
              System.debug('Step 5 smsToApex caseTo===>'+caseTo);
              System.debug('Step 6 smsToApex caseBody===>'+caseBody);         
               Case ca = new Case();
                ca.Subject = 'Test smsToApex caseFrom'+caseFrom;
                ca.Description = 'Test smsToApex caseBody'+caseBody+','+caseTo;
                ca.Origin = 'Phone';
                INSERT ca;                 
         }                      
    }



Right now I am sending the sms via twilio account.But Unable to receive sms in the salesforce
How to get the twilio sms request in the salesfore.
User-added image

I have twilio sms url it hit the automatically open the my visual force page then controller send an sms but it didn't receive the sms details my question is similar to  http://stackoverflow.com/questions/24326577/how-to-receive-the-sms-via-twilio how to get sms details   .I have  follow   https://clintlee.sys-con.com/node/1712284/mobile.
Can some one  please help as soon as possible it is an urgent requirement .



I have install the twilio package and following components.How to configure the two components.When customer send an sms it not created an case in sandbox.Here I am unable to receive sms details.The twilio message url where should I give in the salesforce.

User-added image
I am completely new about twilio configuration.Can someone please help.
Whenever customer send an sms then it create an case in sandbox automatically by using twilio api .

**Component 1: Visual force Fage**

    <apex:page controller="TwilioRequestControllerContacts" action="{!init}" showHeader="false" sidebar="false">
        <center>
            <apex:pageBlock title="Twilio Request Listener"></apex:pageBlock>         
        </center>
    </apex:page>
**Component 2: Controller**

    public with sharing class TwilioRequestControllerContacts
    {
        public String fromNumber      = ApexPages.currentPage().getParameters().get('From');
        public String toNumber        = ApexPages.currentPage().getParameters().get('To');
        public String body            = ApexPages.currentPage().getParameters().get('Body');
        public PageReference init()
        {
        try
        {          
           System.debug('STEP 0 FROM: ==========>' + fromNumber);
           System.debug('STEP 1 TO: ===============>' + toNumber);
           System.debug('STEP 2 BODY: ==========>' + body);
           System.debug('STEP 3  ==============>');                
           String account = 'xxxxxxxxxxx';  
           String token = 'xxxxxxxxxxxx';
           TwilioRestClient client = new TwilioRestClient(account,token);
           system.debug('STEP 4 test==3>'+client);
           if(fromNumber != null && toNumber != null) { 
        //my own logic               
          Case ca = new Case(Subject = fromNumber,Description = body,Origin = 'Phone');
               INSERT ca;      
               RETURN null;
           }
        }               
       catch(exception e){
            system.debug('STEP 7 error ==========>'+e);
       }
        RETURN null;
       } 
    }



Hi all this my code I got the exception below,I unable to send the SMS twilio API. Please some one help me

**ERROR :** Unauthorized endpoint, please check Setup->Security->Remote site settings endpoint: uerl
Where should I add the twilio URL?

    global class SampleSMSTest
        {  
        @future (callout=true)
        Public static void testsms(){
        try{
        String account = 'xxxxxxxxx';         
        String token = 'xxxxxxxxxx';
        TwilioRestClient client = new TwilioRestClient(account, token);          
        Map<String,String> params = new Map<String,String> {
        'To'   => '+91953835xxxx',
        'From' => '+1920569xxxx',//twilio register number
         'Body' => 'Hello there!'         
          };
           TwilioMessage message = client.getAccount().getMessages().create(params);       
                }catch(exception e){
                system.debug('Main error==========>'+e);}
            }
        }
I have install the "twilio" api in salesforce and I have register twilio phone number. How to receive the SMS details and how revert back the conformation.Which class should be call and where should I give the accoutsid,authosid and twilio phone number in Installed Package from Sandbox .
I need to install the Twilio package into my sandbox. I have have a requirement where I need to receive an SMS from the Customer and create a case. After that I need to Revert back an SMS to the Customer saying a received Conformation. How Do i Do it. I am completely new to this API. Please Help me out.
I have install the Twilio package in Sandbox and I have register the mobile number in Twilio it generates new new number. Then I need to get the SMS details then creates new case in Sandbox.Where will I get the SMS details in TWILIO API from Sandbox. If customer send a SMS then API get the SMS details then create a new case in the Sandbox.

Please help me....

I a have install the Twilio API in Organisation and I have a custom object.When ever receives a message in sandbox that message details can store in the Custom object.

1. How to store the message details in the custom Object?

2. After receive the message,How to send a conformation message to customer?

Entire process send/revive message's should be handled TWILIO API
Need to configure the Twilio API in the Sandbox.When I send an SMS that can be created as case in the Sandbox(Like email to case process). How configure the TWILIO API and after configured how to create case in the Sandbox? Some one please help me.


I have StreamingAPI it working properly.It some time response has error at the time response JSON Object as error.The log file response contains error below

Wed May 15 08:33:07 MST 2014 : Waiting for next message - Looping for timeout
Wed May 15 08:33:23 MST 2014 : Login response: {
  "error": "unknown_error",
  "error_description": "retry your request"
}

Wed May 15 08:34:47 MST 2014 : Waiting for next message - Looping for timeout
Wed May 15 08:34:48 MST 2014 : Waiting for next message - Looping for timeout

It continues repeating the message "Waiting for next message - Looping for timeout"

I Have restart the the service manually it working fine. Any one tell me why response is error?
I have a validation rule on the Account Object as below:

AND( 
NOT ISBLANK( Name),
ISPICKVAL (Account_Level__c, "Company" ),
ISBLANK( Address__c ),
NOT $User.Status__c
)
The above rule working when the Account is Created/Updated.Now I am create a Trigger on the Custom Object(Company):Trigger name is CompanySurvey. In CompanySurvey Trigger I Update the one field in Account Object.At the time does't showing the ERROR in standard-lone.But Account is not Updated because is validation rule executes.I debug the CompanySurvey Trigger in ERROR logs it show the error message but not showing the standard-lone.

Company lookup with Account Object.

Best Regards,
Ramesh
Hi,

I have trigger which fires when a Post is inserted in the Chatter.
How do I write a test case for that.
My Trigger code is

rigger ChatterFeedPost on FeedItem (After Insert) {
  
List <Control_data__c> controldata = new List<Control_data__c>();
list<Messaging.SingleEmailMessage> maillist = new list<Messaging.SingleEmailMessage>();
List <TopicAssignment> topassg = new List<TopicAssignment>();
List <Topic> topicname = new List<Topic>();
controldata = [Select id,Name,Data__c,Reference__c from Control_data__c where name = :'CHT'];
TRY
{
     For(FeedItem item : Trigger.New)
     {
       
            if(controldata.size()!=0)
            {
              
                   topassg = [Select id,topicid,entityid from topicassignment where entityid = :item.id];              
                   For(Topicassignment newtop:topassg)
                   {
                       topicname = [Select name from topic where id = :newtop.topicid];
                       if(topicname.size()!=0)
                       {
                           for(Topic finname: topicname)
                           {
                               For(Control_data__c cdata:controldata)
                               {
                                   /* Do something */
                               }
                             
                           }                     
                       }
                                  
                   }
                 
              
            }
              
          
    }
}
CATCH(Exception e){
    System.debug('MAIN EXCEPTION'+e);
}

}

Now how do I write a test case for this Trigger.
Please help me out ...
The Streaming API is some time working in Production and some time's are not working the Production.I don't the region may be the Streaming API LIMITATION'S?

Pleas tell me the any other regions are around the Streaming API.

Warm Regards
Ramesh
I have created VF Page it is attached to Account Object.Now when I click the standard (System default)"Edit" Button on Account Object my VF is not getting displayed,After I click the standard (System default)"Save" Button my VF page is displayed.

Can my VF page be displayed when the Account Object is edited ?

Please let met know.

VF Page

<apex:page standardController="Account"  extensions="NewAndExistingController" id="demoId" >     
    <apex:form >   
        <apex:pageBlock >
            <apex:commandButton value="Call visualforce Page" action="{!click}"/>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Controller:

public class NewAndExistingController {
    Public Account a= new Account();
    public NewAndExistingController(ApexPages.StandardController controller) {
        try{
            a =[select id,name from account where id=:controller.getId()];
        }catch(exception e){}
    } 
    public PageReference click() {
        PageReference openvfpage = New Pagereference('/apex'+'/XXXXVF'+'?aid='+a.id);//calling to another VF page
        openvfpage.setRedirect(false);
        return openvfpage ; 
    }
    public NewAndExistingController() {  }
}
Best Regards,
Ramesh
Hi,

I have created VF Page,It attached to Account Object under the one section.It shows the After Account is Created.Now I update the same Account at the time also not showing,After updated then it showing. I want When the user create/Edit Account at the same time it shows our VF page.If it is possible some one please let me know as soon as possible

Best Regards,
Ramesh
Hi
I have created one secetion on the Account Object.Section name is "Account Order Info",In that secetion I have attached to one VF page in sandbox.Now my question is how to deploy the my section to Production? I know how to deploy the VF page to Production. Suppose I deploy VF page to Production it show's section on the Account? Otherwise we will create new section then attached to my VF page?in the Production.

Thanks & Best Regards,
Ramesh
I have install the "twilio" api in salesforce and I have register twilio phone number. How to receive the SMS details and how revert back the conformation.Which class should be call and where should I give the accoutsid,authosid and twilio phone number in Installed Package from Sandbox .
I'm getting the following error while deploying the case page layout to another org vi Copado.
Deployment Error:

[QuickAction Case.Custom_Email] Send Email is disabled or activities are not allowed. Enable Send Email and allow activities, then try again.[Layout Case-Billing Line Item Adjustment] In field: QuickAction - no QuickAction named Case.Custom_Email found

In target org I did the "No Access" for Deliverability under the Email Administration and tried to deploy the page layout still getting the same error.
Kindly please help me out.
Hi All I have written the apex trigger.It working in sandbox but not in Production.While upload the csv file by using apex data loader in production it throws an exception below.

**Exception:**

    31:04.975 (975279099)|EXCEPTION_THROWN|[29]|System.DmlException: Delete failed. First exception on row 0 with id a3O80000001pJnxxxx; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = a3N8000000aaaa) is currently in trigger Bidpro_Details_Delete, therefore it cannot recursively update itself: []
    12:31:04.975 (975850995)|SYSTEM_METHOD_EXIT|[29]|Database.delete(LIST<SObject>)
    12:31:04.975 (975925291)|SYSTEM_METHOD_ENTRY|[46]|String.valueOf(Object)
    12:31:04.975 (975965515)|SYSTEM_METHOD_EXIT|[46]|String.valueOf(Object)
    12:31:04.975 (975987895)|SYSTEM_METHOD_ENTRY|[46]|System.debug(ANY)
    12:31:04.975 (975997242)|USER_DEBUG|[46]|DEBUG|ERROR : Trigger BidDeleteTrigger_Delete :System.DmlException: Delete failed. First exception on row 0 with id a3O80000001pJnxxxx; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = a3N8000000aaaa) is currently in trigger Delete, therefore it cannot recursively update itself: []
    12:31:04.976 (976004076)|SYSTEM_METHOD_EXIT|[46]|System.debug(ANY)

**Apex Trigger:**

    Trigger BidDeleteTrigger on Bid__c (BEFORE UPDATE)
    {  
   
        TRY
        {
            LIST<Bid_line__c> bidline = NEW LIST<Bid_line__c>();
            LIST<Id> bidid = NEW LIST<Id>();
            FOR(Bid__c bidpro : Trigger.NEW) 
            { 
                 IF(bidpro.Delete__c == TRUE)
                 { 
                    bidpro.Delete__c = FALSE;      
                    bidid.add(bidpro.Id);
                 }
            }
            IF(bidid.SIZE() != 0)
            {   
                bidline = [SELECT ID FROM Bid_line__c WHERE Bid__c IN: bidid LIMIT 50000];
                IF(bidline.size() != 0)               
                      Database.DeleteResult[] del = Database.DELETE(bidline);
            }
         }
         CATCH(EXCEPTION E){
             SYSTEM.DEBUG('ERROR:'+E);
         }  
    }

Same code is working in Sandbox.It not throws any exception.Can someone please help me.


Exception :
System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out*

**Visualforce Page**

    <apex:page controller="Controller" action="{!init}" showHeader="false" sidebar="false">
        <center>
            <apex:pageBlock title="Request Listener"></apex:pageBlock>         
        </center>
    </apex:page>
**Controller :**         


    PUBLIC with sharing class Controller
    {  
        PUBLIC String fromNumber      = ApexPages.currentPage().getParameters().get('From');
        PUBLIC String toNumber        = ApexPages.currentPage().getParameters().get('To');
        PUBLIC String body            = ApexPages.currentPage().getParameters().get('Body');  
        PUBLIC PageReference init()
        {          
            System.debug('From Phone Number :' +fromNumber);
            System.debug('To phone NUmber :' + toNumber);
            System.debug('Message Body :' + body);
                          
            TwilioRestClient Client = TwilioAPI.getDefaultClient();                                                  
                SYSTEM.DEBUG('FROM AND To  Number is NOT NULL');        
                String formattedNumber='+919876543210';   
                IF(body != NULL)
                    body = body;
                ELSE
                    body = '';
                Case c = NEW Case (Subject = formattedNumber,Description = body,Origin = 'Phone');
                INSERT c;                
               
                Map<String,String> params1 = new Map<String,String>
                {
                   'To'   => fromNumber,
                   'From' => '+1908280****',
                   'Body' => 'Conformation to customer'
                };
                TwilioMessage message = client.getAccount().getMessages().create(params1); /* Valid conformation SMS sent to the Customer.*/                                  
            return null ;
        }
    }
   

While login as admin then click preview on visualforce page executed but case is not created.I have checked the the debug log it throw the exception.

 
I have created simple site that create a new case.

User-added image
Note :

- I have given the Site permissions Visualforce page,Controller ,Lead Object and Case Object.
- While execute the site Lead is created similarly I tried to create a new case it not happens.
- I have given the case Object create permission but why it is not created
Can someone please help me.
While executing the site it showing the error:

**Visualforce Page**

    <apex:page controller="Controller" action="{!init}" showHeader="false" sidebar="false">
        <center>
            <apex:pageBlock title="Request Listener"></apex:pageBlock>         
        </center>
    </apex:page>
**Controller :**
  

         public with sharing class Controller
                {           
                    public PageReference init()
                    {
                    try
                    {                   
                    // Lead l1 = new Lead(FirstName='first name1',LastName = 'lead last name',phone ='9876543210');//testing
                     //insert l1;   testing       
                   Case c = new Case(Subject = 'Subject Test',Description ='Description Test');
                  insert c;
                }
                  }
                   catch(exception e){}
                    RETURN null;
                   } 
                }



I have install the "twilio" api in salesforce and I have register twilio phone number. How to receive the SMS details and how revert back the conformation.Which class should be call and where should I give the accoutsid,authosid and twilio phone number in Installed Package from Sandbox .
I need to install the Twilio package into my sandbox. I have have a requirement where I need to receive an SMS from the Customer and create a case. After that I need to Revert back an SMS to the Customer saying a received Conformation. How Do i Do it. I am completely new to this API. Please Help me out.

Hi

 

I have 2 objects here

 

1) Account - Parent 

2) Showing - Child

 

When the status on the account is dead, I wanted the status on the Showing record also to be dead.

 

I have created a trigger to do it but I am getting a strange error.

 

Error:Apex trigger UpdateShowingStatus caused an unexpected exception, contact your administrator: UpdateShowingStatus: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a0KJ0000001CKO5MAO; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ShowingCount: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 001J000000R4YjHIAV; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 001J000000R4YjH) is currently in trigger UpdateShowingStatus, therefore it cannot recursively update itself: [] Trigger.ShowingCount: line 21, column 1: []: Trigger.UpdateShowingStatus: line 17, column 1

 

I am posting the 2 triggers here

 

 

trigger UpdateShowingStatus on Account (before update) {
List<ID> accIds = New List<ID>();

  for(Account a:Trigger.new)
{
    if(a.pb__Status__c == 'Dead'){
      accIds.add(a.Id);
    }
  }

  List<pb__Showing__c> s = [ SELECT id,Account__c,Status__c from pb__Showing__c where Account__c = :accIds];
  for(integer i = 0 ; i < s.size(); i++){
    s[i].Status__c =  'Dead';
    
  }

  update s;
}

 

This is another trigger which is causing the conflict

 

trigger ShowingCount on pb__Showing__c (before insert,before update) {
    
    // if(trigger.new[0].Account__c!=null)
    // {
    Account ac=[select id, No_of_Viewings__c from Account where id=:trigger.new[0].Account__c];
    
    //if(ac!=null)
    //{
    if(ac.No_of_Viewings__c == null)
    ac.No_of_Viewings__c =0;
        
        if(trigger.isinsert) {
            ac.No_of_Viewings__c +=1;
        }
    
        if(trigger.isupdate ) {
            if(trigger.new[0].Status__c == 'Cancelled')
            ac.No_of_Viewings__c -= 1; 
        }
    
    update ac;
  
}

 

Can someone help me to fix this error please.

 

Thanks and Kind Regards

 

Finney

  • January 15, 2013
  • Like
  • 0

I'm trying to do the following in Salesforce Sites:

 

            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            String[] toAddresses = new String[] {opp.Owner.Email};
            mail.setToAddresses(toAddresses);
            mail.setOrgWideEmailAddressId('0S2B00000008OXA');

But whenever I use/set the setOrgWiseEmailAddressId Salesforce sites says that I need authorisation. I just want to change the from address in the email. Can you use organisational wide email addresses in Salesforce Sites?

  • January 17, 2012
  • Like
  • 0

Hi All,

 

I have written a query where I want to update a field on opportunity if Opportunity Owner of any opportunity is changed. I have a field Previous_Owner__c on opportunity which stores the name of previous owner if owner is changed.

I am getting the below error:

"Apex trigger OpptyPreOwnAssn caused an unexpected exception, contact your administrator: OpptyPreOwnAssn: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 006P0000003XNGsIAO; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 006P0000003XNGs) is currently in trigger OpptyPreOwnAssn, therefore it cannot recursively update itself".

 

 

trigger OpptyPreOwnAssn on Opportunity ( before update) {

     List <Opportunity> listOppty= [Select Id,OwnerID, Previous_Owner__c from Opportunity where Id In:Trigger.New];

    Set<ID> Owner1id = new Set<ID>();

   

    List<Opportunity> opp2= new List<opportunity>();      

       

     for(Opportunity opp1 : listOppty){                 

       Owner1id.add(opp1.OwnerId);   }  

 

     List< User > listusr = [Select Id,Name from User where ID in : Owner1id];         

 

  

for (ID id1:Owner1ID){     

 for (Opportunity opp:listOppty){                

   for (User usr:listusr){           

      if(opp.ownerid==usr.id){

                             opp.Previous_Owner__c=usr.Name;              

                             opp2.add(opp);                            

                     }}  }   }              

                 update opp2;              

  }

 

 

 

I am not able to figure out why I am getting the  error. Can anybody please suggest the remedy for the above.

 

Thanks

~Alok

Hi, 

I have written a trigger and if some criteria is met it will fire an email.Everything is fine in my mail but i am not able to set sender display name also i have set (Email Aministration-->Deliverability-->and unchecked Enable compliance with standard email security mechanisms and Enable Sender ID compliance).Can you please help me out with this?? 

email.setToAddresses( toAddresses ); 
email.setSenderDisplayName ('Company name'); 
email.setUseSignature(false); 

I am working on an application where the user will create a custom object (mps) record from the opportunity and a trigger will update certain fields on the mps from the opportunity.When there is an MPS record attached to the opportunity, the opportunity will update the mps, and when the mps is updated, the opportunity is updated. This has created an error that says "...cannot recursively update itself..." I am trying to find a way to prevent this. The problem is I cannot the find a way to break this recursion.

 

I wannt both records to be updated when one record is updated. Below are my triggers:

 

 

trigger OppUpdateMPS on Opportunity (before update) {
       Map<Id, Id> mapOpportunitytoMPS = new Map<Id, Id>();

    for(Opportunity o : trigger.new){
        // Populate map of Opportunity.Id to MPS.Id
        if (o.MPS__c != null) {
            mapOpportunitytoMPS.put(o.Id, o.mps__c);
        }
    }

    if (!mapOpportunitytoMPS.isEmpty()) {
        // Query all relevant opportunities to a map with key of Opportunity.Id
        Map<Id, MPS__c> mps = new Map<Id,MPS__c>([select id, MPS_BV__c, MPS_Comment__c, 
                         MPS_Scheduled_Ship_Date__c, MPS_Status__c, Close_Date__c, LastModifiedDate,
                         Projected_Ship_Date__c, Projected_On_Site_Delivery_Date__c,
                         Forecast_Category__c, Combined_Probability__c, Recursive_Update__c
                         from MPS__c where id in:mapOpportunitytoMPS.values()]);

        List<MPS__c> mpsToUpdate = new List<MPS__c>();
        Id mpsId;
        MPS__c m;

        for (Opportunity s : trigger.new) {
            if (mapOpportunitytoMPS.containsKey(s.Id)) {
                // Get the MPS__c ID from the map
                mpsId = mapOpportunitytoMPS.get(s.Id);
                // Get the opportunity based on the opportunity ID
                m = mps.get(mpsId);
                // Set fields on MPS based on Opportunity
                m.Forecast_Category__c = s.ForecastCategoryName;
                m.Combined_Probability__c = s.Combined_Probability__c;
                m.Close_Date__c = s.CloseDate;
                m.Projected_Ship_Date__c = s.Projected_Ship_Date__c;
                m.Projected_On_Site_Delivery_Date__c = s.Projected_On_Site_Delivery_Date__c ;
                m.MPS_Scheduled_Ship_Date__c = s.MPS_Scheduled_Ship_Date__c;
                MPSToUpdate.add(m);
            }
        }

        // Update all MPS__c in one call
        update MPSToUpdate;
        
    }
}

 

trigger MPSUpdate on MPS__c (Before Insert, Before Update) {
    Map<Id, Id> mapMpsToOpportunity = new Map<Id, Id>();
     
    for(MPS__c mps : trigger.new){
        // Populate map of MPS.Id to Opportunity.Id
        if (mps.OpportunityID__c != null) {
            mapMpsToOpportunity.put(mps.Id, mps.OpportunityID__c);
        }
    }
    
    if (!mapMpsToOpportunity.isEmpty()) {
        // Query all relevant opportunities to a map with key of Opportunity.Id
        Map<Id, Opportunity> opps = new Map<Id, Opportunity>([select id, MPS_BV__c, MPS_Comment__c, 
                         MPS_Scheduled_Ship_Date__c, MPS_Status__c, CloseDate,
                         Projected_Ship_Date__c, Projected_On_Site_Delivery_Date__c,
                         ForecastCategoryName, Combined_Probability__c
                         from Opportunity where id in:mapMpsToOpportunity.values()]);

        List<Opportunity> oppsToUpdate = new List<Opportunity>();
        Id oppId;
        Opportunity o;
        for (MPS__c s : trigger.new) {
            if (mapMpsToOpportunity.containsKey(s.Id)) {
                // Get the opportunity ID from the map
                oppId = mapMpsToOpportunity.get(s.Id);
                // Get the opportunity based on the opportunity ID
                o = opps.get(oppId);
                // Set fields on MPS based on Opportunity
                s.Forecast_Category__c = o.ForecastCategoryName;
                s.Combined_Probability__c = o.Combined_Probability__c;
                s.Close_Date__c = o.CloseDate;
                s.Projected_Ship_Date__c = o.Projected_Ship_Date__c;
                s.Projected_On_Site_Delivery_Date__c = o.Projected_On_Site_Delivery_Date__c;
                // Set fields on Opportunity based on MPS
                o.MPS_Status__c = s.MPS_Status__c;
                o.MPS_BV__c = s.MPS_BV__c;
                o.MPS_Comment__c = s.MPS_Comment__c;
                o.MPS_Scheduled_Ship_Date__c = s.MPS_Scheduled_Ship_Date__c;
                o.MPS__c = s.id;
                oppsToUpdate.add(o);
            }
       } 
        // Update all opportunities in one call
        update oppsToUpdate;
    }
}

 

 

 

I have thought about creating checkboxes to be checked when the a trigger updates a record, and reset the field with a time-based workflow, but I only need to stagger the time a few seconds before the field is reset. Is there any way I can achieve the same thing within the triggers?

 

Thanks,

ckellie

Hi,

Is it possible to get the ID of the Organization Wide Address you want, to be chosen with a test on its display address ?

I would like not to put "hard code" ID.

 

I found some code somewhere and pasted it in mine, but it doesn't work :

 

// create a new single email message object  
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
	
// Assign the addresses for the To, CC and BCC lists to the mail object.  
email.setBccAddresses(lEmailAddressesList);

// Use Organization Wide Address  
for(OrgWideEmailAddress owa : [select id, Address from OrgWideEmailAddress]) {
if(owa.Address.contains('CSR')) email.setOrgWideEmailAddressId(owa.id); } 

// Specify the subject line for your email address.  
email.setSubject('The request has been closed : ' + closedRequest.Name);
	
// Set to True if you want to BCC yourself on the email.  
email.setBccSender(false);
	
// Optionally append the salesforce.com email signature to the email.  
// The email address of the user executing the Apex Code will be used.  
email.setUseSignature(false);

email.setHtmlBody('This request :<b> ' + closedRequest.Name +' </b>has been closed<br />' +
'Subject : ' + closedRequest.Subject__c +'<br />' +
'Short description : ' + closedRequest.Short_description__c +'<br />' +
'<p>Resolution :<b> ' + closedRequest.Answer__c +' </b></p>' +
'<p>Thank you</p>');

email.setSaveAsActivity(false);
  	
// Send the email you have created.  
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email })

For now, I haven' find any documentation about this.

Does someone have any solution for me ?

Marie

 

  • March 23, 2011
  • Like
  • 0

Hi all,

 

I have a trigger to send  emails to the email addresses listed in the "toAddresses" .And all the body message goes within the variable named 'body'. Is there any possible to format the content in the body to make it looks like a table? The following is the email sending part of my code. Thanks in advance for any help

 

 

//Static email subject information
 String subject = Client_Name + '- Project Status Report - ' + Report_Date;
 
 //Construct email body
 String body = 'Report Generated by:   ' + UserName + '<BR />'
 + 'Reporting For:  '+ Report_Date + '<BR />' + '<BR />' +'Client Name: ' +Client_Name + '<BR />'
 +  'Overall Status: '+ Overall_Status + '<BR />' + 'Phase: ' + Phase + '<BR />'
 + 'Actions Today: '+ Actions + '<BR />'+ 'Yellow Flags: '+ Yellow_Flags+'<BR />'
 + 'Action Plan: ' + Action_Plan + '<BR />' 
 
 //Send Email
 Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
 String[] toAddresses = statusReportEmails.get(sReport.Id).split(';');
 mail.setToAddresses(toAddresses);
 mail.setSubject(subject);
mail.setSaveAsActivity(true);
mail.setHtmlBody(body);

 

I am getting the following error message : Please some one help me to getrid off this problem .

 

 

Error:

Update failed. First exception on row 0 with id 500Q0000002FHIoIAO; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, RecordType_Change: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 500Q0000002FHIoIAO; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 500Q0000002FHIo) is currently in trigger RecordType_Change, therefore it cannot recursively update itself: [] Trigger.RecordType_Change: line 12, column 16: []

 

 

trigger RecordType_Change on Case (before Update) {
IF(Trigger.isUpdate){
IF(!CaseRecordTypeUpdate.flag){
List<Case> listCaseold = [Select Id,Accountability__c,Accountable_Agent_VF__c,RecordType.Name from Case where ID =:Trigger.Old[0].ID];
List<Case> listCasenew = [Select Id,Accountability__c,Cause_Level_1__c,Accountable_Agent_VF__c,RecordType.Name from Case where ID =:Trigger.new[0].ID];       
IF(listCaseold[0].RecordType.Name.equalsIgnoreCase('csi')){
          IF(listCasenew[0].Accountability__c.equalsIgnoreCase('AXP') && listCasenew[0].Cause_Level_1__c.equalsIgnoreCase('Service Quality')){    
               RecordType objRec=[Select Id from RecordType where Name =: 'quick feedback'];
               listCasenew[0].RecordType.Name=objRec.ID;
               System.debug('Record Type  :'+objRec.ID);
               listCasenew[0].Accountable_Agent2__c=listCaseold[0].Accountable_Agent_VF__c;                 
               update listCasenew[0];  
     }
   }
}
CaseRecordTypeUpdate.flag=false;
}
}

 

Thanks,

Ram

Hi,

What I am trying to do is like this. I have an object Quote__c and it has child Quote_Line__c. When I update the currency fields in quote__c it has to update the currency field in the children .So ,in the before update trigger of Quote__c I am trying to update the currency fields in children.But in the Quote__c I have some rollup summary fields. So consequently when the child object get updated it try to update the rollup summary fields in Quote__c(master).As a result it caught in the error 

 

System.DmlException: Update failed. First exception on row 0 with id a0dA0000000rAw4IAE; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = a0fA0000000ki1a) is currently in trigger ChangeQuoteCurrency, therefore it cannot recursively update itself: []

 

I tried some methods but I did not get success. I tried This option without any success.

 

Thanks

Samarjit

  • August 18, 2010
  • Like
  • 0

Hi thank you firstlly for helping me out...

So I tried doing a simple bulk trigger... I keep getting this error

 

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger SARQ caused an unexpected exception, contact your administrator: SARQ: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a0AA0000000MaYSMA0; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = a0AA0000000MaYS) is currently in trigger SARQ, therefore it cannot recursively update itself: []: Trigger.SARQ: line 22, column 1

 

Help please...

 

trigger SARQ on Subject_Area__c (before insert,before update) {
//Get Ids for Subject Area
Set<ID> said = new Set<ID>{};

for(Subject_Area__c hrr: trigger.new){

    said.add(hrr.Id);
}
System.Debug('said ' + said);
if(said!=null && said.size()>0){
//The ones to update
    List<Subject_Area__c> htoUpdte =  [select id from Subject_Area__c where ID in :said];
    
//The answer I need to update SA.SARQ in the SA object
    List<Subject_Area_RQ__c> SARQ = [SELECT On_Track_Subject_Area__c
                                      FROM Subject_Area_RQ__c where Subject_Area__c IN :said];
    
for (Subject_Area__c c: htoUpdte ){
System.debug('sarq ' + SARQ[0].On_Track_Subject_Area__c);
            c.SARQ__c = SARQ[0].On_Track_Subject_Area__c;

update htoUpdte ;

}
}
}

 I also tried this:

Trigger SARQ on Subject_Area__c (before insert,before update) {
List<Subject_Area__c> htoUpdte = new List<Subject_Area__c>();


Subject_Area__c sa = Trigger.new[0];
List<Subject_Area_RQ__c> SARQ = [SELECT On_Track_Subject_Area__c
FROM Subject_Area_RQ__c where Subject_Area__r.Name=:sa.Name];


for(Subject_Area__c hr: trigger.new)
{

If(SARQ.size()>0){
hr.SARQ__c = SARQ[0].On_Track_Subject_Area__c ;
htoUpdte.add(hr);
}
}

}

 

We are using email to case and it's working pretty well.  One issue we are seeing is that if you send in an email with an attachment, the attachment does not get attached to the case (it's just dropped).  Attachments are a big part of our workflow that we need attached to the case -how do we set this up?  thanks