Salesforce Certified Application Architect

Thursday, 26 June 2014

Be aware of the following considerations for trigger context variables:

  • trigger.new and trigger.old cannot be used in Apex DML operations.

  • You can use an object to change its own field values using trigger.new, but only in before triggers. In all after triggers, trigger.new is not saved, so a run time exception is thrown.

  • trigger.old is always read-only.

  • You cannot delete trigger.new.


Cheers...

How to Insert Transaction and Update Member on button click.

global class InsertTransaction {

WebService static string  InsertRecord(string id) {

    String OppId=id;
    string ErrorMesg;
    Map<ID,Member__c> mapmembers = new Map<ID,Member__c>();
    List<ID> MemberIDs =new List<ID>();
    List<ID> ProgramEnrIds =new List<ID>();
    List<Transaction__c> listTrans=new List<Transaction__c>();
    List<Member__c> lopp1=[select id ,Active__c,Program_Enrolled__c,Enrolled_Date__c,
    Loyalty_Enrolled__c,Points__c from Member__c where id =:OppId limit 1];
    integer counIn=[select count() from Transaction__c where Member__c =:OppId ];
    set<string> setPromId = new set<string>();
    List<Member__c> Members =new List<Member__c>();
    if(counIn > 0) {
    ErrorMesg ='You can not create a Transaction because this member having the Transaction ';
    }

    else {
    for(Member__c m:lopp1){
    Transaction__c tObj=new Transaction__c(Transaction_Date__c=system.today());
    tObj.Member__c=m.id;
    tObj.ProgramEnrolled__c=m.Program_Enrolled__c;
    tObj.Sub_Type__c='Enrollment';
    tObj.Status__c ='Processed';
    tObj.Loyalty_Product__c='a0590000008at2y';
    listTrans.add(tObj);
    }
 
    for(Transaction__c tObj1:listTrans){
    ProgramEnrIds.add(tObj1.ProgramEnrolled__c);
    MemberIDs.add(tObj1.Member__c);
 
    }
 
 list<Promotion__c > lisProm=[select id,Active__c,Program_Enrolled__c,Apply_To__c from                  Promotion__c where Program_Enrolled__c In : ProgramEnrIds];
    System.debug('lisProm---->'+lisProm.size());
    for(Promotion__c obj:lisProm){
    setPromId.add(obj.id);

    }
    list<Rule_Action__c>ListObj=[Select PointsAssigned__c,        id,Number_of_Points__c,Promotion__c,Promotion__r.Apply_To__c,
 Object__c from Rule_Action__c where Promotion__c in:setPromId];
    System.debug('ListObj---->'+ListObj.size());
 
    Members =[Select Points__c FROM Member__c Where ID in:MemberIDs];
    System.debug('Members ---->+Members )');
 
    for(Member__c m:Members){
    mapmembers.put(m.id,m);
    System.debug('mapmembers---->'+mapmembers.size() );
    }
 
    for(Transaction__c tn:listTrans){
    Member__c Member = mapmembers.get(tn.Member__c);
    System.debug('Member ---->'+Member);
 
    for(Rule_Action__c raObj:ListObj){
    if(raObj.Promotion__r.Apply_To__c == 'Enrollment'){
    Member.Points__c=raObj.Number_of_Points__c;
    System.debug('Member Points---->'+Member.Points__c );
    System.debug('raObj Points---->'+raObj.Number_of_Points__c);
    }
     mapmembers.put(Member.id,Member);
    }
    }
 
    if(listTrans.size()>0){
    Insert listTrans;
    System.debug('mapmembers---->'+mapmembers.size());
    }
 
    update mapmembers.values();
 
    ErrorMesg='Transction created succesfully';
 
    }
      return ErrorMesg;
   }

 }

Monday, 9 June 2014

How to schedule Batch Class for every hour in Salesforce?

Sample code:

SampleSchedulableClass obj = new SampleSchedulableClass();

String cron = '0 59 * * * *'
System.schedule('Testing', cron, obj);


Expression
Description
0 0 13 * * ?
Class runs every day at 1 PM.
0 0 22 ? * 6L
Class runs the last Friday of every month at 10 PM.
0 0 10 ? * MON-FRI
Class runs Monday through Friday at 10 AM.
0 0 20 * * ? 2010
Class runs every day at 8 PM during the year 2010.

Cheers!!

System.schedule in Apex scheduler in Salsforce

Sample code:

SampleSchedulableClass obj = new SampleSchedulableClass();

String cron = '0 59 * * * *'
System.schedule('Testing', cron, obj);

The above code executes SampleSchedulableClass for every one hour.

Syntax for Cron:

Seconds Minutes Hours Day Month Week Year

Seconds : 0 - 59
Minutes  : 0 - 59
Hours     : 0 - 23
Day        : 1 - 31
Month    : 1 - 12
Week     : 1 - 7(Sunday is first and Saturday is last)
Year       : upto 2099

Year is optional.

Expression
Description
0 0 13 * * ?
Class runs every day at 1 PM.
0 0 22 ? * 6L
Class runs the last Friday of every month at 10 PM.
0 0 10 ? * MON-FRI
Class runs Monday through Friday at 10 AM.
0 0 20 * * ? 2010
Class runs every day at 8 PM during the year 2010.

? - No value
* - All values
L - Last
W - Nearest weekday


How to update a field from one to another object on button click.

global class TransactionProcessingUtility_1  {

WebService static void processTransaction (id transactionids) {

List<Transaction__c> TransactionsToUpdate =new List<Transaction__c>();
List<ID> MemberIDs =new List<ID>();
List<ID> ProductIDs =new List<ID>();
List<ID> ProgramEnrIds =new List<ID>();
List<Member__c> Members =new List<Member__c>();
List<LoyaltyProduct__c> Products =new List<LoyaltyProduct__c>();
Map<ID,Member__c>   mapmembers = new Map<ID,Member__c>();
Map<ID,LoyaltyProduct__c>   mapproducts = new Map<ID,LoyaltyProduct__c>();  
Map<ID,Transaction__c>   maptransactions = new Map<ID,Transaction__c>();
List<String> transfilter = new List<String>{'Processed','Cancelled','Failed'};  

if(transactionids != null) {
List<Transaction__c> listofTransactions =[SELECT ID,
Member__c,
Processing_Comment__c,
Loyalty_Product__c,
Status__c,
Sub_Type__c,ProgramEnrolled__c,
Type__c,
Transaction_Date__c
FROM Transaction__c WHERE id =:transactionids AND
Status__c NOT IN :transfilter];

for(Transaction__c t:listofTransactions){
MemberIDs.add(t.Member__c);
ProductIDs.add(t.Loyalty_Product__c);
maptransactions.put(t.id, t);
ProgramEnrIds.add(t.ProgramEnrolled__c);

}

set<string> setPromId = new set<string>();
Map<string,Rule_Action__c >  updateMap = new Map<string,Rule_Action__c >();
list<Promotion__c > lisProm=[select id,Active__c,Program_Enrolled__c,Apply_To__c from Promotion__c where Program_Enrolled__c In : ProgramEnrIds];

for(Promotion__c obj:lisProm){
setPromId.add(obj.id);

}

list<Rule_Action__c>ListObj=[Select id,Number_of_Points__c,Promotion__c,Promotion__r.Apply_To__c, Object__c from Rule_Action__c where Promotion__c in:setPromId];
Members  =[Select Points__c FROM Member__c Where ID in:MemberIDs];
Products =[Select Product_points__c FROM LoyaltyProduct__c Where ID in:ProductIDs];

for(Member__c m:Members){
mapmembers.put(m.id,m);

}

for(LoyaltyProduct__c p:Products){
mapproducts.put(p.id,p);

}

for(Transaction__c t:listofTransactions){
Member__c Member = mapmembers.get(t.Member__c);
LoyaltyProduct__c product = mapproducts.get(t.Loyalty_Product__c);
for(Rule_Action__c raObj:ListObj)
{

if(t.Type__c =='Accrual' && t.Sub_Type__c =='Product' && raObj.Promotion__r.Apply_To__c == 'Accrual-Product' ){
Member.Points__c=Member.Points__c+raObj.Number_of_Points__c;
t.Status__c ='Processed';
t.Processing_Comment__c ='Points added to member';
}

else if( t.Type__c =='Redemption' && t.Sub_Type__c =='Product' && raObj.Promotion__r.Apply_To__c == 'Redemption-Product' ) {
if( raObj.Number_of_Points__c < Member.Points__c  )
{

Member.Points__c=Member.Points__c - raObj.Number_of_Points__c;
t.Status__c ='Processed';
t.Processing_Comment__c ='Points redeemed from member';

}
else if(raObj.Number_of_Points__c > Member.Points__c ) {
t.Status__c ='Failed';
t.Processing_Comment__c ='Not enough points to redeem';

}
}
maptransactions.put(t.id,t);

}
}
update mapmembers.values();
update maptransactions.values();

}
}

}
=============================================================
{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")}
    {!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")}
   
     var result = sforce.apex.execute(
    "TransactionProcessingUtility_1",  //class name  
    "processTransaction",  //method name      
    { transactionids: '{!Transaction__c.Id}'    // method parameter
     });
window.alert("Are you sure want to proceed!!" );
window.location.reload(true);

Wednesday, 21 May 2014

ASIDE is a Sales force IDE in the Cloud.

What is ASIDE?ASIDE is full-featured Salesforce IDE built from the ground up for efficient delivery, design, and testing of Apex and Visualforce code. 

Is ASIDE open source?Currently it is not, but possibly in the future. 

What features will be added to ASIDE next?Currently ASIDE is getting bugs fixed and polish added, but after that the next new feature will be improved static resource support. 

Is there anything I can do if the ASIDE login is not working?Try using the frontdoor login. 

Does ASIDE store any of my Salesforce or personal data?No, ASIDE does not store any of this information. 

Who can I contact if I have more questions?Click here if you have any.

ASIDE does all of the things you need from a Salesforce IDE, just easier and faster. Check out the feature list below.
  • Code Editor
    • Create, edit and delete all Apex and Visualforce code within your org
    • Auto-completion of Apex and Visualforce
    • Auto-generation of Apex Controllers/Extensions and related test code
    • Save conflict detection
    • Static Resource edit support
    • Execute Anonymous
    • Debug log access
    • Find and replace within file
    • Org-wide code search
    • Update file version
    • Local code history
    • "Open in Salesforce", allowing easy access to rendered VF pages and more
    • Look and feel of editor is fully configurable (theme, font size, invisibles, etc)
    • Based on the awesome ace editor
    • Access to documentation, ability to run unit tests, and probably a few things im forgetting…
    • Highlight lines not unit tested and see other coverage information
  • Unit Test Execution Environment
    • See all unit test results, class-by-class
    • Configure the result view to focus on certain unit tests
    • Easily drill into failures with the stack trace parser
    • Run unit tests three different ways
      • All at once - run all the tests in your org with one button click
      • By query - write a query that targets a group of tests to run
      • Manual selection - from a multi-select typeahead
    • Generate a code coverage report for your organization
  • Deploy Manager
    • Easy-to-use interface for retrieves and deploys
    • Create filters to target files for retrieves
    • Ability to filter by last retrieve and last deploy dates
    • Can retrieve files multiple ways:
      • Drop a package.xml
      • Select files to retrieve by using a pre-canned or custom filter
    • Can deploy by dropping a zip file retrieve result
    • Detailed deploy status and results shown upon deploy
    • Ability to configure deploy (e.g. Run Unit Tests, Validate Only, etc)
  • Query Tool
    • Query all the data in your org
    • Delete and export query results
    • Filter and paginate query results
    • Inline data edit and create
    • Maintains query history
    • Show/hide/reorder/resize columns
    • Sort query results
    • Share queries with other users

cheers..

Tuesday, 13 May 2014

Relationship between parent and child .

Hi,

Please see below relatioship ...

1) Parent to Child
SELECT Id, (SELECT Id from OpportunityLineItems) FROM Opportunity (Standard Version)
Select ID, (Select ID FROM Orders__r) FROM Account (Custom Object Version)



2) Child to Parent
SELECT Id, Name, Account.Name FROM Contact
Select ID, VCR__r.Name FROM Account

Salesforce Certified Application Architect & Certified Data Architecture and Management Designer Exam

How to pass Salesforce Certified Data Architecture and Management Designer Exam This exam was 1st architect exam for me. Its not that muc...