Thursday, February 19, 2015

deploy code from Sandbox to Production?

To deploy code from a Sandbox or Developer Edition org to Production, you will need to use either the Force.com Migration Tool or the Force.com IDE.
Note: If you deploy to a production organization, 75% of your Apex scripts must be covered by unit tests, and all of those tests must complete successfully.
While only 75% of your Apex code must be covered by tests, your focus shouldn't be on the percentage of code that is covered. Instead, you should make sure that every use case of your application is covered, including positive and negative cases, as well as bulk and single record. This should lead to 75% or more of your code being covered by unit tests.
Force.com Migration Tool
The Force.com Migration Tool is a Java/Ant-based command-line utility for moving metadata between a local directory and a Force.com organization.
- http://wiki.developerforce.com/index.php/Force.com_Migration_Tool
Force.com IDE
The Force.com IDE is a powerful client application for creating, modifying and deploying Force.com applications. Based on the Eclipse platform, it provides a comfortable environment for programmers familiar with integrated development environments, allowing you to code, compile, test, package and deploy all from within the IDE itself. Much of the actual work, such as compilation, happens on the Force.com platform—the Force.com IDE performs the communication and result parsing transparently.
- http://wiki.developerforce.com/index.php/An_Introduction_to_Force_IDE

Please refer to the Apex Language Reference Documentation for more information
http://www.salesforce.com/us/developer/docs/apexcode/salesforce_apex_language_reference.pdf
See the chapter on Deploying Apex Scripts

Apex Triggers throw the error SELF_REFERENCE_FROM_TRIGGER

You cannot recursively update or delete the same object from an Apex trigger.
This error often occurs when:

        * You try to update or delete an object from within its before trigger.
        * You try to delete an object from within its after trigger.   

This error occurs with both direct and indirect operations. The following is an example of an indirect operation:

       1. A request is submitted to update Object A.
       2. A before update trigger on object A creates an object B.
       3. Object A is updated.
       4. An after insert trigger on object B queries object A and updates it. This is an indirect update of object A because of the before trigger of object A, so an error is generated.

Tuesday, February 3, 2015

Creating a CSV file from salesforce and sending through the Email

List<Account> lstAccount = [Select id,Name,CreatedDate from Account limit 10];
string header = 'Id, Name , Created Date \n';
string finalstr = header ;
for(Account acc: lstAccount)
{
       string recordString = '"'+acc.id+'","'+acc.Name+'","'+acc.CreatedDate+'"\n';
       finalstr = finalstr +recordString;
}

Messaging.EmailFileAttachment sendCsv = new Messaging.EmailFileAttachment();
blob csvBlob = Blob.valueOf(finalstr);
string fileName= 'Accounts.csv';
sendCsv.setFileName(fileName);
sendCsv.setBody(csvBlob);
Messaging.SingleEmailMessage email =new Messaging.SingleEmailMessage();
String[] toAddresses = new list<string> {'test@gmail.com'};
email.setSubject('Accounts');
email.setToAddresses( toAddresses );
email.setPlainTextBody('Accounts');
email.setFileAttachments(new Messaging.EmailFileAttachment[]{sendCsv});
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});

Labels

visualforce page ( 13 ) apex integration ( 5 ) apex trigger ( 4 ) csv file from vf page ( 4 ) javascript ( 4 ) csv visualforce page ( 3 ) Too many ( 2 ) call out ( 2 ) integration ( 2 ) rest api ( 2 ) salesforce rest api ( 2 ) salesforce to salesforce integration ( 2 ) sfdc rest api ( 2 ) trigger ( 2 ) 15 digit to 18 digit ( 1 ) DML rows in Apex ( 1 ) Date Conversion ( 1 ) Date/Time conversion ( 1 ) Deploy ( 1 ) Objects to Future Annotated Methods ( 1 ) SFDC limits ( 1 ) Sobject to Future Annotated Methods ( 1 ) Test Class ( 1 ) TimeZone Conversion ( 1 ) Too many dml rows ( 1 ) Too many future calls ( 1 ) annotations ( 1 ) apex code ( 1 ) closed opportunities ( 1 ) commit ( 1 ) convert ( 1 ) create records ( 1 ) csv create records ( 1 ) custom setting ( 1 ) deployment ( 1 ) deployment changeset ( 1 ) disable apex class ( 1 ) disable apex trigger ( 1 ) disable in production ( 1 ) document ( 1 ) download ( 1 ) field name ( 1 ) formula fields ( 1 ) iframe ( 1 ) inactive ( 1 ) intellisense ( 1 ) jsforce ( 1 ) limits ( 1 ) matrix report in vf page ( 1 ) multi select ( 1 ) multi select salesforce ( 1 ) multiselect ( 1 ) paypal ( 1 ) picklist ( 1 ) record type ( 1 ) rollback ( 1 ) salesforce limits ( 1 ) salesforce list ( 1 ) salesforce map ( 1 ) salesforce rest ( 1 ) salesforce set ( 1 ) salesforce1 ( 1 ) sandbox deployment ( 1 ) sfdc collection ( 1 ) sfdc list ( 1 ) sfdc map ( 1 ) sfdc rest ( 1 ) sfdc set ( 1 ) uncommitted ( 1 ) updated field ( 1 ) user ( 1 ) validation rule opportunity ( 1 ) validation rules opportunities ( 1 ) vf page ( 1 )

Ad