0

I have a trigger in account and based on billingcountry I need to make callout to SAP. I have but acNew.Billicountry=='US' and is working fine.

If opportunity uses account which has billingcountry 'US' then only opportunity trigger make callout ,else it should not. SO what condition i need to add in opportunity trigger? please help me out

3
  • can you update your question with your opportunity trigger if you have?
    – Himanshu
    Dec 17, 2015 at 5:42
  • I cannot post my code due to security reasons. Earlier based on opportunity stage I used to makecallout. Now I need to add 1 more condition based on account's billing country. how to do that?
    – Gayathri
    Dec 17, 2015 at 5:46
  • Gayathri .. consider that you can also try to write anonymous dummy code using different field names than in your actual production code. Some questions are a LOT easier to answer if we can see and understand your code. Dec 17, 2015 at 10:06

1 Answer 1

2

As you might now relationship field are not available inside trigger so you need to query that information in your trigger and from there you can match the information in trigger.new loop. Following code will demonstrate it

//get all the account from current opporutniy
set<id> setAccountIds = new set<id>();

//Get all the account id
for(Opportunity opp : Trigger.new)
{
    if(opp.Accountid!=null)
        setAccountIds.add(opp.Accountid)
}

//query the account object for details and add that into map
Map<id,Account> mapAccounts = new Map<id,Account>([select id,Billicountry from Account where id in : setAccountIds])

//loop over opporutnity and check for account details and make call out
for(Opportunity opp : Trigger.new)
{
    //Check for the logic
    if(opp.Accountid!=null && mapAccounts.containskey(opp.accountid) && mapAccounts.get(opp.AccountId).Billingcountry)
    {
        //Write your call out logic here
    }
}
2
  • let me try this and update
    – Gayathri
    Dec 17, 2015 at 6:04
  • great... select the answer and close this question. :)
    – Himanshu
    Dec 17, 2015 at 6:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .